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
data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/TraceDebugEventListener.java
ADDED
@@ -0,0 +1,108 @@
|
|
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.debug;
|
29
|
+
|
30
|
+
import org.antlr.runtime.Token;
|
31
|
+
import org.antlr.runtime.tree.TreeAdaptor;
|
32
|
+
|
33
|
+
/** Print out (most of) the events... Useful for debugging, testing... */
|
34
|
+
public class TraceDebugEventListener extends BlankDebugEventListener {
|
35
|
+
TreeAdaptor adaptor;
|
36
|
+
|
37
|
+
private static final String TAG = "ANTLR:DEBUG:TraceDebugEventListener";
|
38
|
+
|
39
|
+
public TraceDebugEventListener(TreeAdaptor adaptor) {
|
40
|
+
this.adaptor = adaptor;
|
41
|
+
}
|
42
|
+
|
43
|
+
public void enterRule(String ruleName) { /*System.out.println("enterRule "+ruleName);*/ android.util.Log.i(TAG, "enterRule "+ruleName); }
|
44
|
+
public void exitRule(String ruleName) { /*System.out.println("exitRule "+ruleName);*/ android.util.Log.i(TAG, "exitRule "+ruleName); }
|
45
|
+
public void enterSubRule(int decisionNumber) { /*System.out.println("enterSubRule");*/ android.util.Log.i(TAG, "enterSubRule"); }
|
46
|
+
public void exitSubRule(int decisionNumber) { /*System.out.println("exitSubRule");*/ android.util.Log.i(TAG, "exitSubRule"); }
|
47
|
+
public void location(int line, int pos) { /*System.out.println("location "+line+":"+pos);*/ android.util.Log.i(TAG, "location "+line+":"+pos); }
|
48
|
+
|
49
|
+
// Tree parsing stuff
|
50
|
+
|
51
|
+
public void consumeNode(Object t) {
|
52
|
+
int ID = adaptor.getUniqueID(t);
|
53
|
+
String text = adaptor.getText(t);
|
54
|
+
int type = adaptor.getType(t);
|
55
|
+
//System.out.println("consumeNode "+ID+" "+text+" "+type);
|
56
|
+
android.util.Log.i(TAG, "consumeNode "+ID+" "+text+" "+type);
|
57
|
+
}
|
58
|
+
|
59
|
+
public void LT(int i, Object t) {
|
60
|
+
int ID = adaptor.getUniqueID(t);
|
61
|
+
String text = adaptor.getText(t);
|
62
|
+
int type = adaptor.getType(t);
|
63
|
+
//System.out.println("LT "+i+" "+ID+" "+text+" "+type);
|
64
|
+
android.util.Log.i(TAG, "LT "+i+" "+ID+" "+text+" "+type);
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
// AST stuff
|
69
|
+
public void nilNode(Object t) { /*System.out.println("nilNode "+adaptor.getUniqueID(t));*/ android.util.Log.i(TAG, "nilNode "+adaptor.getUniqueID(t)); }
|
70
|
+
|
71
|
+
public void createNode(Object t) {
|
72
|
+
int ID = adaptor.getUniqueID(t);
|
73
|
+
String text = adaptor.getText(t);
|
74
|
+
int type = adaptor.getType(t);
|
75
|
+
//System.out.println("create "+ID+": "+text+", "+type);
|
76
|
+
android.util.Log.i(TAG, "create "+ID+": "+text+", "+type);
|
77
|
+
}
|
78
|
+
|
79
|
+
public void createNode(Object node, Token token) {
|
80
|
+
int ID = adaptor.getUniqueID(node);
|
81
|
+
String text = adaptor.getText(node);
|
82
|
+
int tokenIndex = token.getTokenIndex();
|
83
|
+
//System.out.println("create "+ID+": "+tokenIndex);
|
84
|
+
android.util.Log.i(TAG, "create "+ID+": "+tokenIndex);
|
85
|
+
}
|
86
|
+
|
87
|
+
public void becomeRoot(Object newRoot, Object oldRoot) {
|
88
|
+
//System.out.println("becomeRoot "+adaptor.getUniqueID(newRoot)+", "+
|
89
|
+
//adaptor.getUniqueID(oldRoot));
|
90
|
+
android.util.Log.i(TAG, "becomeRoot "+adaptor.getUniqueID(newRoot)+", "+
|
91
|
+
adaptor.getUniqueID(oldRoot));
|
92
|
+
}
|
93
|
+
|
94
|
+
public void addChild(Object root, Object child) {
|
95
|
+
//System.out.println("addChild "+adaptor.getUniqueID(root)+", "+
|
96
|
+
//adaptor.getUniqueID(child));
|
97
|
+
android.util.Log.i(TAG, "addChild "+adaptor.getUniqueID(root)+", "+
|
98
|
+
adaptor.getUniqueID(child));
|
99
|
+
}
|
100
|
+
|
101
|
+
public void setTokenBoundaries(Object t, int tokenStartIndex, int tokenStopIndex) {
|
102
|
+
//System.out.println("setTokenBoundaries "+adaptor.getUniqueID(t)+", "+
|
103
|
+
//tokenStartIndex+", "+tokenStopIndex);
|
104
|
+
android.util.Log.i(TAG, "setTokenBoundaries "+adaptor.getUniqueID(t)+", "+
|
105
|
+
tokenStartIndex+", "+tokenStopIndex);
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
@@ -0,0 +1,69 @@
|
|
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.debug;
|
29
|
+
|
30
|
+
import org.antlr.runtime.IntStream;
|
31
|
+
import org.antlr.runtime.TokenStream;
|
32
|
+
|
33
|
+
/** The default tracer mimics the traceParser behavior of ANTLR 2.x.
|
34
|
+
* This listens for debugging events from the parser and implies
|
35
|
+
* that you cannot debug and trace at the same time.
|
36
|
+
*/
|
37
|
+
public class Tracer extends BlankDebugEventListener {
|
38
|
+
public IntStream input;
|
39
|
+
protected int level = 0;
|
40
|
+
|
41
|
+
private static final String TAG = "ANTLR:DEBUG:Tracer";
|
42
|
+
|
43
|
+
public Tracer(IntStream input) {
|
44
|
+
this.input = input;
|
45
|
+
}
|
46
|
+
|
47
|
+
public void enterRule(String ruleName) {
|
48
|
+
for (int i=1; i<=level; i++) {System.out.print(" ");}
|
49
|
+
//System.out.println("> "+ruleName+" lookahead(1)="+getInputSymbol(1));
|
50
|
+
android.util.Log.i(TAG, "> "+ruleName+" lookahead(1)="+getInputSymbol(1));
|
51
|
+
level++;
|
52
|
+
}
|
53
|
+
|
54
|
+
public void exitRule(String ruleName) {
|
55
|
+
level--;
|
56
|
+
for (int i=1; i<=level; i++) {System.out.print(" ");}
|
57
|
+
//System.out.println("< "+ruleName+" lookahead(1)="+getInputSymbol(1));
|
58
|
+
android.util.Log.i(TAG, "< "+ruleName+" lookahead(1)="+getInputSymbol(1));
|
59
|
+
}
|
60
|
+
|
61
|
+
public Object getInputSymbol(int k) {
|
62
|
+
if ( input instanceof TokenStream ) {
|
63
|
+
return ((TokenStream)input).LT(k);
|
64
|
+
}
|
65
|
+
return new Character((char)input.LA(k));
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
package org.antlr.runtime.misc;
|
2
|
+
|
3
|
+
import java.util.*;
|
4
|
+
|
5
|
+
/** Sometimes we need to map a key to a value but key is two pieces of data.
|
6
|
+
* This nested hash table saves creating a single key each time we access
|
7
|
+
* map; avoids mem creation.
|
8
|
+
*/
|
9
|
+
public class DoubleKeyMap<Key1, Key2, Value> {
|
10
|
+
Map<Key1, Map<Key2, Value>> data = new LinkedHashMap<Key1, Map<Key2, Value>>();
|
11
|
+
|
12
|
+
public Value put(Key1 k1, Key2 k2, Value v) {
|
13
|
+
Map<Key2, Value> data2 = data.get(k1);
|
14
|
+
Value prev = null;
|
15
|
+
if ( data2==null ) {
|
16
|
+
data2 = new LinkedHashMap<Key2, Value>();
|
17
|
+
data.put(k1, data2);
|
18
|
+
}
|
19
|
+
else {
|
20
|
+
prev = data2.get(k2);
|
21
|
+
}
|
22
|
+
data2.put(k2, v);
|
23
|
+
return prev;
|
24
|
+
}
|
25
|
+
|
26
|
+
public Value get(Key1 k1, Key2 k2) {
|
27
|
+
Map<Key2, Value> data2 = data.get(k1);
|
28
|
+
if ( data2==null ) return null;
|
29
|
+
return data2.get(k2);
|
30
|
+
}
|
31
|
+
|
32
|
+
public Map<Key2, Value> get(Key1 k1) { return data.get(k1); }
|
33
|
+
|
34
|
+
/** Get all values associated with primary key */
|
35
|
+
public Collection<Value> values(Key1 k1) {
|
36
|
+
Map<Key2, Value> data2 = data.get(k1);
|
37
|
+
if ( data2==null ) return null;
|
38
|
+
return data2.values();
|
39
|
+
}
|
40
|
+
|
41
|
+
/** get all primary keys */
|
42
|
+
public Set<Key1> keySet() {
|
43
|
+
return data.keySet();
|
44
|
+
}
|
45
|
+
|
46
|
+
/** get all secondary keys associated with a primary key */
|
47
|
+
public Set<Key2> keySet(Key1 k1) {
|
48
|
+
Map<Key2, Value> data2 = data.get(k1);
|
49
|
+
if ( data2==null ) return null;
|
50
|
+
return data2.keySet();
|
51
|
+
}
|
52
|
+
|
53
|
+
public Collection<Value> values() {
|
54
|
+
Set<Value> s = new HashSet<Value>();
|
55
|
+
for (Map<Key2, Value> k2 : data.values()) {
|
56
|
+
for (Value v : k2.values()) {
|
57
|
+
s.add(v);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
return s;
|
61
|
+
}
|
62
|
+
}
|
@@ -0,0 +1,100 @@
|
|
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.misc;
|
29
|
+
|
30
|
+
import java.util.List;
|
31
|
+
import java.util.ArrayList;
|
32
|
+
import java.util.NoSuchElementException;
|
33
|
+
|
34
|
+
/** A queue that can dequeue and get(i) in O(1) and grow arbitrarily large.
|
35
|
+
* A linked list is fast at dequeue but slow at get(i). An array is
|
36
|
+
* the reverse. This is O(1) for both operations.
|
37
|
+
*
|
38
|
+
* List grows until you dequeue last element at end of buffer. Then
|
39
|
+
* it resets to start filling at 0 again. If adds/removes are balanced, the
|
40
|
+
* buffer will not grow too large.
|
41
|
+
*
|
42
|
+
* No iterator stuff as that's not how we'll use it.
|
43
|
+
*/
|
44
|
+
public class FastQueue<T> {
|
45
|
+
/** dynamically-sized buffer of elements */
|
46
|
+
protected List<T> data = new ArrayList<T>();
|
47
|
+
/** index of next element to fill */
|
48
|
+
protected int p = 0;
|
49
|
+
protected int range = -1; // how deep have we gone?
|
50
|
+
|
51
|
+
public void reset() { clear(); }
|
52
|
+
public void clear() { p = 0; data.clear(); }
|
53
|
+
|
54
|
+
/** Get and remove first element in queue */
|
55
|
+
public T remove() {
|
56
|
+
T o = elementAt(0);
|
57
|
+
p++;
|
58
|
+
// have we hit end of buffer?
|
59
|
+
if ( p == data.size() ) {
|
60
|
+
// if so, it's an opportunity to start filling at index 0 again
|
61
|
+
clear(); // size goes to 0, but retains memory
|
62
|
+
}
|
63
|
+
return o;
|
64
|
+
}
|
65
|
+
|
66
|
+
public void add(T o) { data.add(o); }
|
67
|
+
|
68
|
+
public int size() { return data.size() - p; }
|
69
|
+
|
70
|
+
public int range() { return range; }
|
71
|
+
|
72
|
+
public T head() { return elementAt(0); }
|
73
|
+
|
74
|
+
/** Return element i elements ahead of current element. i==0 gets
|
75
|
+
* current element. This is not an absolute index into the data list
|
76
|
+
* since p defines the start of the real list.
|
77
|
+
*/
|
78
|
+
public T elementAt(int i) {
|
79
|
+
int absIndex = p + i;
|
80
|
+
if ( absIndex >= data.size() ) {
|
81
|
+
throw new NoSuchElementException("queue index "+ absIndex +" > last index "+(data.size()-1));
|
82
|
+
}
|
83
|
+
if ( absIndex < 0 ) {
|
84
|
+
throw new NoSuchElementException("queue index "+ absIndex +" < 0");
|
85
|
+
}
|
86
|
+
if ( absIndex>range ) range = absIndex;
|
87
|
+
return data.get(absIndex);
|
88
|
+
}
|
89
|
+
|
90
|
+
/** Return string of current buffer contents; non-destructive */
|
91
|
+
public String toString() {
|
92
|
+
StringBuffer buf = new StringBuffer();
|
93
|
+
int n = size();
|
94
|
+
for (int i=0; i<n; i++) {
|
95
|
+
buf.append(elementAt(i));
|
96
|
+
if ( (i+1)<n ) buf.append(" ");
|
97
|
+
}
|
98
|
+
return buf.toString();
|
99
|
+
}
|
100
|
+
}
|
@@ -0,0 +1,87 @@
|
|
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.misc;
|
29
|
+
|
30
|
+
/** A dynamic array that uses int not Integer objects. In principle this
|
31
|
+
* is more efficient in time, but certainly in space.
|
32
|
+
*
|
33
|
+
* This is simple enough that you can access the data array directly,
|
34
|
+
* but make sure that you append elements only with add() so that you
|
35
|
+
* get dynamic sizing. Make sure to call ensureCapacity() when you are
|
36
|
+
* manually adding new elements.
|
37
|
+
*
|
38
|
+
* Doesn't impl List because it doesn't return objects and I mean this
|
39
|
+
* really as just an array not a List per se. Manipulate the elements
|
40
|
+
* at will. This has stack methods too.
|
41
|
+
*
|
42
|
+
* When runtime can be 1.5, I'll make this generic.
|
43
|
+
*/
|
44
|
+
public class IntArray {
|
45
|
+
public static final int INITIAL_SIZE = 10;
|
46
|
+
public int[] data;
|
47
|
+
protected int p = -1;
|
48
|
+
|
49
|
+
public void add(int v) {
|
50
|
+
ensureCapacity(p+1);
|
51
|
+
data[++p] = v;
|
52
|
+
}
|
53
|
+
|
54
|
+
public void push(int v) {
|
55
|
+
add(v);
|
56
|
+
}
|
57
|
+
|
58
|
+
public int pop() {
|
59
|
+
int v = data[p];
|
60
|
+
p--;
|
61
|
+
return v;
|
62
|
+
}
|
63
|
+
|
64
|
+
/** This only tracks elements added via push/add. */
|
65
|
+
public int size() {
|
66
|
+
return p;
|
67
|
+
}
|
68
|
+
|
69
|
+
public void clear() {
|
70
|
+
p = -1;
|
71
|
+
}
|
72
|
+
|
73
|
+
public void ensureCapacity(int index) {
|
74
|
+
if ( data==null ) {
|
75
|
+
data = new int[INITIAL_SIZE];
|
76
|
+
}
|
77
|
+
else if ( (index+1)>=data.length ) {
|
78
|
+
int newSize = data.length*2;
|
79
|
+
if ( index>newSize ) {
|
80
|
+
newSize = index+1;
|
81
|
+
}
|
82
|
+
int[] newData = new int[newSize];
|
83
|
+
System.arraycopy(data, 0, newData, 0, data.length);
|
84
|
+
data = newData;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
@@ -0,0 +1,161 @@
|
|
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.misc;
|
29
|
+
|
30
|
+
import org.antlr.runtime.Token;
|
31
|
+
|
32
|
+
import java.util.NoSuchElementException;
|
33
|
+
|
34
|
+
/** A lookahead queue that knows how to mark/release locations
|
35
|
+
* in the buffer for backtracking purposes. Any markers force the FastQueue
|
36
|
+
* superclass to keep all tokens until no more markers; then can reset
|
37
|
+
* to avoid growing a huge buffer.
|
38
|
+
*/
|
39
|
+
public abstract class LookaheadStream<T> extends FastQueue<T> {
|
40
|
+
public static final int UNINITIALIZED_EOF_ELEMENT_INDEX = Integer.MAX_VALUE;
|
41
|
+
|
42
|
+
/** Absolute token index. It's the index of the symbol about to be
|
43
|
+
* read via LT(1). Goes from 0 to numtokens.
|
44
|
+
*/
|
45
|
+
protected int currentElementIndex = 0;
|
46
|
+
|
47
|
+
protected T prevElement;
|
48
|
+
|
49
|
+
/** Track object returned by nextElement upon end of stream;
|
50
|
+
* Return it later when they ask for LT passed end of input.
|
51
|
+
*/
|
52
|
+
public T eof = null;
|
53
|
+
|
54
|
+
/** Track the last mark() call result value for use in rewind(). */
|
55
|
+
protected int lastMarker;
|
56
|
+
|
57
|
+
/** tracks how deep mark() calls are nested */
|
58
|
+
protected int markDepth = 0;
|
59
|
+
|
60
|
+
public void reset() {
|
61
|
+
super.reset();
|
62
|
+
currentElementIndex = 0;
|
63
|
+
p = 0;
|
64
|
+
prevElement=null;
|
65
|
+
}
|
66
|
+
|
67
|
+
/** Implement nextElement to supply a stream of elements to this
|
68
|
+
* lookahead buffer. Return eof upon end of the stream we're pulling from.
|
69
|
+
*/
|
70
|
+
public abstract T nextElement();
|
71
|
+
|
72
|
+
public abstract boolean isEOF(T o);
|
73
|
+
|
74
|
+
/** Get and remove first element in queue; override FastQueue.remove();
|
75
|
+
* it's the same, just checks for backtracking.
|
76
|
+
*/
|
77
|
+
public T remove() {
|
78
|
+
T o = elementAt(0);
|
79
|
+
p++;
|
80
|
+
// have we hit end of buffer and not backtracking?
|
81
|
+
if ( p == data.size() && markDepth==0 ) {
|
82
|
+
// if so, it's an opportunity to start filling at index 0 again
|
83
|
+
clear(); // size goes to 0, but retains memory
|
84
|
+
}
|
85
|
+
return o;
|
86
|
+
}
|
87
|
+
|
88
|
+
/** Make sure we have at least one element to remove, even if EOF */
|
89
|
+
public void consume() {
|
90
|
+
syncAhead(1);
|
91
|
+
prevElement = remove();
|
92
|
+
currentElementIndex++;
|
93
|
+
}
|
94
|
+
|
95
|
+
/** Make sure we have 'need' elements from current position p. Last valid
|
96
|
+
* p index is data.size()-1. p+need-1 is the data index 'need' elements
|
97
|
+
* ahead. If we need 1 element, (p+1-1)==p must be < data.size().
|
98
|
+
*/
|
99
|
+
protected void syncAhead(int need) {
|
100
|
+
int n = (p+need-1) - data.size() + 1; // how many more elements we need?
|
101
|
+
if ( n > 0 ) fill(n); // out of elements?
|
102
|
+
}
|
103
|
+
|
104
|
+
/** add n elements to buffer */
|
105
|
+
public void fill(int n) {
|
106
|
+
for (int i=1; i<=n; i++) {
|
107
|
+
T o = nextElement();
|
108
|
+
if ( isEOF(o) ) eof = o;
|
109
|
+
data.add(o);
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
/** Size of entire stream is unknown; we only know buffer size from FastQueue */
|
114
|
+
public int size() { throw new UnsupportedOperationException("streams are of unknown size"); }
|
115
|
+
|
116
|
+
public T LT(int k) {
|
117
|
+
if ( k==0 ) {
|
118
|
+
return null;
|
119
|
+
}
|
120
|
+
if ( k<0 ) return LB(-k);
|
121
|
+
//System.out.print("LT(p="+p+","+k+")=");
|
122
|
+
syncAhead(k);
|
123
|
+
if ( (p+k-1) > data.size() ) return eof;
|
124
|
+
return elementAt(k-1);
|
125
|
+
}
|
126
|
+
|
127
|
+
public int index() { return currentElementIndex; }
|
128
|
+
|
129
|
+
public int mark() {
|
130
|
+
markDepth++;
|
131
|
+
lastMarker = p; // track where we are in buffer not absolute token index
|
132
|
+
return lastMarker;
|
133
|
+
}
|
134
|
+
|
135
|
+
public void release(int marker) {
|
136
|
+
// no resources to release
|
137
|
+
}
|
138
|
+
|
139
|
+
public void rewind(int marker) {
|
140
|
+
markDepth--;
|
141
|
+
seek(marker); // assume marker is top
|
142
|
+
// release(marker); // waste of call; it does nothing in this class
|
143
|
+
}
|
144
|
+
|
145
|
+
public void rewind() {
|
146
|
+
seek(lastMarker); // rewind but do not release marker
|
147
|
+
}
|
148
|
+
|
149
|
+
/** Seek to a 0-indexed position within data buffer. Can't handle
|
150
|
+
* case where you seek beyond end of existing buffer. Normally used
|
151
|
+
* to seek backwards in the buffer. Does not force loading of nodes.
|
152
|
+
* Doesn't see to absolute position in input stream since this stream
|
153
|
+
* is unbuffered. Seeks only into our moving window of elements.
|
154
|
+
*/
|
155
|
+
public void seek(int index) { p = index; }
|
156
|
+
|
157
|
+
protected T LB(int k) {
|
158
|
+
if ( k==1 ) return prevElement;
|
159
|
+
throw new NoSuchElementException("can't look backwards more than one token in this stream");
|
160
|
+
}
|
161
|
+
}
|