/tutorial/xml/dom/my_validating_tree.e
Specman e | 45 lines | 36 code | 5 blank | 4 comment | 4 complexity | 025669ef105dff1c4c65b1499ed79a9f MD5 | raw file
1class 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 7inherit 8 XML_TREE 9 redefine 10 new_node 11 end 12 13create {EXAMPLE2} 14 with_error_handler 15 16feature {} 17 Tree_tag: STRING is "tree" 18 Node_tag: STRING is "node" 19 Leaf_tag: STRING is "leaf" 20 21 new_node (node_name: STRING; line, column: INTEGER): XML_NODE is 22 do 23 inspect node_name 24 when "tree" then 25 if current_node /= Void then 26 parse_error(line, column, once "unexpected tree without a parent node") 27 else 28 create Result.make(Tree_tag, line, column) 29 end 30 when "node" then 31 if current_node = Void or else current_node = Leaf_tag then 32 parse_error(line, column, once "unexpected node without parent node or with parent node being a leaf") 33 else 34 create Result.make(Node_tag, line, column) 35 end 36 when "leaf" then 37 if current_node = Void then 38 parse_error(line, column, once "unexpected leaf without parent node") 39 else 40 create Result.make(Leaf_tag, line, column) 41 end 42 end 43 end 44 45end