/tutorial/xml/dom/my_validating_tree.e

http://github.com/tybor/Liberty · Specman e · 45 lines · 36 code · 5 blank · 4 comment · 4 complexity · 025669ef105dff1c4c65b1499ed79a9f MD5 · raw file

  1. class MY_VALIDATING_TREE
  2. --
  3. -- Just to show how to simply have some home-crafted validation.
  4. -- The principle is to redefine the `new_node' factory.
  5. --
  6. inherit
  7. XML_TREE
  8. redefine
  9. new_node
  10. end
  11. create {EXAMPLE2}
  12. with_error_handler
  13. feature {}
  14. Tree_tag: STRING is "tree"
  15. Node_tag: STRING is "node"
  16. Leaf_tag: STRING is "leaf"
  17. new_node (node_name: STRING; line, column: INTEGER): XML_NODE is
  18. do
  19. inspect node_name
  20. when "tree" then
  21. if current_node /= Void then
  22. parse_error(line, column, once "unexpected tree without a parent node")
  23. else
  24. create Result.make(Tree_tag, line, column)
  25. end
  26. when "node" then
  27. if current_node = Void or else current_node = Leaf_tag then
  28. parse_error(line, column, once "unexpected node without parent node or with parent node being a leaf")
  29. else
  30. create Result.make(Node_tag, line, column)
  31. end
  32. when "leaf" then
  33. if current_node = Void then
  34. parse_error(line, column, once "unexpected leaf without parent node")
  35. else
  36. create Result.make(Leaf_tag, line, column)
  37. end
  38. end
  39. end
  40. end