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,52 @@
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;
29
+
30
+ /** Rules that return more than a single value must return an object
31
+ * containing all the values. Besides the properties defined in
32
+ * RuleLabelScope.predefinedRulePropertiesScope there may be user-defined
33
+ * return values. This class simply defines the minimum properties that
34
+ * are always defined and methods to access the others that might be
35
+ * available depending on output option such as template and tree.
36
+ *
37
+ * Note text is not an actual property of the return value, it is computed
38
+ * from start and stop using the input stream's toString() method. I
39
+ * could add a ctor to this so that we can pass in and store the input
40
+ * stream, but I'm not sure we want to do that. It would seem to be undefined
41
+ * to get the .text property anyway if the rule matches tokens from multiple
42
+ * input streams.
43
+ *
44
+ * I do not use getters for fields of objects that are used simply to
45
+ * group values such as this aggregate. The getters/setters are there to
46
+ * satisfy the superclass interface.
47
+ */
48
+ public class ParserRuleReturnScope extends RuleReturnScope {
49
+ public Token start, stop;
50
+ public Object getStart() { return start; }
51
+ public Object getStop() { return stop; }
52
+ }
@@ -0,0 +1,180 @@
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;
29
+
30
+ import org.antlr.runtime.tree.*;
31
+
32
+ /** The root of the ANTLR exception hierarchy.
33
+ *
34
+ * To avoid English-only error messages and to generally make things
35
+ * as flexible as possible, these exceptions are not created with strings,
36
+ * but rather the information necessary to generate an error. Then
37
+ * the various reporting methods in Parser and Lexer can be overridden
38
+ * to generate a localized error message. For example, MismatchedToken
39
+ * exceptions are built with the expected token type.
40
+ * So, don't expect getMessage() to return anything.
41
+ *
42
+ * Note that as of Java 1.4, you can access the stack trace, which means
43
+ * that you can compute the complete trace of rules from the start symbol.
44
+ * This gives you considerable context information with which to generate
45
+ * useful error messages.
46
+ *
47
+ * ANTLR generates code that throws exceptions upon recognition error and
48
+ * also generates code to catch these exceptions in each rule. If you
49
+ * want to quit upon first error, you can turn off the automatic error
50
+ * handling mechanism using rulecatch action, but you still need to
51
+ * override methods mismatch and recoverFromMismatchSet.
52
+ *
53
+ * In general, the recognition exceptions can track where in a grammar a
54
+ * problem occurred and/or what was the expected input. While the parser
55
+ * knows its state (such as current input symbol and line info) that
56
+ * state can change before the exception is reported so current token index
57
+ * is computed and stored at exception time. From this info, you can
58
+ * perhaps print an entire line of input not just a single token, for example.
59
+ * Better to just say the recognizer had a problem and then let the parser
60
+ * figure out a fancy report.
61
+ */
62
+ public class RecognitionException extends Exception {
63
+ /** What input stream did the error occur in? */
64
+ public transient IntStream input;
65
+
66
+ /** What is index of token/char were we looking at when the error occurred? */
67
+ public int index;
68
+
69
+ /** The current Token when an error occurred. Since not all streams
70
+ * can retrieve the ith Token, we have to track the Token object.
71
+ * For parsers. Even when it's a tree parser, token might be set.
72
+ */
73
+ public Token token;
74
+
75
+ /** If this is a tree parser exception, node is set to the node with
76
+ * the problem.
77
+ */
78
+ public Object node;
79
+
80
+ /** The current char when an error occurred. For lexers. */
81
+ public int c;
82
+
83
+ /** Track the line at which the error occurred in case this is
84
+ * generated from a lexer. We need to track this since the
85
+ * unexpected char doesn't carry the line info.
86
+ */
87
+ public int line;
88
+
89
+ public int charPositionInLine;
90
+
91
+ /** If you are parsing a tree node stream, you will encounter som
92
+ * imaginary nodes w/o line/col info. We now search backwards looking
93
+ * for most recent token with line/col info, but notify getErrorHeader()
94
+ * that info is approximate.
95
+ */
96
+ public boolean approximateLineInfo;
97
+
98
+ /** Used for remote debugger deserialization */
99
+ public RecognitionException() {
100
+ }
101
+
102
+ public RecognitionException(IntStream input) {
103
+ this.input = input;
104
+ this.index = input.index();
105
+ if ( input instanceof TokenStream ) {
106
+ this.token = ((TokenStream)input).LT(1);
107
+ this.line = token.getLine();
108
+ this.charPositionInLine = token.getCharPositionInLine();
109
+ }
110
+ if ( input instanceof TreeNodeStream ) {
111
+ extractInformationFromTreeNodeStream(input);
112
+ }
113
+ else if ( input instanceof CharStream ) {
114
+ this.c = input.LA(1);
115
+ this.line = ((CharStream)input).getLine();
116
+ this.charPositionInLine = ((CharStream)input).getCharPositionInLine();
117
+ }
118
+ else {
119
+ this.c = input.LA(1);
120
+ }
121
+ }
122
+
123
+ protected void extractInformationFromTreeNodeStream(IntStream input) {
124
+ TreeNodeStream nodes = (TreeNodeStream)input;
125
+ this.node = nodes.LT(1);
126
+ TreeAdaptor adaptor = nodes.getTreeAdaptor();
127
+ Token payload = adaptor.getToken(node);
128
+ if ( payload!=null ) {
129
+ this.token = payload;
130
+ if ( payload.getLine()<= 0 ) {
131
+ // imaginary node; no line/pos info; scan backwards
132
+ int i = -1;
133
+ Object priorNode = nodes.LT(i);
134
+ while ( priorNode!=null ) {
135
+ Token priorPayload = adaptor.getToken(priorNode);
136
+ if ( priorPayload!=null && priorPayload.getLine()>0 ) {
137
+ // we found the most recent real line / pos info
138
+ this.line = priorPayload.getLine();
139
+ this.charPositionInLine = priorPayload.getCharPositionInLine();
140
+ this.approximateLineInfo = true;
141
+ break;
142
+ }
143
+ --i;
144
+ priorNode = nodes.LT(i);
145
+ }
146
+ }
147
+ else { // node created from real token
148
+ this.line = payload.getLine();
149
+ this.charPositionInLine = payload.getCharPositionInLine();
150
+ }
151
+ }
152
+ else if ( this.node instanceof Tree) {
153
+ this.line = ((Tree)this.node).getLine();
154
+ this.charPositionInLine = ((Tree)this.node).getCharPositionInLine();
155
+ if ( this.node instanceof CommonTree) {
156
+ this.token = ((CommonTree)this.node).token;
157
+ }
158
+ }
159
+ else {
160
+ int type = adaptor.getType(this.node);
161
+ String text = adaptor.getText(this.node);
162
+ this.token = new CommonToken(type, text);
163
+ }
164
+ }
165
+
166
+ /** Return the token type or char of the unexpected input element */
167
+ public int getUnexpectedType() {
168
+ if ( input instanceof TokenStream ) {
169
+ return token.getType();
170
+ }
171
+ else if ( input instanceof TreeNodeStream ) {
172
+ TreeNodeStream nodes = (TreeNodeStream)input;
173
+ TreeAdaptor adaptor = nodes.getTreeAdaptor();
174
+ return adaptor.getType(node);
175
+ }
176
+ else {
177
+ return c;
178
+ }
179
+ }
180
+ }
@@ -0,0 +1,144 @@
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
+ */package org.antlr.runtime;
28
+
29
+ import java.util.Map;
30
+
31
+ /** The set of fields needed by an abstract recognizer to recognize input
32
+ * and recover from errors etc... As a separate state object, it can be
33
+ * shared among multiple grammars; e.g., when one grammar imports another.
34
+ *
35
+ * These fields are publically visible but the actual state pointer per
36
+ * parser is protected.
37
+ */
38
+ public class RecognizerSharedState {
39
+ /** Track the set of token types that can follow any rule invocation.
40
+ * Stack grows upwards. When it hits the max, it grows 2x in size
41
+ * and keeps going.
42
+ */
43
+ public BitSet[] following = new BitSet[BaseRecognizer.INITIAL_FOLLOW_STACK_SIZE];
44
+ public int _fsp = -1;
45
+
46
+ /** This is true when we see an error and before having successfully
47
+ * matched a token. Prevents generation of more than one error message
48
+ * per error.
49
+ */
50
+ public boolean errorRecovery = false;
51
+
52
+ /** The index into the input stream where the last error occurred.
53
+ * This is used to prevent infinite loops where an error is found
54
+ * but no token is consumed during recovery...another error is found,
55
+ * ad naseum. This is a failsafe mechanism to guarantee that at least
56
+ * one token/tree node is consumed for two errors.
57
+ */
58
+ public int lastErrorIndex = -1;
59
+
60
+ /** In lieu of a return value, this indicates that a rule or token
61
+ * has failed to match. Reset to false upon valid token match.
62
+ */
63
+ public boolean failed = false;
64
+
65
+ /** Did the recognizer encounter a syntax error? Track how many. */
66
+ public int syntaxErrors = 0;
67
+
68
+ /** If 0, no backtracking is going on. Safe to exec actions etc...
69
+ * If >0 then it's the level of backtracking.
70
+ */
71
+ public int backtracking = 0;
72
+
73
+ /** An array[size num rules] of Map<Integer,Integer> that tracks
74
+ * the stop token index for each rule. ruleMemo[ruleIndex] is
75
+ * the memoization table for ruleIndex. For key ruleStartIndex, you
76
+ * get back the stop token for associated rule or MEMO_RULE_FAILED.
77
+ *
78
+ * This is only used if rule memoization is on (which it is by default).
79
+ */
80
+ public Map[] ruleMemo;
81
+
82
+
83
+ // LEXER FIELDS (must be in same state object to avoid casting
84
+ // constantly in generated code and Lexer object) :(
85
+
86
+
87
+ /** The goal of all lexer rules/methods is to create a token object.
88
+ * This is an instance variable as multiple rules may collaborate to
89
+ * create a single token. nextToken will return this object after
90
+ * matching lexer rule(s). If you subclass to allow multiple token
91
+ * emissions, then set this to the last token to be matched or
92
+ * something nonnull so that the auto token emit mechanism will not
93
+ * emit another token.
94
+ */
95
+ public Token token;
96
+
97
+ /** What character index in the stream did the current token start at?
98
+ * Needed, for example, to get the text for current token. Set at
99
+ * the start of nextToken.
100
+ */
101
+ public int tokenStartCharIndex = -1;
102
+
103
+ /** The line on which the first character of the token resides */
104
+ public int tokenStartLine;
105
+
106
+ /** The character position of first character within the line */
107
+ public int tokenStartCharPositionInLine;
108
+
109
+ /** The channel number for the current token */
110
+ public int channel;
111
+
112
+ /** The token type for the current token */
113
+ public int type;
114
+
115
+ /** You can set the text for the current token to override what is in
116
+ * the input char buffer. Use setText() or can set this instance var.
117
+ */
118
+ public String text;
119
+
120
+ public RecognizerSharedState() {;}
121
+
122
+ public RecognizerSharedState(RecognizerSharedState state) {
123
+ if ( this.following.length < state.following.length ) {
124
+ this.following = new BitSet[state.following.length];
125
+ }
126
+ System.arraycopy(state.following, 0, this.following, 0, state.following.length);
127
+ this._fsp = state._fsp;
128
+ this.errorRecovery = state.errorRecovery;
129
+ this.lastErrorIndex = state.lastErrorIndex;
130
+ this.failed = state.failed;
131
+ this.syntaxErrors = state.syntaxErrors;
132
+ this.backtracking = state.backtracking;
133
+ if ( state.ruleMemo!=null ) {
134
+ this.ruleMemo = new Map[state.ruleMemo.length];
135
+ System.arraycopy(state.ruleMemo, 0, this.ruleMemo, 0, state.ruleMemo.length);
136
+ }
137
+ this.token = state.token;
138
+ this.tokenStartCharIndex = state.tokenStartCharIndex;
139
+ this.tokenStartCharPositionInLine = state.tokenStartCharPositionInLine;
140
+ this.channel = state.channel;
141
+ this.type = state.type;
142
+ this.text = state.text;
143
+ }
144
+ }
@@ -0,0 +1,42 @@
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;
29
+
30
+ /** Rules can return start/stop info as well as possible trees and templates */
31
+ public class RuleReturnScope {
32
+ /** Return the start token or tree */
33
+ public Object getStart() { return null; }
34
+ /** Return the stop token or tree */
35
+ public Object getStop() { return null; }
36
+ /** Has a value potentially if output=AST; */
37
+ public Object getTree() { return null; }
38
+ /** Has a value potentially if output=template; Don't use StringTemplate
39
+ * type as it then causes a dependency with ST lib.
40
+ */
41
+ public Object getTemplate() { return null; }
42
+ }
@@ -0,0 +1,204 @@
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
+
29
+ package org.antlr.runtime;
30
+
31
+ import java.io.IOException;
32
+ import java.io.FileInputStream;
33
+ import java.io.BufferedInputStream;
34
+ import java.io.DataInputStream;
35
+ import java.util.List;
36
+ import java.util.ArrayList;
37
+
38
+ public class SerializedGrammar {
39
+ public static final String COOKIE = "$ANTLR";
40
+ public static final int FORMAT_VERSION = 1;
41
+ //public static org.antlr.tool.Grammar gr; // TESTING ONLY; remove later
42
+
43
+ private static final String TAG = "ANTLR:SerializedGrammar";
44
+
45
+ public String name;
46
+ public char type; // in {l, p, t, c}
47
+ public List rules;
48
+
49
+ class Rule {
50
+ String name;
51
+ Block block;
52
+ public Rule(String name, Block block) {
53
+ this.name = name;
54
+ this.block = block;
55
+ }
56
+ public String toString() {
57
+ return name+":"+block;
58
+ }
59
+ }
60
+
61
+ class Block {
62
+ List[] alts;
63
+ public Block(List[] alts) {
64
+ this.alts = alts;
65
+ }
66
+ public String toString() {
67
+ StringBuffer buf = new StringBuffer();
68
+ buf.append("(");
69
+ for (int i = 0; i < alts.length; i++) {
70
+ List alt = alts[i];
71
+ if ( i>0 ) buf.append("|");
72
+ buf.append(alt.toString());
73
+ }
74
+ buf.append(")");
75
+ return buf.toString();
76
+ }
77
+ }
78
+
79
+ class TokenRef {
80
+ int ttype;
81
+ public TokenRef(int ttype) { this.ttype = ttype; }
82
+ public String toString() { return String.valueOf(ttype); }
83
+ }
84
+
85
+ class RuleRef {
86
+ int ruleIndex;
87
+ public RuleRef(int ruleIndex) { this.ruleIndex = ruleIndex; }
88
+ public String toString() { return String.valueOf(ruleIndex); }
89
+ }
90
+
91
+ public SerializedGrammar(String filename) throws IOException {
92
+ //System.out.println("loading "+filename);
93
+ android.util.Log.i(TAG, "loading "+filename);
94
+ FileInputStream fis = new FileInputStream(filename);
95
+ BufferedInputStream bos = new BufferedInputStream(fis);
96
+ DataInputStream in = new DataInputStream(bos);
97
+ readFile(in);
98
+ in.close();
99
+ }
100
+
101
+ protected void readFile(DataInputStream in) throws IOException {
102
+ String cookie = readString(in); // get $ANTLR
103
+ if ( !cookie.equals(COOKIE) ) throw new IOException("not a serialized grammar file");
104
+ int version = in.readByte();
105
+ char grammarType = (char)in.readByte();
106
+ this.type = grammarType;
107
+ String grammarName = readString(in);
108
+ this.name = grammarName;
109
+ //System.out.println(grammarType+" grammar "+grammarName);
110
+ android.util.Log.i(TAG, grammarType+" grammar "+grammarName);
111
+ int numRules = in.readShort();
112
+ //System.out.println("num rules = "+numRules);
113
+ android.util.Log.i(TAG, "num rules = "+numRules);
114
+ rules = readRules(in, numRules);
115
+ }
116
+
117
+ protected List readRules(DataInputStream in, int numRules) throws IOException {
118
+ List rules = new ArrayList();
119
+ for (int i=0; i<numRules; i++) {
120
+ Rule r = readRule(in);
121
+ rules.add(r);
122
+ }
123
+ return rules;
124
+ }
125
+
126
+ protected Rule readRule(DataInputStream in) throws IOException {
127
+ byte R = in.readByte();
128
+ if ( R!='R' ) throw new IOException("missing R on start of rule");
129
+ String name = readString(in);
130
+ //System.out.println("rule: "+name);
131
+ android.util.Log.i(TAG, "rule: "+name);
132
+ byte B = in.readByte();
133
+ Block b = readBlock(in);
134
+ byte period = in.readByte();
135
+ if ( period!='.' ) throw new IOException("missing . on end of rule");
136
+ return new Rule(name, b);
137
+ }
138
+
139
+ protected Block readBlock(DataInputStream in) throws IOException {
140
+ int nalts = in.readShort();
141
+ List[] alts = new List[nalts];
142
+ //System.out.println("enter block n="+nalts);
143
+ for (int i=0; i<nalts; i++) {
144
+ List alt = readAlt(in);
145
+ alts[i] = alt;
146
+ }
147
+ //System.out.println("exit block");
148
+ return new Block(alts);
149
+ }
150
+
151
+ protected List readAlt(DataInputStream in) throws IOException {
152
+ List alt = new ArrayList();
153
+ byte A = in.readByte();
154
+ if ( A!='A' ) throw new IOException("missing A on start of alt");
155
+ byte cmd = in.readByte();
156
+ while ( cmd!=';' ) {
157
+ switch (cmd) {
158
+ case 't' :
159
+ int ttype = in.readShort();
160
+ alt.add(new TokenRef(ttype));
161
+ //System.out.println("read token "+gr.getTokenDisplayName(ttype));
162
+ break;
163
+ case 'r' :
164
+ int ruleIndex = in.readShort();
165
+ alt.add(new RuleRef(ruleIndex));
166
+ //System.out.println("read rule "+gr.getRuleName(ruleIndex));
167
+ break;
168
+ case '.' : // wildcard
169
+ break;
170
+ case '-' : // range
171
+ int from = in.readChar();
172
+ int to = in.readChar();
173
+ break;
174
+ case '~' : // not
175
+ int notThisTokenType = in.readShort();
176
+ break;
177
+ case 'B' : // nested block
178
+ Block b = readBlock(in);
179
+ alt.add(b);
180
+ break;
181
+ }
182
+ cmd = in.readByte();
183
+ }
184
+ //System.out.println("exit alt");
185
+ return alt;
186
+ }
187
+
188
+ protected String readString(DataInputStream in) throws IOException {
189
+ byte c = in.readByte();
190
+ StringBuffer buf = new StringBuffer();
191
+ while ( c!=';' ) {
192
+ buf.append((char)c);
193
+ c = in.readByte();
194
+ }
195
+ return buf.toString();
196
+ }
197
+
198
+ public String toString() {
199
+ StringBuffer buf = new StringBuffer();
200
+ buf.append(type+" grammar "+name);
201
+ buf.append(rules);
202
+ return buf.toString();
203
+ }
204
+ }