1324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/*
2324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * [The "BSD licence"]
3324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * Copyright (c) 2005-2008 Terence Parr
4324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * All rights reserved.
5324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver *
6324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * Conversion to C#:
7324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * Copyright (c) 2008-2009 Sam Harwell, Pixel Mine, Inc.
8324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * All rights reserved.
9324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver *
10324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * Redistribution and use in source and binary forms, with or without
11324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * modification, are permitted provided that the following conditions
12324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * are met:
13324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * 1. Redistributions of source code must retain the above copyright
14324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver *    notice, this list of conditions and the following disclaimer.
15324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * 2. Redistributions in binary form must reproduce the above copyright
16324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver *    notice, this list of conditions and the following disclaimer in the
17324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver *    documentation and/or other materials provided with the distribution.
18324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * 3. The name of the author may not be used to endorse or promote products
19324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver *    derived from this software without specific prior written permission.
20324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver *
21324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver */
32324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
33324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruvernamespace Antlr.Runtime.Tree
34324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver{
35324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** <summary>A stream of tree nodes, accessing nodes from a tree of some kind</summary> */
36324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    public interface ITreeNodeStream : IIntStream
37324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    {
38324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        /** <summary>
39324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  Get a tree node at an absolute index i; 0..n-1.
40324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  If you don't want to buffer up nodes, then this method makes no
41324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  sense for you.
42324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  </summary>
43324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         */
44324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        object this[int i]
45324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
46324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            get;
47324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
48324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
49324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        /** <summary>
50324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  Get tree node at current input pointer + i ahead where i=1 is next node.
51324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  i&lt;0 indicates nodes in the past.  So LT(-1) is previous node, but
52324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  implementations are not required to provide results for k &lt; -1.
53324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  LT(0) is undefined.  For i&gt;=n, return null.
54324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  Return null for LT(0) and any index that results in an absolute address
55324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  that is negative.
56324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  </summary>
57324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *
58324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  <remarks>
59324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  This is analogus to the LT() method of the TokenStream, but this
60324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  returns a tree node instead of a token.  Makes code gen identical
61324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  for both parser and tree grammars. :)
62324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  </remarks>
63324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         */
64324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        object LT( int k );
65324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
66324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        /** <summary>
67324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  Where is this stream pulling nodes from?  This is not the name, but
68324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  the object that provides node objects.
69324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  </summary>
70324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         */
71324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        object TreeSource
72324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
73324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            get;
74324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
75324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
76324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        /** <summary>
77324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  If the tree associated with this stream was created from a TokenStream,
78324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  you can specify it here.  Used to do rule $text attribute in tree
79324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  parser.  Optional unless you use tree parser rule text attribute
80324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  or output=template and rewrite=true options.
81324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  </summary>
82324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         */
83324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        ITokenStream TokenStream
84324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
85324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            get;
86324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
87324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
88324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        /** <summary>
89324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  What adaptor can tell me how to interpret/navigate nodes and
90324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  trees.  E.g., get text of a node.
91324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  </summary>
92324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         */
93324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        ITreeAdaptor TreeAdaptor
94324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
95324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            get;
96324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
97324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
98324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        /** <summary>
99324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  As we flatten the tree, we use UP, DOWN nodes to represent
100324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  the tree structure.  When debugging we need unique nodes
101324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  so we have to instantiate new ones.  When doing normal tree
102324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  parsing, it's slow and a waste of memory to create unique
103324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  navigation nodes.  Default should be false;
104324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  </summary>
105324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         */
106324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        bool UniqueNavigationNodes
107324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        {
108324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            get;
109324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver            set;
110324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        }
111324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
112324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        /** <summary>
113324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  Return the text of all nodes from start to stop, inclusive.
114324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  If the stream does not buffer all the nodes then it can still
115324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  walk recursively from start until stop.  You can always return
116324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  null or "" too, but users should not access $ruleLabel.text in
117324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  an action of course in that case.
118324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  </summary>
119324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         */
120324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        string ToString( object start, object stop );
121324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
122324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
123324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        #region REWRITING TREES (used by tree parser)
124324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
125324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        /** <summary>
126324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  Replace from start to stop child index of parent with t, which might
127324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  be a list.  Number of children may be different
128324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  after this call.  The stream is notified because it is walking the
129324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  tree and might need to know you are monkeying with the underlying
130324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  tree.  Also, it might be able to modify the node stream to avoid
131324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  restreaming for future phases.
132324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  </summary>
133324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *
134324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  <remarks>
135324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  If parent is null, don't do anything; must be at root of overall tree.
136324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  Can't replace whatever points to the parent externally.  Do nothing.
137324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         *  </remarks>
138324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver         */
139324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        void ReplaceChildren( object parent, int startChildIndex, int stopChildIndex, object t );
140324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
141324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver        #endregion
142324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
143324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    }
144324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver}
145