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.
- data/bin/calabash-android-build.rb +6 -0
- data/bin/calabash-android-setup.rb +2 -3
- data/lib/calabash-android/canned_steps.md +1 -1
- data/lib/calabash-android/helpers.rb +35 -2
- data/lib/calabash-android/lib/TestServer.apk +0 -0
- data/lib/calabash-android/operations.rb +13 -6
- data/lib/calabash-android/version.rb +1 -1
- data/test-server/instrumentation-backend/.classpath +2 -1
- data/test-server/instrumentation-backend/antlr.sh +2 -0
- data/test-server/instrumentation-backend/antlr/UIQuery.g +70 -0
- data/test-server/instrumentation-backend/antlr/UIQuery.tokens +12 -0
- data/test-server/instrumentation-backend/build-libs/antlr-3.4-complete.jar +0 -0
- data/test-server/instrumentation-backend/build-libs/junit.jar +0 -0
- data/test-server/instrumentation-backend/build.xml +56 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/ANTLRFileStream.java +78 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/ANTLRInputStream.java +70 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/ANTLRReaderStream.java +95 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/ANTLRStringStream.java +230 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/BaseRecognizer.java +894 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/BitSet.java +325 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/BufferedTokenStream.java +272 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/CharStream.java +57 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/CharStreamState.java +45 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/ClassicToken.java +141 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/CommonToken.java +191 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/CommonTokenStream.java +153 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/DFA.java +250 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/EarlyExitException.java +41 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/FailedPredicateException.java +54 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/IntStream.java +122 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/LegacyCommonTokenStream.java +394 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/Lexer.java +340 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedNotSetException.java +41 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedRangeException.java +45 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedSetException.java +44 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedTokenException.java +45 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedTreeNodeException.java +49 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/MissingTokenException.java +56 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/NoViableAltException.java +57 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/Parser.java +98 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/ParserRuleReturnScope.java +52 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/RecognitionException.java +180 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/RecognizerSharedState.java +144 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/RuleReturnScope.java +42 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/SerializedGrammar.java +204 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/Token.java +92 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/TokenRewriteStream.java +569 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/TokenSource.java +54 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/TokenStream.java +75 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/UnbufferedTokenStream.java +82 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/UnwantedTokenException.java +53 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/BlankDebugEventListener.java +77 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugEventHub.java +292 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugEventListener.java +323 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugEventRepeater.java +88 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugEventSocketProxy.java +358 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugParser.java +101 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugTokenStream.java +156 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugTreeAdaptor.java +250 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugTreeNodeStream.java +155 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugTreeParser.java +112 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/ParseTreeBuilder.java +109 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/Profiler.java +772 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/RemoteDebugEventSocketListener.java +541 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/TraceDebugEventListener.java +108 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/Tracer.java +69 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/DoubleKeyMap.java +62 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/FastQueue.java +100 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/IntArray.java +87 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/LookaheadStream.java +161 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/Stats.java +189 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/BaseTree.java +349 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/BaseTreeAdaptor.java +279 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/BufferedTreeNodeStream.java +489 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/CommonErrorNode.java +108 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/CommonTree.java +185 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/CommonTreeAdaptor.java +168 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/CommonTreeNodeStream.java +171 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/ParseTree.java +119 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteCardinalityException.java +47 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteEarlyExitException.java +39 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteEmptyStreamException.java +35 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteRuleElementStream.java +210 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteRuleNodeStream.java +70 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteRuleSubtreeStream.java +86 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteRuleTokenStream.java +76 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/Tree.java +127 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeAdaptor.java +263 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeFilter.java +135 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeIterator.java +132 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeNodeStream.java +106 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeParser.java +169 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreePatternLexer.java +135 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreePatternParser.java +154 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeRewriter.java +124 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeRuleReturnScope.java +41 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeVisitor.java +69 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeVisitorAction.java +47 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeWizard.java +531 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java +22 -7
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/InstrumentationBackend.java +4 -4
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/Result.java +0 -1
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/HttpServer.java +161 -129
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/activity/SetActivityOrientation.java +5 -7
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/GetViewProperty.java +1 -7
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/Query.java +70 -61
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/UIQuery.tokens +12 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ViewMapper.java +63 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/antlr/UIQuery.tokens +10 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/antlr/UIQueryLexer.java +945 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/antlr/UIQueryParser.java +463 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/InvalidUIQueryException.java +10 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryAST.java +8 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTClassName.java +115 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTWith.java +157 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryDirection.java +5 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java +205 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryUtils.java +135 -0
- data/test-server/instrumentation-backend/tests/sh/calaba/instrumentationbackend/query/tests/UIQueryTest.java +134 -0
- metadata +106 -3
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/activity/SetOrientation.java +0 -39
@@ -0,0 +1,250 @@
|
|
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
|
+
/** A DFA implemented as a set of transition tables.
|
31
|
+
*
|
32
|
+
* Any state that has a semantic predicate edge is special; those states
|
33
|
+
* are generated with if-then-else structures in a specialStateTransition()
|
34
|
+
* which is generated by cyclicDFA template.
|
35
|
+
*
|
36
|
+
* There are at most 32767 states (16-bit signed short).
|
37
|
+
* Could get away with byte sometimes but would have to generate different
|
38
|
+
* types and the simulation code too. For a point of reference, the Java
|
39
|
+
* lexer's Tokens rule DFA has 326 states roughly.
|
40
|
+
*/
|
41
|
+
public class DFA {
|
42
|
+
protected short[] eot;
|
43
|
+
protected short[] eof;
|
44
|
+
protected char[] min;
|
45
|
+
protected char[] max;
|
46
|
+
protected short[] accept;
|
47
|
+
protected short[] special;
|
48
|
+
protected short[][] transition;
|
49
|
+
|
50
|
+
protected int decisionNumber;
|
51
|
+
|
52
|
+
/** Which recognizer encloses this DFA? Needed to check backtracking */
|
53
|
+
protected BaseRecognizer recognizer;
|
54
|
+
|
55
|
+
public static final boolean debug = false;
|
56
|
+
private static final String TAG = "ANTLR:DFA";
|
57
|
+
|
58
|
+
/** From the input stream, predict what alternative will succeed
|
59
|
+
* using this DFA (representing the covering regular approximation
|
60
|
+
* to the underlying CFL). Return an alternative number 1..n. Throw
|
61
|
+
* an exception upon error.
|
62
|
+
*/
|
63
|
+
public int predict(IntStream input)
|
64
|
+
throws RecognitionException
|
65
|
+
{
|
66
|
+
if ( debug ) {
|
67
|
+
//System.err.println("Enter DFA.predict for decision "+decisionNumber);
|
68
|
+
android.util.Log.e(TAG, "Enter DFA.predict for decision "+decisionNumber);
|
69
|
+
}
|
70
|
+
int mark = input.mark(); // remember where decision started in input
|
71
|
+
int s = 0; // we always start at s0
|
72
|
+
try {
|
73
|
+
while ( true ) {
|
74
|
+
if ( debug ) { //System.err.println("DFA "+decisionNumber+" state "+s+" LA(1)="+(char)input.LA(1)+"("+input.LA(1)+
|
75
|
+
//"), index="+input.index());
|
76
|
+
android.util.Log.e(TAG, "DFA "+decisionNumber+" state "+s+" LA(1)="+(char)input.LA(1)+"("+input.LA(1)+
|
77
|
+
"), index="+input.index());
|
78
|
+
}
|
79
|
+
int specialState = special[s];
|
80
|
+
if ( specialState>=0 ) {
|
81
|
+
if ( debug ) {
|
82
|
+
//System.err.println("DFA "+decisionNumber+
|
83
|
+
//" state "+s+" is special state "+specialState);
|
84
|
+
android.util.Log.e(TAG, "DFA "+decisionNumber+" state "+s+" is special state "+specialState);
|
85
|
+
}
|
86
|
+
s = specialStateTransition(specialState,input);
|
87
|
+
if ( debug ) {
|
88
|
+
//System.err.println("DFA "+decisionNumber+
|
89
|
+
//" returns from special state "+specialState+" to "+s);
|
90
|
+
android.util.Log.e(TAG, "DFA "+decisionNumber+" returns from special state "+specialState+" to "+s);
|
91
|
+
}
|
92
|
+
if ( s==-1 ) {
|
93
|
+
noViableAlt(s,input);
|
94
|
+
return 0;
|
95
|
+
}
|
96
|
+
input.consume();
|
97
|
+
continue;
|
98
|
+
}
|
99
|
+
if ( accept[s] >= 1 ) {
|
100
|
+
if ( debug ) { //System.err.println("accept; predict "+accept[s]+" from state "+s);
|
101
|
+
android.util.Log.e(TAG, "accept; predict "+accept[s]+" from state "+s);
|
102
|
+
}
|
103
|
+
return accept[s];
|
104
|
+
}
|
105
|
+
// look for a normal char transition
|
106
|
+
char c = (char)input.LA(1); // -1 == \uFFFF, all tokens fit in 65000 space
|
107
|
+
if (c>=min[s] && c<=max[s]) {
|
108
|
+
int snext = transition[s][c-min[s]]; // move to next state
|
109
|
+
if ( snext < 0 ) {
|
110
|
+
// was in range but not a normal transition
|
111
|
+
// must check EOT, which is like the else clause.
|
112
|
+
// eot[s]>=0 indicates that an EOT edge goes to another
|
113
|
+
// state.
|
114
|
+
if ( eot[s]>=0 ) { // EOT Transition to accept state?
|
115
|
+
if ( debug ) { //System.err.println("EOT transition");
|
116
|
+
android.util.Log.e(TAG, "EOT transition");
|
117
|
+
}
|
118
|
+
s = eot[s];
|
119
|
+
input.consume();
|
120
|
+
// TODO: I had this as return accept[eot[s]]
|
121
|
+
// which assumed here that the EOT edge always
|
122
|
+
// went to an accept...faster to do this, but
|
123
|
+
// what about predicated edges coming from EOT
|
124
|
+
// target?
|
125
|
+
continue;
|
126
|
+
}
|
127
|
+
noViableAlt(s,input);
|
128
|
+
return 0;
|
129
|
+
}
|
130
|
+
s = snext;
|
131
|
+
input.consume();
|
132
|
+
continue;
|
133
|
+
}
|
134
|
+
if ( eot[s]>=0 ) { // EOT Transition?
|
135
|
+
if ( debug ) { //System.err.println("EOT transition");
|
136
|
+
android.util.Log.e(TAG, "EOT transition");
|
137
|
+
}
|
138
|
+
s = eot[s];
|
139
|
+
input.consume();
|
140
|
+
continue;
|
141
|
+
}
|
142
|
+
if ( c==(char)Token.EOF && eof[s]>=0 ) { // EOF Transition to accept state?
|
143
|
+
if ( debug ) { //System.err.println("accept via EOF; predict "+accept[eof[s]]+" from "+eof[s]);
|
144
|
+
android.util.Log.e(TAG, "accept via EOF; predict "+accept[eof[s]]+" from "+eof[s]);
|
145
|
+
}
|
146
|
+
return accept[eof[s]];
|
147
|
+
}
|
148
|
+
// not in range and not EOF/EOT, must be invalid symbol
|
149
|
+
if ( debug ) {
|
150
|
+
//System.err.println("min["+s+"]="+min[s]);
|
151
|
+
android.util.Log.e(TAG, "min["+s+"]="+min[s]);
|
152
|
+
//System.err.println("max["+s+"]="+max[s]);
|
153
|
+
android.util.Log.e(TAG, "max["+s+"]="+max[s]);
|
154
|
+
//System.err.println("eot["+s+"]="+eot[s]);
|
155
|
+
android.util.Log.e(TAG, "eot["+s+"]="+eot[s]);
|
156
|
+
//System.err.println("eof["+s+"]="+eof[s]);
|
157
|
+
android.util.Log.e(TAG, "eof["+s+"]="+eof[s]);
|
158
|
+
for (int p=0; p<transition[s].length; p++) {
|
159
|
+
//System.err.print(transition[s][p]+" ");
|
160
|
+
android.util.Log.e(TAG, transition[s][p]+" ");
|
161
|
+
}
|
162
|
+
//System.err.println();
|
163
|
+
android.util.Log.e(TAG, "");
|
164
|
+
}
|
165
|
+
noViableAlt(s,input);
|
166
|
+
return 0;
|
167
|
+
}
|
168
|
+
}
|
169
|
+
finally {
|
170
|
+
input.rewind(mark);
|
171
|
+
}
|
172
|
+
}
|
173
|
+
|
174
|
+
protected void noViableAlt(int s, IntStream input) throws NoViableAltException {
|
175
|
+
if (recognizer.state.backtracking>0) {
|
176
|
+
recognizer.state.failed=true;
|
177
|
+
return;
|
178
|
+
}
|
179
|
+
NoViableAltException nvae =
|
180
|
+
new NoViableAltException(getDescription(),
|
181
|
+
decisionNumber,
|
182
|
+
s,
|
183
|
+
input);
|
184
|
+
error(nvae);
|
185
|
+
throw nvae;
|
186
|
+
}
|
187
|
+
|
188
|
+
/** A hook for debugging interface */
|
189
|
+
protected void error(NoViableAltException nvae) { ; }
|
190
|
+
|
191
|
+
public int specialStateTransition(int s, IntStream input)
|
192
|
+
throws NoViableAltException
|
193
|
+
{
|
194
|
+
return -1;
|
195
|
+
}
|
196
|
+
|
197
|
+
public String getDescription() {
|
198
|
+
return "n/a";
|
199
|
+
}
|
200
|
+
|
201
|
+
/** Given a String that has a run-length-encoding of some unsigned shorts
|
202
|
+
* like "\1\2\3\9", convert to short[] {2,9,9,9}. We do this to avoid
|
203
|
+
* static short[] which generates so much init code that the class won't
|
204
|
+
* compile. :(
|
205
|
+
*/
|
206
|
+
public static short[] unpackEncodedString(String encodedString) {
|
207
|
+
// walk first to find how big it is.
|
208
|
+
int size = 0;
|
209
|
+
for (int i=0; i<encodedString.length(); i+=2) {
|
210
|
+
size += encodedString.charAt(i);
|
211
|
+
}
|
212
|
+
short[] data = new short[size];
|
213
|
+
int di = 0;
|
214
|
+
for (int i=0; i<encodedString.length(); i+=2) {
|
215
|
+
char n = encodedString.charAt(i);
|
216
|
+
char v = encodedString.charAt(i+1);
|
217
|
+
// add v n times to data
|
218
|
+
for (int j=1; j<=n; j++) {
|
219
|
+
data[di++] = (short)v;
|
220
|
+
}
|
221
|
+
}
|
222
|
+
return data;
|
223
|
+
}
|
224
|
+
|
225
|
+
/** Hideous duplication of code, but I need different typed arrays out :( */
|
226
|
+
public static char[] unpackEncodedStringToUnsignedChars(String encodedString) {
|
227
|
+
// walk first to find how big it is.
|
228
|
+
int size = 0;
|
229
|
+
for (int i=0; i<encodedString.length(); i+=2) {
|
230
|
+
size += encodedString.charAt(i);
|
231
|
+
}
|
232
|
+
char[] data = new char[size];
|
233
|
+
int di = 0;
|
234
|
+
for (int i=0; i<encodedString.length(); i+=2) {
|
235
|
+
char n = encodedString.charAt(i);
|
236
|
+
char v = encodedString.charAt(i+1);
|
237
|
+
// add v n times to data
|
238
|
+
for (int j=1; j<=n; j++) {
|
239
|
+
data[di++] = v;
|
240
|
+
}
|
241
|
+
}
|
242
|
+
return data;
|
243
|
+
}
|
244
|
+
|
245
|
+
/*
|
246
|
+
public int specialTransition(int state, int symbol) {
|
247
|
+
return 0;
|
248
|
+
}
|
249
|
+
*/
|
250
|
+
}
|
@@ -0,0 +1,41 @@
|
|
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
|
+
/** The recognizer did not match anything for a (..)+ loop. */
|
31
|
+
public class EarlyExitException extends RecognitionException {
|
32
|
+
public int decisionNumber;
|
33
|
+
|
34
|
+
/** Used for remote debugger deserialization */
|
35
|
+
public EarlyExitException() {;}
|
36
|
+
|
37
|
+
public EarlyExitException(int decisionNumber, IntStream input) {
|
38
|
+
super(input);
|
39
|
+
this.decisionNumber = decisionNumber;
|
40
|
+
}
|
41
|
+
}
|
@@ -0,0 +1,54 @@
|
|
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
|
+
/** A semantic predicate failed during validation. Validation of predicates
|
31
|
+
* occurs when normally parsing the alternative just like matching a token.
|
32
|
+
* Disambiguating predicate evaluation occurs when we hoist a predicate into
|
33
|
+
* a prediction decision.
|
34
|
+
*/
|
35
|
+
public class FailedPredicateException extends RecognitionException {
|
36
|
+
public String ruleName;
|
37
|
+
public String predicateText;
|
38
|
+
|
39
|
+
/** Used for remote debugger deserialization */
|
40
|
+
public FailedPredicateException() {;}
|
41
|
+
|
42
|
+
public FailedPredicateException(IntStream input,
|
43
|
+
String ruleName,
|
44
|
+
String predicateText)
|
45
|
+
{
|
46
|
+
super(input);
|
47
|
+
this.ruleName = ruleName;
|
48
|
+
this.predicateText = predicateText;
|
49
|
+
}
|
50
|
+
|
51
|
+
public String toString() {
|
52
|
+
return "FailedPredicateException("+ruleName+",{"+predicateText+"}?)";
|
53
|
+
}
|
54
|
+
}
|
@@ -0,0 +1,122 @@
|
|
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
|
+
/** A simple stream of integers used when all I care about is the char
|
31
|
+
* or token type sequence (such as interpretation).
|
32
|
+
*/
|
33
|
+
public interface IntStream {
|
34
|
+
void consume();
|
35
|
+
|
36
|
+
/** Get int at current input pointer + i ahead where i=1 is next int.
|
37
|
+
* Negative indexes are allowed. LA(-1) is previous token (token
|
38
|
+
* just matched). LA(-i) where i is before first token should
|
39
|
+
* yield -1, invalid char / EOF.
|
40
|
+
*/
|
41
|
+
int LA(int i);
|
42
|
+
|
43
|
+
/** Tell the stream to start buffering if it hasn't already. Return
|
44
|
+
* current input position, index(), or some other marker so that
|
45
|
+
* when passed to rewind() you get back to the same spot.
|
46
|
+
* rewind(mark()) should not affect the input cursor. The Lexer
|
47
|
+
* track line/col info as well as input index so its markers are
|
48
|
+
* not pure input indexes. Same for tree node streams.
|
49
|
+
*/
|
50
|
+
int mark();
|
51
|
+
|
52
|
+
/** Return the current input symbol index 0..n where n indicates the
|
53
|
+
* last symbol has been read. The index is the symbol about to be
|
54
|
+
* read not the most recently read symbol.
|
55
|
+
*/
|
56
|
+
int index();
|
57
|
+
|
58
|
+
/** Reset the stream so that next call to index would return marker.
|
59
|
+
* The marker will usually be index() but it doesn't have to be. It's
|
60
|
+
* just a marker to indicate what state the stream was in. This is
|
61
|
+
* essentially calling release() and seek(). If there are markers
|
62
|
+
* created after this marker argument, this routine must unroll them
|
63
|
+
* like a stack. Assume the state the stream was in when this marker
|
64
|
+
* was created.
|
65
|
+
*/
|
66
|
+
void rewind(int marker);
|
67
|
+
|
68
|
+
/** Rewind to the input position of the last marker.
|
69
|
+
* Used currently only after a cyclic DFA and just
|
70
|
+
* before starting a sem/syn predicate to get the
|
71
|
+
* input position back to the start of the decision.
|
72
|
+
* Do not "pop" the marker off the state. mark(i)
|
73
|
+
* and rewind(i) should balance still. It is
|
74
|
+
* like invoking rewind(last marker) but it should not "pop"
|
75
|
+
* the marker off. It's like seek(last marker's input position).
|
76
|
+
*/
|
77
|
+
void rewind();
|
78
|
+
|
79
|
+
/** You may want to commit to a backtrack but don't want to force the
|
80
|
+
* stream to keep bookkeeping objects around for a marker that is
|
81
|
+
* no longer necessary. This will have the same behavior as
|
82
|
+
* rewind() except it releases resources without the backward seek.
|
83
|
+
* This must throw away resources for all markers back to the marker
|
84
|
+
* argument. So if you're nested 5 levels of mark(), and then release(2)
|
85
|
+
* you have to release resources for depths 2..5.
|
86
|
+
*/
|
87
|
+
void release(int marker);
|
88
|
+
|
89
|
+
/** Set the input cursor to the position indicated by index. This is
|
90
|
+
* normally used to seek ahead in the input stream. No buffering is
|
91
|
+
* required to do this unless you know your stream will use seek to
|
92
|
+
* move backwards such as when backtracking.
|
93
|
+
*
|
94
|
+
* This is different from rewind in its multi-directional
|
95
|
+
* requirement and in that its argument is strictly an input cursor (index).
|
96
|
+
*
|
97
|
+
* For char streams, seeking forward must update the stream state such
|
98
|
+
* as line number. For seeking backwards, you will be presumably
|
99
|
+
* backtracking using the mark/rewind mechanism that restores state and
|
100
|
+
* so this method does not need to update state when seeking backwards.
|
101
|
+
*
|
102
|
+
* Currently, this method is only used for efficient backtracking using
|
103
|
+
* memoization, but in the future it may be used for incremental parsing.
|
104
|
+
*
|
105
|
+
* The index is 0..n-1. A seek to position i means that LA(1) will
|
106
|
+
* return the ith symbol. So, seeking to 0 means LA(1) will return the
|
107
|
+
* first element in the stream.
|
108
|
+
*/
|
109
|
+
void seek(int index);
|
110
|
+
|
111
|
+
/** Only makes sense for streams that buffer everything up probably, but
|
112
|
+
* might be useful to display the entire stream or for testing. This
|
113
|
+
* value includes a single EOF.
|
114
|
+
*/
|
115
|
+
int size();
|
116
|
+
|
117
|
+
/** Where are you getting symbols from? Normally, implementations will
|
118
|
+
* pass the buck all the way to the lexer who can ask its input stream
|
119
|
+
* for the file name or whatever.
|
120
|
+
*/
|
121
|
+
public String getSourceName();
|
122
|
+
}
|