Home | History | Annotate | Download | only in antlr3

Lines Matching defs:Tree

41 Name space containing all of the entities pertaining to tree construction and
42 tree parsing.
48 autoload :Wizard, 'antlr3/tree/wizard'
49 autoload :Visitor, 'antlr3/tree/visitor'
52 ############################################ Tree Parser ###########################################
59 TreeParser is the default base class of ANTLR-generated tree parsers. The class
60 tailors the functionality provided by Recognizer to the task of tree-pattern
63 == About Tree Parsers
68 * tree parsers
72 Trees (ASTs), tree structures that reflect the high-level syntactic and semantic
78 custom actions along the way -- tree parsers.
80 Tree parsers are created from tree grammars. ANTLR-generated tree parsers
86 == The Tree Parser API
89 Mainly, it customizes a few methods specifically to deal with tree nodes
92 Like all ANTLR recognizers, tree parsers contained a shared state structure and
94 tree features flexible and customizable, and thus it does not make any
96 this flexibility is that tree parsers also require an extra tree adaptor object,
97 the purpose of which is to provide a homogeneous interface for handling tree
98 construction and analysis of your tree nodes.
100 See Tree and TreeAdaptor for more information.
187 ############################################ Tree Nodes ############################################
190 =begin rdoc ANTLR3::AST::Tree
194 As ANTLR is concerned, an Abstract Syntax Tree (AST) node is an object that
196 source text embodied within the tree and its children.
198 The Tree module, like the Token and Stream modules, emulates an abstract base
200 tree nodes as well as the methods trees need to implement.
209 [flat list (nil tree)] a tree node without a token payload, but with more
211 tree nodes
212 [root] a top-level tree node, i.e. a node that does not have a parent
215 [ancestors] the list of successive parents from a tree node to the root node
221 module Tree
305 A base implementation of an Abstract Syntax Tree Node. It mainly defines the
307 relationship that characterize a tree; it does not provide any logic concerning
315 include Tree
359 def set_child( index, tree )
360 return if tree.nil?
361 tree.flat_list? and raise ArgumentError, "Can't set single child to a list"
362 tree.parent = self
363 tree.child_index = index
364 self[ index ] = tree
450 The default Tree class implementation used by ANTLR tree-related code.
452 A CommonTree object is a tree node that wraps a token <i>payload</i> (or a +nil+
453 value) and contains zero or more child tree nodes. Additionally, it tracks
454 information about the range of data collectively spanned by the tree node:
457 the tree
464 unnecessary. In such a case, a more bare-bones tree class could be written
466 TreeAdaptor class to handle tree construction and manipulation for the
636 when Tree
662 ########################################### Tree Adaptors ##########################################
667 Since a tree can be represented by a multitude of formats, ANTLR's tree-related
668 code mandates the use of Tree Adaptor objects to build and manipulate any actual
670 number of different tree structures without adding rigid interface requirements
671 on customized tree structures. For example, if you want to represent trees using
672 simple arrays of arrays, you just need to design an appropriate tree adaptor and
675 Tree adaptors are tasked with:
677 * copying and creating tree nodes and tokens
679 * cleaning up / normalizing a full tree structure after construction
680 * reading and writing the attributes ANTLR expects of tree nodes
690 def add_child( tree, child )
691 tree.add_child( child ) if tree and child
694 def child_count( tree )
695 tree.child_count
698 def child_index( tree )
699 tree.child_index rescue 0
702 def child_of( tree, index )
703 tree.nil? ? nil : tree.child( index )
710 def copy_tree( tree, parent = nil )
711 tree or return nil
712 new_tree = copy_node( tree )
713 set_child_index( new_tree, child_index( tree ) )
715 each_child( tree ) do | child |
722 def delete_child( tree, index )
723 tree.delete_child( index )
727 def each_child( tree )
728 block_given? or return enum_for( :each_child, tree )
729 for i in 0 ... child_count( tree )
730 yield( child_of( tree, i ) )
732 return tree
735 def each_ancestor( tree, include_tree = true )
736 block_given? or return enum_for( :each_ancestor, tree, include_tree )
738 begin yield( tree ) end while tree = parent_of( tree )
740 while tree = parent_of( tree ) do yield( tree ) end
744 def flat_list?( tree )
745 tree.flat_list?
748 def empty?( tree )
749 child_count( tree ).zero?
752 def parent( tree )
753 tree.parent
771 def set_child_index( tree, index )
772 tree.child_index = index
775 def set_parent( tree, parent )
776 tree.parent = parent
779 def set_token_boundaries( tree, start_token = nil, stop_token = nil )
780 return unless tree
784 tree.start_index = start
785 tree.stop_index = stop
786 return tree
789 def text_of( tree )
790 tree.text rescue nil
793 def token( tree )
794 CommonTree === tree ? tree.token : nil
797 def token_start_index( tree )
798 tree ? tree.token_start_index : -1
801 def token_stop_index( tree )
802 tree ? tree.token_stop_index : -1
805 def type_name( tree )
806 tree.name rescue 'INVALID'
809 def type_of( tree )
810 tree.type rescue INVALID_TOKEN_TYPE
821 The default tree adaptor used by ANTLR-generated tree code. It, of course,
862 tree = create_with_payload( from_token )
863 return tree
913 def empty?( tree )
914 tree.empty?
917 def each_child( tree )
918 block_given? or return enum_for( :each_child, tree )
919 tree.each do | child |
928 ########################################### Tree Streams ###########################################
933 TreeNodeStreams flatten two-dimensional tree structures into one-dimensional
934 sequences. They preserve the two-dimensional structure of the tree by inserting
937 Consider a hypothetical tree:
946 A tree node stream would serialize the tree into the following sequence:
950 Other than serializing a tree into a sequence of nodes, a tree node stream
951 operates similarly to other streams. They are commonly used by tree parsers as
953 of the next node. #look returns the next full tree node.
975 objects. CommonTreeNodeStreams are the default input streams for tree parsers.
1020 def fill_buffer( tree = @root )
1021 @nodes << tree unless nil_tree = @adaptor.flat_list?( tree )
1022 unless @adaptor.empty?( tree )
1024 @adaptor.each_child( tree ) { | c | fill_buffer( c ) }
1027 @position = 0 if tree == @root
1235 Special type of stream that is used internally by tree-building and tree-
1326 Special type of stream that is used internally by tree-building and tree-
1345 Special type of stream that is used internally by tree-building and tree-
1365 Special type of stream that is used internally by tree-building and tree-