calabash-android 0.4.0.pre1 → 0.4.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/bin/calabash-android-build.rb +6 -0
  2. data/bin/calabash-android-setup.rb +2 -3
  3. data/lib/calabash-android/canned_steps.md +1 -1
  4. data/lib/calabash-android/helpers.rb +35 -2
  5. data/lib/calabash-android/lib/TestServer.apk +0 -0
  6. data/lib/calabash-android/operations.rb +13 -6
  7. data/lib/calabash-android/version.rb +1 -1
  8. data/test-server/instrumentation-backend/.classpath +2 -1
  9. data/test-server/instrumentation-backend/antlr.sh +2 -0
  10. data/test-server/instrumentation-backend/antlr/UIQuery.g +70 -0
  11. data/test-server/instrumentation-backend/antlr/UIQuery.tokens +12 -0
  12. data/test-server/instrumentation-backend/build-libs/antlr-3.4-complete.jar +0 -0
  13. data/test-server/instrumentation-backend/build-libs/junit.jar +0 -0
  14. data/test-server/instrumentation-backend/build.xml +56 -0
  15. data/test-server/instrumentation-backend/src/org/antlr/runtime/ANTLRFileStream.java +78 -0
  16. data/test-server/instrumentation-backend/src/org/antlr/runtime/ANTLRInputStream.java +70 -0
  17. data/test-server/instrumentation-backend/src/org/antlr/runtime/ANTLRReaderStream.java +95 -0
  18. data/test-server/instrumentation-backend/src/org/antlr/runtime/ANTLRStringStream.java +230 -0
  19. data/test-server/instrumentation-backend/src/org/antlr/runtime/BaseRecognizer.java +894 -0
  20. data/test-server/instrumentation-backend/src/org/antlr/runtime/BitSet.java +325 -0
  21. data/test-server/instrumentation-backend/src/org/antlr/runtime/BufferedTokenStream.java +272 -0
  22. data/test-server/instrumentation-backend/src/org/antlr/runtime/CharStream.java +57 -0
  23. data/test-server/instrumentation-backend/src/org/antlr/runtime/CharStreamState.java +45 -0
  24. data/test-server/instrumentation-backend/src/org/antlr/runtime/ClassicToken.java +141 -0
  25. data/test-server/instrumentation-backend/src/org/antlr/runtime/CommonToken.java +191 -0
  26. data/test-server/instrumentation-backend/src/org/antlr/runtime/CommonTokenStream.java +153 -0
  27. data/test-server/instrumentation-backend/src/org/antlr/runtime/DFA.java +250 -0
  28. data/test-server/instrumentation-backend/src/org/antlr/runtime/EarlyExitException.java +41 -0
  29. data/test-server/instrumentation-backend/src/org/antlr/runtime/FailedPredicateException.java +54 -0
  30. data/test-server/instrumentation-backend/src/org/antlr/runtime/IntStream.java +122 -0
  31. data/test-server/instrumentation-backend/src/org/antlr/runtime/LegacyCommonTokenStream.java +394 -0
  32. data/test-server/instrumentation-backend/src/org/antlr/runtime/Lexer.java +340 -0
  33. data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedNotSetException.java +41 -0
  34. data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedRangeException.java +45 -0
  35. data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedSetException.java +44 -0
  36. data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedTokenException.java +45 -0
  37. data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedTreeNodeException.java +49 -0
  38. data/test-server/instrumentation-backend/src/org/antlr/runtime/MissingTokenException.java +56 -0
  39. data/test-server/instrumentation-backend/src/org/antlr/runtime/NoViableAltException.java +57 -0
  40. data/test-server/instrumentation-backend/src/org/antlr/runtime/Parser.java +98 -0
  41. data/test-server/instrumentation-backend/src/org/antlr/runtime/ParserRuleReturnScope.java +52 -0
  42. data/test-server/instrumentation-backend/src/org/antlr/runtime/RecognitionException.java +180 -0
  43. data/test-server/instrumentation-backend/src/org/antlr/runtime/RecognizerSharedState.java +144 -0
  44. data/test-server/instrumentation-backend/src/org/antlr/runtime/RuleReturnScope.java +42 -0
  45. data/test-server/instrumentation-backend/src/org/antlr/runtime/SerializedGrammar.java +204 -0
  46. data/test-server/instrumentation-backend/src/org/antlr/runtime/Token.java +92 -0
  47. data/test-server/instrumentation-backend/src/org/antlr/runtime/TokenRewriteStream.java +569 -0
  48. data/test-server/instrumentation-backend/src/org/antlr/runtime/TokenSource.java +54 -0
  49. data/test-server/instrumentation-backend/src/org/antlr/runtime/TokenStream.java +75 -0
  50. data/test-server/instrumentation-backend/src/org/antlr/runtime/UnbufferedTokenStream.java +82 -0
  51. data/test-server/instrumentation-backend/src/org/antlr/runtime/UnwantedTokenException.java +53 -0
  52. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/BlankDebugEventListener.java +77 -0
  53. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugEventHub.java +292 -0
  54. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugEventListener.java +323 -0
  55. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugEventRepeater.java +88 -0
  56. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugEventSocketProxy.java +358 -0
  57. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugParser.java +101 -0
  58. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugTokenStream.java +156 -0
  59. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugTreeAdaptor.java +250 -0
  60. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugTreeNodeStream.java +155 -0
  61. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugTreeParser.java +112 -0
  62. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/ParseTreeBuilder.java +109 -0
  63. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/Profiler.java +772 -0
  64. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/RemoteDebugEventSocketListener.java +541 -0
  65. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/TraceDebugEventListener.java +108 -0
  66. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/Tracer.java +69 -0
  67. data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/DoubleKeyMap.java +62 -0
  68. data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/FastQueue.java +100 -0
  69. data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/IntArray.java +87 -0
  70. data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/LookaheadStream.java +161 -0
  71. data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/Stats.java +189 -0
  72. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/BaseTree.java +349 -0
  73. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/BaseTreeAdaptor.java +279 -0
  74. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/BufferedTreeNodeStream.java +489 -0
  75. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/CommonErrorNode.java +108 -0
  76. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/CommonTree.java +185 -0
  77. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/CommonTreeAdaptor.java +168 -0
  78. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/CommonTreeNodeStream.java +171 -0
  79. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/ParseTree.java +119 -0
  80. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteCardinalityException.java +47 -0
  81. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteEarlyExitException.java +39 -0
  82. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteEmptyStreamException.java +35 -0
  83. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteRuleElementStream.java +210 -0
  84. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteRuleNodeStream.java +70 -0
  85. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteRuleSubtreeStream.java +86 -0
  86. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteRuleTokenStream.java +76 -0
  87. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/Tree.java +127 -0
  88. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeAdaptor.java +263 -0
  89. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeFilter.java +135 -0
  90. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeIterator.java +132 -0
  91. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeNodeStream.java +106 -0
  92. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeParser.java +169 -0
  93. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreePatternLexer.java +135 -0
  94. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreePatternParser.java +154 -0
  95. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeRewriter.java +124 -0
  96. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeRuleReturnScope.java +41 -0
  97. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeVisitor.java +69 -0
  98. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeVisitorAction.java +47 -0
  99. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeWizard.java +531 -0
  100. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java +22 -7
  101. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/InstrumentationBackend.java +4 -4
  102. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/Result.java +0 -1
  103. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/HttpServer.java +161 -129
  104. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/activity/SetActivityOrientation.java +5 -7
  105. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/GetViewProperty.java +1 -7
  106. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/Query.java +70 -61
  107. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/UIQuery.tokens +12 -0
  108. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ViewMapper.java +63 -0
  109. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/antlr/UIQuery.tokens +10 -0
  110. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/antlr/UIQueryLexer.java +945 -0
  111. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/antlr/UIQueryParser.java +463 -0
  112. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/InvalidUIQueryException.java +10 -0
  113. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryAST.java +8 -0
  114. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTClassName.java +115 -0
  115. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTWith.java +157 -0
  116. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryDirection.java +5 -0
  117. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java +205 -0
  118. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryUtils.java +135 -0
  119. data/test-server/instrumentation-backend/tests/sh/calaba/instrumentationbackend/query/tests/UIQueryTest.java +134 -0
  120. metadata +106 -3
  121. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/activity/SetOrientation.java +0 -39
@@ -0,0 +1,70 @@
1
+ /*
2
+ [The "BSD license"]
3
+ Copyright (c) 2005-2009 Terence Parr
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions
8
+ are met:
9
+ 1. Redistributions of source code must retain the above copyright
10
+ notice, this list of conditions and the following disclaimer.
11
+ 2. Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the distribution.
14
+ 3. The name of the author may not be used to endorse or promote products
15
+ derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+ package org.antlr.runtime.tree;
29
+
30
+ import java.util.List;
31
+
32
+ /** Queues up nodes matched on left side of -> in a tree parser. This is
33
+ * the analog of RewriteRuleTokenStream for normal parsers.
34
+ */
35
+ public class RewriteRuleNodeStream extends RewriteRuleElementStream {
36
+
37
+ public RewriteRuleNodeStream(TreeAdaptor adaptor, String elementDescription) {
38
+ super(adaptor, elementDescription);
39
+ }
40
+
41
+ /** Create a stream with one element */
42
+ public RewriteRuleNodeStream(TreeAdaptor adaptor,
43
+ String elementDescription,
44
+ Object oneElement)
45
+ {
46
+ super(adaptor, elementDescription, oneElement);
47
+ }
48
+
49
+ /** Create a stream, but feed off an existing list */
50
+ public RewriteRuleNodeStream(TreeAdaptor adaptor,
51
+ String elementDescription,
52
+ List elements)
53
+ {
54
+ super(adaptor, elementDescription, elements);
55
+ }
56
+
57
+ public Object nextNode() {
58
+ return _next();
59
+ }
60
+
61
+ protected Object toTree(Object el) {
62
+ return adaptor.dupNode(el);
63
+ }
64
+
65
+ protected Object dup(Object el) {
66
+ // we dup every node, so don't have to worry about calling dup; short-
67
+ // circuited next() so it doesn't call.
68
+ throw new UnsupportedOperationException("dup can't be called for a node stream.");
69
+ }
70
+ }
@@ -0,0 +1,86 @@
1
+ /*
2
+ [The "BSD license"]
3
+ Copyright (c) 2005-2009 Terence Parr
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions
8
+ are met:
9
+ 1. Redistributions of source code must retain the above copyright
10
+ notice, this list of conditions and the following disclaimer.
11
+ 2. Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the distribution.
14
+ 3. The name of the author may not be used to endorse or promote products
15
+ derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+ package org.antlr.runtime.tree;
29
+
30
+ import java.util.List;
31
+
32
+ public class RewriteRuleSubtreeStream extends RewriteRuleElementStream {
33
+
34
+ public RewriteRuleSubtreeStream(TreeAdaptor adaptor, String elementDescription) {
35
+ super(adaptor, elementDescription);
36
+ }
37
+
38
+ /** Create a stream with one element */
39
+ public RewriteRuleSubtreeStream(TreeAdaptor adaptor,
40
+ String elementDescription,
41
+ Object oneElement)
42
+ {
43
+ super(adaptor, elementDescription, oneElement);
44
+ }
45
+
46
+ /** Create a stream, but feed off an existing list */
47
+ public RewriteRuleSubtreeStream(TreeAdaptor adaptor,
48
+ String elementDescription,
49
+ List elements)
50
+ {
51
+ super(adaptor, elementDescription, elements);
52
+ }
53
+
54
+ /** Treat next element as a single node even if it's a subtree.
55
+ * This is used instead of next() when the result has to be a
56
+ * tree root node. Also prevents us from duplicating recently-added
57
+ * children; e.g., ^(type ID)+ adds ID to type and then 2nd iteration
58
+ * must dup the type node, but ID has been added.
59
+ *
60
+ * Referencing a rule result twice is ok; dup entire tree as
61
+ * we can't be adding trees as root; e.g., expr expr.
62
+ *
63
+ * Hideous code duplication here with super.next(). Can't think of
64
+ * a proper way to refactor. This needs to always call dup node
65
+ * and super.next() doesn't know which to call: dup node or dup tree.
66
+ */
67
+ public Object nextNode() {
68
+ //System.out.println("nextNode: elements="+elements+", singleElement="+((Tree)singleElement).toStringTree());
69
+ int n = size();
70
+ if ( dirty || (cursor>=n && n==1) ) {
71
+ // if out of elements and size is 1, dup (at most a single node
72
+ // since this is for making root nodes).
73
+ Object el = _next();
74
+ return adaptor.dupNode(el);
75
+ }
76
+ // test size above then fetch
77
+ Object tree = _next();
78
+ //System.out.println("_next="+((Tree)tree).toStringTree());
79
+ Object el = adaptor.dupNode(tree); // dup just the root (want node here)
80
+ return el;
81
+ }
82
+
83
+ protected Object dup(Object el) {
84
+ return adaptor.dupTree(el);
85
+ }
86
+ }
@@ -0,0 +1,76 @@
1
+ /*
2
+ [The "BSD license"]
3
+ Copyright (c) 2005-2009 Terence Parr
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions
8
+ are met:
9
+ 1. Redistributions of source code must retain the above copyright
10
+ notice, this list of conditions and the following disclaimer.
11
+ 2. Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the distribution.
14
+ 3. The name of the author may not be used to endorse or promote products
15
+ derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+ package org.antlr.runtime.tree;
29
+
30
+ import org.antlr.runtime.Token;
31
+
32
+ import java.util.List;
33
+
34
+ public class RewriteRuleTokenStream extends RewriteRuleElementStream {
35
+
36
+ public RewriteRuleTokenStream(TreeAdaptor adaptor, String elementDescription) {
37
+ super(adaptor, elementDescription);
38
+ }
39
+
40
+ /** Create a stream with one element */
41
+ public RewriteRuleTokenStream(TreeAdaptor adaptor,
42
+ String elementDescription,
43
+ Object oneElement)
44
+ {
45
+ super(adaptor, elementDescription, oneElement);
46
+ }
47
+
48
+ /** Create a stream, but feed off an existing list */
49
+ public RewriteRuleTokenStream(TreeAdaptor adaptor,
50
+ String elementDescription,
51
+ List elements)
52
+ {
53
+ super(adaptor, elementDescription, elements);
54
+ }
55
+
56
+ /** Get next token from stream and make a node for it */
57
+ public Object nextNode() {
58
+ Token t = (Token)_next();
59
+ return adaptor.create(t);
60
+ }
61
+
62
+ public Token nextToken() {
63
+ return (Token)_next();
64
+ }
65
+
66
+ /** Don't convert to a tree unless they explicitly call nextTree.
67
+ * This way we can do hetero tree nodes in rewrite.
68
+ */
69
+ protected Object toTree(Object el) {
70
+ return el;
71
+ }
72
+
73
+ protected Object dup(Object el) {
74
+ throw new UnsupportedOperationException("dup can't be called for a token stream.");
75
+ }
76
+ }
@@ -0,0 +1,127 @@
1
+ /*
2
+ [The "BSD license"]
3
+ Copyright (c) 2005-2009 Terence Parr
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions
8
+ are met:
9
+ 1. Redistributions of source code must retain the above copyright
10
+ notice, this list of conditions and the following disclaimer.
11
+ 2. Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the distribution.
14
+ 3. The name of the author may not be used to endorse or promote products
15
+ derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+ package org.antlr.runtime.tree;
29
+
30
+ import org.antlr.runtime.Token;
31
+
32
+ import java.util.List;
33
+
34
+ /** What does a tree look like? ANTLR has a number of support classes
35
+ * such as CommonTreeNodeStream that work on these kinds of trees. You
36
+ * don't have to make your trees implement this interface, but if you do,
37
+ * you'll be able to use more support code.
38
+ *
39
+ * NOTE: When constructing trees, ANTLR can build any kind of tree; it can
40
+ * even use Token objects as trees if you add a child list to your tokens.
41
+ *
42
+ * This is a tree node without any payload; just navigation and factory stuff.
43
+ */
44
+ public interface Tree {
45
+ public static final Tree INVALID_NODE = new CommonTree(Token.INVALID_TOKEN);
46
+
47
+ Tree getChild(int i);
48
+
49
+ int getChildCount();
50
+
51
+ // Tree tracks parent and child index now > 3.0
52
+
53
+ public Tree getParent();
54
+
55
+ public void setParent(Tree t);
56
+
57
+ /** Is there is a node above with token type ttype? */
58
+ public boolean hasAncestor(int ttype);
59
+
60
+ /** Walk upwards and get first ancestor with this token type. */
61
+ public Tree getAncestor(int ttype);
62
+
63
+ /** Return a list of all ancestors of this node. The first node of
64
+ * list is the root and the last is the parent of this node.
65
+ */
66
+ public List getAncestors();
67
+
68
+ /** This node is what child index? 0..n-1 */
69
+ public int getChildIndex();
70
+
71
+ public void setChildIndex(int index);
72
+
73
+ /** Set the parent and child index values for all children */
74
+ public void freshenParentAndChildIndexes();
75
+
76
+ /** Add t as a child to this node. If t is null, do nothing. If t
77
+ * is nil, add all children of t to this' children.
78
+ */
79
+ void addChild(Tree t);
80
+
81
+ /** Set ith child (0..n-1) to t; t must be non-null and non-nil node */
82
+ public void setChild(int i, Tree t);
83
+
84
+ public Object deleteChild(int i);
85
+
86
+ /** Delete children from start to stop and replace with t even if t is
87
+ * a list (nil-root tree). num of children can increase or decrease.
88
+ * For huge child lists, inserting children can force walking rest of
89
+ * children to set their childindex; could be slow.
90
+ */
91
+ public void replaceChildren(int startChildIndex, int stopChildIndex, Object t);
92
+
93
+ /** Indicates the node is a nil node but may still have children, meaning
94
+ * the tree is a flat list.
95
+ */
96
+ boolean isNil();
97
+
98
+ /** What is the smallest token index (indexing from 0) for this node
99
+ * and its children?
100
+ */
101
+ int getTokenStartIndex();
102
+
103
+ void setTokenStartIndex(int index);
104
+
105
+ /** What is the largest token index (indexing from 0) for this node
106
+ * and its children?
107
+ */
108
+ int getTokenStopIndex();
109
+
110
+ void setTokenStopIndex(int index);
111
+
112
+ Tree dupNode();
113
+
114
+ /** Return a token type; needed for tree parsing */
115
+ int getType();
116
+
117
+ String getText();
118
+
119
+ /** In case we don't have a token payload, what is the line for errors? */
120
+ int getLine();
121
+
122
+ int getCharPositionInLine();
123
+
124
+ String toStringTree();
125
+
126
+ String toString();
127
+ }
@@ -0,0 +1,263 @@
1
+ /*
2
+ [The "BSD license"]
3
+ Copyright (c) 2005-2009 Terence Parr
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions
8
+ are met:
9
+ 1. Redistributions of source code must retain the above copyright
10
+ notice, this list of conditions and the following disclaimer.
11
+ 2. Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the distribution.
14
+ 3. The name of the author may not be used to endorse or promote products
15
+ derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+ package org.antlr.runtime.tree;
29
+
30
+ import org.antlr.runtime.Token;
31
+ import org.antlr.runtime.TokenStream;
32
+ import org.antlr.runtime.RecognitionException;
33
+
34
+ /** How to create and navigate trees. Rather than have a separate factory
35
+ * and adaptor, I've merged them. Makes sense to encapsulate.
36
+ *
37
+ * This takes the place of the tree construction code generated in the
38
+ * generated code in 2.x and the ASTFactory.
39
+ *
40
+ * I do not need to know the type of a tree at all so they are all
41
+ * generic Objects. This may increase the amount of typecasting needed. :(
42
+ */
43
+ public interface TreeAdaptor {
44
+ // C o n s t r u c t i o n
45
+
46
+ /** Create a tree node from Token object; for CommonTree type trees,
47
+ * then the token just becomes the payload. This is the most
48
+ * common create call.
49
+ *
50
+ * Override if you want another kind of node to be built.
51
+ */
52
+ public Object create(Token payload);
53
+
54
+ /** Duplicate a single tree node.
55
+ * Override if you want another kind of node to be built.
56
+ */
57
+ public Object dupNode(Object treeNode);
58
+
59
+ /** Duplicate tree recursively, using dupNode() for each node */
60
+ public Object dupTree(Object tree);
61
+
62
+ /** Return a nil node (an empty but non-null node) that can hold
63
+ * a list of element as the children. If you want a flat tree (a list)
64
+ * use "t=adaptor.nil(); t.addChild(x); t.addChild(y);"
65
+ */
66
+ public Object nil();
67
+
68
+ /** Return a tree node representing an error. This node records the
69
+ * tokens consumed during error recovery. The start token indicates the
70
+ * input symbol at which the error was detected. The stop token indicates
71
+ * the last symbol consumed during recovery.
72
+ *
73
+ * You must specify the input stream so that the erroneous text can
74
+ * be packaged up in the error node. The exception could be useful
75
+ * to some applications; default implementation stores ptr to it in
76
+ * the CommonErrorNode.
77
+ *
78
+ * This only makes sense during token parsing, not tree parsing.
79
+ * Tree parsing should happen only when parsing and tree construction
80
+ * succeed.
81
+ */
82
+ public Object errorNode(TokenStream input, Token start, Token stop, RecognitionException e);
83
+
84
+ /** Is tree considered a nil node used to make lists of child nodes? */
85
+ public boolean isNil(Object tree);
86
+
87
+ /** Add a child to the tree t. If child is a flat tree (a list), make all
88
+ * in list children of t. Warning: if t has no children, but child does
89
+ * and child isNil then you can decide it is ok to move children to t via
90
+ * t.children = child.children; i.e., without copying the array. Just
91
+ * make sure that this is consistent with have the user will build
92
+ * ASTs. Do nothing if t or child is null.
93
+ */
94
+ public void addChild(Object t, Object child);
95
+
96
+ /** If oldRoot is a nil root, just copy or move the children to newRoot.
97
+ * If not a nil root, make oldRoot a child of newRoot.
98
+ *
99
+ * old=^(nil a b c), new=r yields ^(r a b c)
100
+ * old=^(a b c), new=r yields ^(r ^(a b c))
101
+ *
102
+ * If newRoot is a nil-rooted single child tree, use the single
103
+ * child as the new root node.
104
+ *
105
+ * old=^(nil a b c), new=^(nil r) yields ^(r a b c)
106
+ * old=^(a b c), new=^(nil r) yields ^(r ^(a b c))
107
+ *
108
+ * If oldRoot was null, it's ok, just return newRoot (even if isNil).
109
+ *
110
+ * old=null, new=r yields r
111
+ * old=null, new=^(nil r) yields ^(nil r)
112
+ *
113
+ * Return newRoot. Throw an exception if newRoot is not a
114
+ * simple node or nil root with a single child node--it must be a root
115
+ * node. If newRoot is ^(nil x) return x as newRoot.
116
+ *
117
+ * Be advised that it's ok for newRoot to point at oldRoot's
118
+ * children; i.e., you don't have to copy the list. We are
119
+ * constructing these nodes so we should have this control for
120
+ * efficiency.
121
+ */
122
+ public Object becomeRoot(Object newRoot, Object oldRoot);
123
+
124
+ /** Given the root of the subtree created for this rule, post process
125
+ * it to do any simplifications or whatever you want. A required
126
+ * behavior is to convert ^(nil singleSubtree) to singleSubtree
127
+ * as the setting of start/stop indexes relies on a single non-nil root
128
+ * for non-flat trees.
129
+ *
130
+ * Flat trees such as for lists like "idlist : ID+ ;" are left alone
131
+ * unless there is only one ID. For a list, the start/stop indexes
132
+ * are set in the nil node.
133
+ *
134
+ * This method is executed after all rule tree construction and right
135
+ * before setTokenBoundaries().
136
+ */
137
+ public Object rulePostProcessing(Object root);
138
+
139
+ /** For identifying trees.
140
+ *
141
+ * How to identify nodes so we can say "add node to a prior node"?
142
+ * Even becomeRoot is an issue. Use System.identityHashCode(node)
143
+ * usually.
144
+ */
145
+ public int getUniqueID(Object node);
146
+
147
+
148
+ // R e w r i t e R u l e s
149
+
150
+ /** Create a node for newRoot make it the root of oldRoot.
151
+ * If oldRoot is a nil root, just copy or move the children to newRoot.
152
+ * If not a nil root, make oldRoot a child of newRoot.
153
+ *
154
+ * Return node created for newRoot.
155
+ *
156
+ * Be advised: when debugging ASTs, the DebugTreeAdaptor manually
157
+ * calls create(Token child) and then plain becomeRoot(node, node)
158
+ * because it needs to trap calls to create, but it can't since it delegates
159
+ * to not inherits from the TreeAdaptor.
160
+ */
161
+ public Object becomeRoot(Token newRoot, Object oldRoot);
162
+
163
+ /** Create a new node derived from a token, with a new token type.
164
+ * This is invoked from an imaginary node ref on right side of a
165
+ * rewrite rule as IMAG[$tokenLabel].
166
+ *
167
+ * This should invoke createToken(Token).
168
+ */
169
+ public Object create(int tokenType, Token fromToken);
170
+
171
+ /** Same as create(tokenType,fromToken) except set the text too.
172
+ * This is invoked from an imaginary node ref on right side of a
173
+ * rewrite rule as IMAG[$tokenLabel, "IMAG"].
174
+ *
175
+ * This should invoke createToken(Token).
176
+ */
177
+ public Object create(int tokenType, Token fromToken, String text);
178
+
179
+ /** Create a new node derived from a token, with a new token type.
180
+ * This is invoked from an imaginary node ref on right side of a
181
+ * rewrite rule as IMAG["IMAG"].
182
+ *
183
+ * This should invoke createToken(int,String).
184
+ */
185
+ public Object create(int tokenType, String text);
186
+
187
+
188
+ // C o n t e n t
189
+
190
+ /** For tree parsing, I need to know the token type of a node */
191
+ public int getType(Object t);
192
+
193
+ /** Node constructors can set the type of a node */
194
+ public void setType(Object t, int type);
195
+
196
+ public String getText(Object t);
197
+
198
+ /** Node constructors can set the text of a node */
199
+ public void setText(Object t, String text);
200
+
201
+ /** Return the token object from which this node was created.
202
+ * Currently used only for printing an error message.
203
+ * The error display routine in BaseRecognizer needs to
204
+ * display where the input the error occurred. If your
205
+ * tree of limitation does not store information that can
206
+ * lead you to the token, you can create a token filled with
207
+ * the appropriate information and pass that back. See
208
+ * BaseRecognizer.getErrorMessage().
209
+ */
210
+ public Token getToken(Object t);
211
+
212
+ /** Where are the bounds in the input token stream for this node and
213
+ * all children? Each rule that creates AST nodes will call this
214
+ * method right before returning. Flat trees (i.e., lists) will
215
+ * still usually have a nil root node just to hold the children list.
216
+ * That node would contain the start/stop indexes then.
217
+ */
218
+ public void setTokenBoundaries(Object t, Token startToken, Token stopToken);
219
+
220
+ /** Get the token start index for this subtree; return -1 if no such index */
221
+ public int getTokenStartIndex(Object t);
222
+
223
+ /** Get the token stop index for this subtree; return -1 if no such index */
224
+ public int getTokenStopIndex(Object t);
225
+
226
+
227
+ // N a v i g a t i o n / T r e e P a r s i n g
228
+
229
+ /** Get a child 0..n-1 node */
230
+ public Object getChild(Object t, int i);
231
+
232
+ /** Set ith child (0..n-1) to t; t must be non-null and non-nil node */
233
+ public void setChild(Object t, int i, Object child);
234
+
235
+ /** Remove ith child and shift children down from right. */
236
+ public Object deleteChild(Object t, int i);
237
+
238
+ /** How many children? If 0, then this is a leaf node */
239
+ public int getChildCount(Object t);
240
+
241
+ /** Who is the parent node of this node; if null, implies node is root.
242
+ * If your node type doesn't handle this, it's ok but the tree rewrites
243
+ * in tree parsers need this functionality.
244
+ */
245
+ public Object getParent(Object t);
246
+ public void setParent(Object t, Object parent);
247
+
248
+ /** What index is this node in the child list? Range: 0..n-1
249
+ * If your node type doesn't handle this, it's ok but the tree rewrites
250
+ * in tree parsers need this functionality.
251
+ */
252
+ public int getChildIndex(Object t);
253
+ public void setChildIndex(Object t, int index);
254
+
255
+ /** Replace from start to stop child index of parent with t, which might
256
+ * be a list. Number of children may be different
257
+ * after this call.
258
+ *
259
+ * If parent is null, don't do anything; must be at root of overall tree.
260
+ * Can't replace whatever points to the parent externally. Do nothing.
261
+ */
262
+ public void replaceChildren(Object parent, int startChildIndex, int stopChildIndex, Object t);
263
+ }