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,135 @@
|
|
1
|
+
/*
|
2
|
+
[The "BSD license"]
|
3
|
+
Copyright (c) 2005-2009 Terence Parr
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions
|
8
|
+
are met:
|
9
|
+
1. Redistributions of source code must retain the above copyright
|
10
|
+
notice, this list of conditions and the following disclaimer.
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright
|
12
|
+
notice, this list of conditions and the following disclaimer in the
|
13
|
+
documentation and/or other materials provided with the distribution.
|
14
|
+
3. The name of the author may not be used to endorse or promote products
|
15
|
+
derived from this software without specific prior written permission.
|
16
|
+
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
18
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
19
|
+
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
20
|
+
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
21
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
22
|
+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
23
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
24
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
26
|
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
*/
|
28
|
+
package org.antlr.runtime.tree;
|
29
|
+
|
30
|
+
public class TreePatternLexer {
|
31
|
+
public static final int EOF = -1;
|
32
|
+
public static final int BEGIN = 1;
|
33
|
+
public static final int END = 2;
|
34
|
+
public static final int ID = 3;
|
35
|
+
public static final int ARG = 4;
|
36
|
+
public static final int PERCENT = 5;
|
37
|
+
public static final int COLON = 6;
|
38
|
+
public static final int DOT = 7;
|
39
|
+
|
40
|
+
/** The tree pattern to lex like "(A B C)" */
|
41
|
+
protected String pattern;
|
42
|
+
|
43
|
+
/** Index into input string */
|
44
|
+
protected int p = -1;
|
45
|
+
|
46
|
+
/** Current char */
|
47
|
+
protected int c;
|
48
|
+
|
49
|
+
/** How long is the pattern in char? */
|
50
|
+
protected int n;
|
51
|
+
|
52
|
+
/** Set when token type is ID or ARG (name mimics Java's StreamTokenizer) */
|
53
|
+
public StringBuffer sval = new StringBuffer();
|
54
|
+
|
55
|
+
public boolean error = false;
|
56
|
+
|
57
|
+
public TreePatternLexer(String pattern) {
|
58
|
+
this.pattern = pattern;
|
59
|
+
this.n = pattern.length();
|
60
|
+
consume();
|
61
|
+
}
|
62
|
+
|
63
|
+
public int nextToken() {
|
64
|
+
sval.setLength(0); // reset, but reuse buffer
|
65
|
+
while ( c != EOF ) {
|
66
|
+
if ( c==' ' || c=='\n' || c=='\r' || c=='\t' ) {
|
67
|
+
consume();
|
68
|
+
continue;
|
69
|
+
}
|
70
|
+
if ( (c>='a' && c<='z') || (c>='A' && c<='Z') || c=='_' ) {
|
71
|
+
sval.append((char)c);
|
72
|
+
consume();
|
73
|
+
while ( (c>='a' && c<='z') || (c>='A' && c<='Z') ||
|
74
|
+
(c>='0' && c<='9') || c=='_' )
|
75
|
+
{
|
76
|
+
sval.append((char)c);
|
77
|
+
consume();
|
78
|
+
}
|
79
|
+
return ID;
|
80
|
+
}
|
81
|
+
if ( c=='(' ) {
|
82
|
+
consume();
|
83
|
+
return BEGIN;
|
84
|
+
}
|
85
|
+
if ( c==')' ) {
|
86
|
+
consume();
|
87
|
+
return END;
|
88
|
+
}
|
89
|
+
if ( c=='%' ) {
|
90
|
+
consume();
|
91
|
+
return PERCENT;
|
92
|
+
}
|
93
|
+
if ( c==':' ) {
|
94
|
+
consume();
|
95
|
+
return COLON;
|
96
|
+
}
|
97
|
+
if ( c=='.' ) {
|
98
|
+
consume();
|
99
|
+
return DOT;
|
100
|
+
}
|
101
|
+
if ( c=='[' ) { // grab [x] as a string, returning x
|
102
|
+
consume();
|
103
|
+
while ( c!=']' ) {
|
104
|
+
if ( c=='\\' ) {
|
105
|
+
consume();
|
106
|
+
if ( c!=']' ) {
|
107
|
+
sval.append('\\');
|
108
|
+
}
|
109
|
+
sval.append((char)c);
|
110
|
+
}
|
111
|
+
else {
|
112
|
+
sval.append((char)c);
|
113
|
+
}
|
114
|
+
consume();
|
115
|
+
}
|
116
|
+
consume();
|
117
|
+
return ARG;
|
118
|
+
}
|
119
|
+
consume();
|
120
|
+
error = true;
|
121
|
+
return EOF;
|
122
|
+
}
|
123
|
+
return EOF;
|
124
|
+
}
|
125
|
+
|
126
|
+
protected void consume() {
|
127
|
+
p++;
|
128
|
+
if ( p>=n ) {
|
129
|
+
c = EOF;
|
130
|
+
}
|
131
|
+
else {
|
132
|
+
c = pattern.charAt(p);
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|
@@ -0,0 +1,154 @@
|
|
1
|
+
/*
|
2
|
+
[The "BSD license"]
|
3
|
+
Copyright (c) 2005-2009 Terence Parr
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions
|
8
|
+
are met:
|
9
|
+
1. Redistributions of source code must retain the above copyright
|
10
|
+
notice, this list of conditions and the following disclaimer.
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright
|
12
|
+
notice, this list of conditions and the following disclaimer in the
|
13
|
+
documentation and/or other materials provided with the distribution.
|
14
|
+
3. The name of the author may not be used to endorse or promote products
|
15
|
+
derived from this software without specific prior written permission.
|
16
|
+
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
18
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
19
|
+
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
20
|
+
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
21
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
22
|
+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
23
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
24
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
26
|
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
*/
|
28
|
+
package org.antlr.runtime.tree;
|
29
|
+
|
30
|
+
import org.antlr.runtime.Token;
|
31
|
+
import org.antlr.runtime.CommonToken;
|
32
|
+
|
33
|
+
public class TreePatternParser {
|
34
|
+
protected TreePatternLexer tokenizer;
|
35
|
+
protected int ttype;
|
36
|
+
protected TreeWizard wizard;
|
37
|
+
protected TreeAdaptor adaptor;
|
38
|
+
|
39
|
+
public TreePatternParser(TreePatternLexer tokenizer, TreeWizard wizard, TreeAdaptor adaptor) {
|
40
|
+
this.tokenizer = tokenizer;
|
41
|
+
this.wizard = wizard;
|
42
|
+
this.adaptor = adaptor;
|
43
|
+
ttype = tokenizer.nextToken(); // kickstart
|
44
|
+
}
|
45
|
+
|
46
|
+
public Object pattern() {
|
47
|
+
if ( ttype==TreePatternLexer.BEGIN ) {
|
48
|
+
return parseTree();
|
49
|
+
}
|
50
|
+
else if ( ttype==TreePatternLexer.ID ) {
|
51
|
+
Object node = parseNode();
|
52
|
+
if ( ttype==TreePatternLexer.EOF ) {
|
53
|
+
return node;
|
54
|
+
}
|
55
|
+
return null; // extra junk on end
|
56
|
+
}
|
57
|
+
return null;
|
58
|
+
}
|
59
|
+
|
60
|
+
public Object parseTree() {
|
61
|
+
if ( ttype != TreePatternLexer.BEGIN ) {
|
62
|
+
throw new RuntimeException("no BEGIN");
|
63
|
+
}
|
64
|
+
ttype = tokenizer.nextToken();
|
65
|
+
Object root = parseNode();
|
66
|
+
if ( root==null ) {
|
67
|
+
return null;
|
68
|
+
}
|
69
|
+
while ( ttype==TreePatternLexer.BEGIN ||
|
70
|
+
ttype==TreePatternLexer.ID ||
|
71
|
+
ttype==TreePatternLexer.PERCENT ||
|
72
|
+
ttype==TreePatternLexer.DOT )
|
73
|
+
{
|
74
|
+
if ( ttype==TreePatternLexer.BEGIN ) {
|
75
|
+
Object subtree = parseTree();
|
76
|
+
adaptor.addChild(root, subtree);
|
77
|
+
}
|
78
|
+
else {
|
79
|
+
Object child = parseNode();
|
80
|
+
if ( child==null ) {
|
81
|
+
return null;
|
82
|
+
}
|
83
|
+
adaptor.addChild(root, child);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
if ( ttype != TreePatternLexer.END ) {
|
87
|
+
throw new RuntimeException("no END");
|
88
|
+
}
|
89
|
+
ttype = tokenizer.nextToken();
|
90
|
+
return root;
|
91
|
+
}
|
92
|
+
|
93
|
+
public Object parseNode() {
|
94
|
+
// "%label:" prefix
|
95
|
+
String label = null;
|
96
|
+
if ( ttype == TreePatternLexer.PERCENT ) {
|
97
|
+
ttype = tokenizer.nextToken();
|
98
|
+
if ( ttype != TreePatternLexer.ID ) {
|
99
|
+
return null;
|
100
|
+
}
|
101
|
+
label = tokenizer.sval.toString();
|
102
|
+
ttype = tokenizer.nextToken();
|
103
|
+
if ( ttype != TreePatternLexer.COLON ) {
|
104
|
+
return null;
|
105
|
+
}
|
106
|
+
ttype = tokenizer.nextToken(); // move to ID following colon
|
107
|
+
}
|
108
|
+
|
109
|
+
// Wildcard?
|
110
|
+
if ( ttype == TreePatternLexer.DOT ) {
|
111
|
+
ttype = tokenizer.nextToken();
|
112
|
+
Token wildcardPayload = new CommonToken(0, ".");
|
113
|
+
TreeWizard.TreePattern node =
|
114
|
+
new TreeWizard.WildcardTreePattern(wildcardPayload);
|
115
|
+
if ( label!=null ) {
|
116
|
+
node.label = label;
|
117
|
+
}
|
118
|
+
return node;
|
119
|
+
}
|
120
|
+
|
121
|
+
// "ID" or "ID[arg]"
|
122
|
+
if ( ttype != TreePatternLexer.ID ) {
|
123
|
+
return null;
|
124
|
+
}
|
125
|
+
String tokenName = tokenizer.sval.toString();
|
126
|
+
ttype = tokenizer.nextToken();
|
127
|
+
if ( tokenName.equals("nil") ) {
|
128
|
+
return adaptor.nil();
|
129
|
+
}
|
130
|
+
String text = tokenName;
|
131
|
+
// check for arg
|
132
|
+
String arg = null;
|
133
|
+
if ( ttype == TreePatternLexer.ARG ) {
|
134
|
+
arg = tokenizer.sval.toString();
|
135
|
+
text = arg;
|
136
|
+
ttype = tokenizer.nextToken();
|
137
|
+
}
|
138
|
+
|
139
|
+
// create node
|
140
|
+
int treeNodeType = wizard.getTokenType(tokenName);
|
141
|
+
if ( treeNodeType==Token.INVALID_TOKEN_TYPE ) {
|
142
|
+
return null;
|
143
|
+
}
|
144
|
+
Object node;
|
145
|
+
node = adaptor.create(treeNodeType, text);
|
146
|
+
if ( label!=null && node.getClass()==TreeWizard.TreePattern.class ) {
|
147
|
+
((TreeWizard.TreePattern)node).label = label;
|
148
|
+
}
|
149
|
+
if ( arg!=null && node.getClass()==TreeWizard.TreePattern.class ) {
|
150
|
+
((TreeWizard.TreePattern)node).hasTextArg = true;
|
151
|
+
}
|
152
|
+
return node;
|
153
|
+
}
|
154
|
+
}
|
@@ -0,0 +1,124 @@
|
|
1
|
+
/*
|
2
|
+
[The "BSD license"]
|
3
|
+
Copyright (c) 2005-2009 Terence Parr
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions
|
8
|
+
are met:
|
9
|
+
1. Redistributions of source code must retain the above copyright
|
10
|
+
notice, this list of conditions and the following disclaimer.
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright
|
12
|
+
notice, this list of conditions and the following disclaimer in the
|
13
|
+
documentation and/or other materials provided with the distribution.
|
14
|
+
3. The name of the author may not be used to endorse or promote products
|
15
|
+
derived from this software without specific prior written permission.
|
16
|
+
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
18
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
19
|
+
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
20
|
+
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
21
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
22
|
+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
23
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
24
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
26
|
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
*/
|
28
|
+
package org.antlr.runtime.tree;
|
29
|
+
|
30
|
+
import org.antlr.runtime.RecognizerSharedState;
|
31
|
+
import org.antlr.runtime.RecognitionException;
|
32
|
+
import org.antlr.runtime.TokenStream;
|
33
|
+
|
34
|
+
public class TreeRewriter extends TreeParser {
|
35
|
+
|
36
|
+
private static final String TAG = "ANTLR:TREE:TreeRewriter";
|
37
|
+
|
38
|
+
public interface fptr {
|
39
|
+
public Object rule() throws RecognitionException;
|
40
|
+
}
|
41
|
+
|
42
|
+
protected boolean showTransformations = false;
|
43
|
+
|
44
|
+
protected TokenStream originalTokenStream;
|
45
|
+
protected TreeAdaptor originalAdaptor;
|
46
|
+
|
47
|
+
public TreeRewriter(TreeNodeStream input) {
|
48
|
+
this(input, new RecognizerSharedState());
|
49
|
+
}
|
50
|
+
public TreeRewriter(TreeNodeStream input, RecognizerSharedState state) {
|
51
|
+
super(input, state);
|
52
|
+
originalAdaptor = input.getTreeAdaptor();
|
53
|
+
originalTokenStream = input.getTokenStream();
|
54
|
+
}
|
55
|
+
|
56
|
+
public Object applyOnce(Object t, fptr whichRule) {
|
57
|
+
if ( t==null ) return null;
|
58
|
+
try {
|
59
|
+
// share TreeParser object but not parsing-related state
|
60
|
+
state = new RecognizerSharedState();
|
61
|
+
input = new CommonTreeNodeStream(originalAdaptor, t);
|
62
|
+
((CommonTreeNodeStream)input).setTokenStream(originalTokenStream);
|
63
|
+
setBacktrackingLevel(1);
|
64
|
+
TreeRuleReturnScope r = (TreeRuleReturnScope)whichRule.rule();
|
65
|
+
setBacktrackingLevel(0);
|
66
|
+
if ( failed() ) return t;
|
67
|
+
if ( showTransformations &&
|
68
|
+
r!=null && !t.equals(r.getTree()) && r.getTree()!=null )
|
69
|
+
{
|
70
|
+
reportTransformation(t, r.getTree());
|
71
|
+
}
|
72
|
+
if ( r!=null && r.getTree()!=null ) return r.getTree();
|
73
|
+
else return t;
|
74
|
+
}
|
75
|
+
catch (RecognitionException e) { ; }
|
76
|
+
return t;
|
77
|
+
}
|
78
|
+
|
79
|
+
public Object applyRepeatedly(Object t, fptr whichRule) {
|
80
|
+
boolean treeChanged = true;
|
81
|
+
while ( treeChanged ) {
|
82
|
+
Object u = applyOnce(t, whichRule);
|
83
|
+
treeChanged = !t.equals(u);
|
84
|
+
t = u;
|
85
|
+
}
|
86
|
+
return t;
|
87
|
+
}
|
88
|
+
|
89
|
+
public Object downup(Object t) { return downup(t, false); }
|
90
|
+
|
91
|
+
public Object downup(Object t, boolean showTransformations) {
|
92
|
+
this.showTransformations = showTransformations;
|
93
|
+
TreeVisitor v = new TreeVisitor(new CommonTreeAdaptor());
|
94
|
+
TreeVisitorAction actions = new TreeVisitorAction() {
|
95
|
+
public Object pre(Object t) { return applyOnce(t, topdown_fptr); }
|
96
|
+
public Object post(Object t) { return applyRepeatedly(t, bottomup_ftpr); }
|
97
|
+
};
|
98
|
+
t = v.visit(t, actions);
|
99
|
+
return t;
|
100
|
+
}
|
101
|
+
|
102
|
+
/** Override this if you need transformation tracing to go somewhere
|
103
|
+
* other than stdout or if you're not using Tree-derived trees.
|
104
|
+
*/
|
105
|
+
public void reportTransformation(Object oldTree, Object newTree) {
|
106
|
+
//System.out.println(((Tree)oldTree).toStringTree()+" -> "+
|
107
|
+
//((Tree)newTree).toStringTree());
|
108
|
+
android.util.Log.i(TAG, ((Tree)oldTree).toStringTree()+" -> "+((Tree)newTree).toStringTree());
|
109
|
+
}
|
110
|
+
|
111
|
+
fptr topdown_fptr = new fptr() {
|
112
|
+
public Object rule() throws RecognitionException { return topdown(); }
|
113
|
+
};
|
114
|
+
|
115
|
+
fptr bottomup_ftpr = new fptr() {
|
116
|
+
public Object rule() throws RecognitionException { return bottomup(); }
|
117
|
+
};
|
118
|
+
|
119
|
+
// methods the downup strategy uses to do the up and down rules.
|
120
|
+
// to override, just define tree grammar rule topdown and turn on
|
121
|
+
// filter=true.
|
122
|
+
public Object topdown() throws RecognitionException { return null; }
|
123
|
+
public Object bottomup() throws RecognitionException { return null; }
|
124
|
+
}
|
@@ -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.tree;
|
29
|
+
|
30
|
+
import org.antlr.runtime.RuleReturnScope;
|
31
|
+
|
32
|
+
/** This is identical to the ParserRuleReturnScope except that
|
33
|
+
* the start property is a tree nodes not Token object
|
34
|
+
* when you are parsing trees. To be generic the tree node types
|
35
|
+
* have to be Object.
|
36
|
+
*/
|
37
|
+
public class TreeRuleReturnScope extends RuleReturnScope {
|
38
|
+
/** First node or root node of tree matched for this rule. */
|
39
|
+
public Object start;
|
40
|
+
public Object getStart() { return start; }
|
41
|
+
}
|