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,57 @@
|
|
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 source of characters for an ANTLR lexer */
|
31
|
+
public interface CharStream extends IntStream {
|
32
|
+
public static final int EOF = -1;
|
33
|
+
|
34
|
+
/** For infinite streams, you don't need this; primarily I'm providing
|
35
|
+
* a useful interface for action code. Just make sure actions don't
|
36
|
+
* use this on streams that don't support it.
|
37
|
+
*/
|
38
|
+
public String substring(int start, int stop);
|
39
|
+
|
40
|
+
/** Get the ith character of lookahead. This is the same usually as
|
41
|
+
* LA(i). This will be used for labels in the generated
|
42
|
+
* lexer code. I'd prefer to return a char here type-wise, but it's
|
43
|
+
* probably better to be 32-bit clean and be consistent with LA.
|
44
|
+
*/
|
45
|
+
public int LT(int i);
|
46
|
+
|
47
|
+
/** ANTLR tracks the line information automatically */
|
48
|
+
int getLine();
|
49
|
+
|
50
|
+
/** Because this stream can rewind, we need to be able to reset the line */
|
51
|
+
void setLine(int line);
|
52
|
+
|
53
|
+
void setCharPositionInLine(int pos);
|
54
|
+
|
55
|
+
/** The index of the character relative to the beginning of the line 0..n-1 */
|
56
|
+
int getCharPositionInLine();
|
57
|
+
}
|
@@ -0,0 +1,45 @@
|
|
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
|
+
/** When walking ahead with cyclic DFA or for syntactic predicates,
|
31
|
+
* we need to record the state of the input stream (char index,
|
32
|
+
* line, etc...) so that we can rewind the state after scanning ahead.
|
33
|
+
*
|
34
|
+
* This is the complete state of a stream.
|
35
|
+
*/
|
36
|
+
public class CharStreamState {
|
37
|
+
/** Index into the char stream of next lookahead char */
|
38
|
+
int p;
|
39
|
+
|
40
|
+
/** What line number is the scanner at before processing buffer[p]? */
|
41
|
+
int line;
|
42
|
+
|
43
|
+
/** What char position 0..n-1 in line is scanner before processing buffer[p]? */
|
44
|
+
int charPositionInLine;
|
45
|
+
}
|
@@ -0,0 +1,141 @@
|
|
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 Token object like we'd use in ANTLR 2.x; has an actual string created
|
31
|
+
* and associated with this object. These objects are needed for imaginary
|
32
|
+
* tree nodes that have payload objects. We need to create a Token object
|
33
|
+
* that has a string; the tree node will point at this token. CommonToken
|
34
|
+
* has indexes into a char stream and hence cannot be used to introduce
|
35
|
+
* new strings.
|
36
|
+
*/
|
37
|
+
public class ClassicToken implements Token {
|
38
|
+
protected String text;
|
39
|
+
protected int type;
|
40
|
+
protected int line;
|
41
|
+
protected int charPositionInLine;
|
42
|
+
protected int channel=DEFAULT_CHANNEL;
|
43
|
+
|
44
|
+
/** What token number is this from 0..n-1 tokens */
|
45
|
+
protected int index;
|
46
|
+
|
47
|
+
public ClassicToken(int type) {
|
48
|
+
this.type = type;
|
49
|
+
}
|
50
|
+
|
51
|
+
public ClassicToken(Token oldToken) {
|
52
|
+
text = oldToken.getText();
|
53
|
+
type = oldToken.getType();
|
54
|
+
line = oldToken.getLine();
|
55
|
+
charPositionInLine = oldToken.getCharPositionInLine();
|
56
|
+
channel = oldToken.getChannel();
|
57
|
+
}
|
58
|
+
|
59
|
+
public ClassicToken(int type, String text) {
|
60
|
+
this.type = type;
|
61
|
+
this.text = text;
|
62
|
+
}
|
63
|
+
|
64
|
+
public ClassicToken(int type, String text, int channel) {
|
65
|
+
this.type = type;
|
66
|
+
this.text = text;
|
67
|
+
this.channel = channel;
|
68
|
+
}
|
69
|
+
|
70
|
+
public int getType() {
|
71
|
+
return type;
|
72
|
+
}
|
73
|
+
|
74
|
+
public void setLine(int line) {
|
75
|
+
this.line = line;
|
76
|
+
}
|
77
|
+
|
78
|
+
public String getText() {
|
79
|
+
return text;
|
80
|
+
}
|
81
|
+
|
82
|
+
public void setText(String text) {
|
83
|
+
this.text = text;
|
84
|
+
}
|
85
|
+
|
86
|
+
public int getLine() {
|
87
|
+
return line;
|
88
|
+
}
|
89
|
+
|
90
|
+
public int getCharPositionInLine() {
|
91
|
+
return charPositionInLine;
|
92
|
+
}
|
93
|
+
|
94
|
+
public void setCharPositionInLine(int charPositionInLine) {
|
95
|
+
this.charPositionInLine = charPositionInLine;
|
96
|
+
}
|
97
|
+
|
98
|
+
public int getChannel() {
|
99
|
+
return channel;
|
100
|
+
}
|
101
|
+
|
102
|
+
public void setChannel(int channel) {
|
103
|
+
this.channel = channel;
|
104
|
+
}
|
105
|
+
|
106
|
+
public void setType(int type) {
|
107
|
+
this.type = type;
|
108
|
+
}
|
109
|
+
|
110
|
+
public int getTokenIndex() {
|
111
|
+
return index;
|
112
|
+
}
|
113
|
+
|
114
|
+
public void setTokenIndex(int index) {
|
115
|
+
this.index = index;
|
116
|
+
}
|
117
|
+
|
118
|
+
public CharStream getInputStream() {
|
119
|
+
return null;
|
120
|
+
}
|
121
|
+
|
122
|
+
public void setInputStream(CharStream input) {
|
123
|
+
}
|
124
|
+
|
125
|
+
public String toString() {
|
126
|
+
String channelStr = "";
|
127
|
+
if ( channel>0 ) {
|
128
|
+
channelStr=",channel="+channel;
|
129
|
+
}
|
130
|
+
String txt = getText();
|
131
|
+
if ( txt!=null ) {
|
132
|
+
txt = txt.replaceAll("\n","\\\\n");
|
133
|
+
txt = txt.replaceAll("\r","\\\\r");
|
134
|
+
txt = txt.replaceAll("\t","\\\\t");
|
135
|
+
}
|
136
|
+
else {
|
137
|
+
txt = "<no text>";
|
138
|
+
}
|
139
|
+
return "[@"+getTokenIndex()+",'"+txt+"',<"+type+">"+channelStr+","+line+":"+getCharPositionInLine()+"]";
|
140
|
+
}
|
141
|
+
}
|
@@ -0,0 +1,191 @@
|
|
1
|
+
/*
|
2
|
+
[The "BSD license"]
|
3
|
+
Copyright (c) 2005-2009 Terence Parr
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions
|
8
|
+
are met:
|
9
|
+
1. Redistributions of source code must retain the above copyright
|
10
|
+
notice, this list of conditions and the following disclaimer.
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright
|
12
|
+
notice, this list of conditions and the following disclaimer in the
|
13
|
+
documentation and/or other materials provided with the distribution.
|
14
|
+
3. The name of the author may not be used to endorse or promote products
|
15
|
+
derived from this software without specific prior written permission.
|
16
|
+
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
18
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
19
|
+
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
20
|
+
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
21
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
22
|
+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
23
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
24
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
26
|
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
*/
|
28
|
+
package org.antlr.runtime;
|
29
|
+
|
30
|
+
import java.io.Serializable;
|
31
|
+
|
32
|
+
public class CommonToken implements Token, Serializable {
|
33
|
+
protected int type;
|
34
|
+
protected int line;
|
35
|
+
protected int charPositionInLine = -1; // set to invalid position
|
36
|
+
protected int channel=DEFAULT_CHANNEL;
|
37
|
+
protected transient CharStream input;
|
38
|
+
|
39
|
+
/** We need to be able to change the text once in a while. If
|
40
|
+
* this is non-null, then getText should return this. Note that
|
41
|
+
* start/stop are not affected by changing this.
|
42
|
+
*/
|
43
|
+
protected String text;
|
44
|
+
|
45
|
+
/** What token number is this from 0..n-1 tokens; < 0 implies invalid index */
|
46
|
+
protected int index = -1;
|
47
|
+
|
48
|
+
/** The char position into the input buffer where this token starts */
|
49
|
+
protected int start;
|
50
|
+
|
51
|
+
/** The char position into the input buffer where this token stops */
|
52
|
+
protected int stop;
|
53
|
+
|
54
|
+
public CommonToken(int type) {
|
55
|
+
this.type = type;
|
56
|
+
}
|
57
|
+
|
58
|
+
public CommonToken(CharStream input, int type, int channel, int start, int stop) {
|
59
|
+
this.input = input;
|
60
|
+
this.type = type;
|
61
|
+
this.channel = channel;
|
62
|
+
this.start = start;
|
63
|
+
this.stop = stop;
|
64
|
+
}
|
65
|
+
|
66
|
+
public CommonToken(int type, String text) {
|
67
|
+
this.type = type;
|
68
|
+
this.channel = DEFAULT_CHANNEL;
|
69
|
+
this.text = text;
|
70
|
+
}
|
71
|
+
|
72
|
+
public CommonToken(Token oldToken) {
|
73
|
+
text = oldToken.getText();
|
74
|
+
type = oldToken.getType();
|
75
|
+
line = oldToken.getLine();
|
76
|
+
index = oldToken.getTokenIndex();
|
77
|
+
charPositionInLine = oldToken.getCharPositionInLine();
|
78
|
+
channel = oldToken.getChannel();
|
79
|
+
input = oldToken.getInputStream();
|
80
|
+
if ( oldToken instanceof CommonToken ) {
|
81
|
+
start = ((CommonToken)oldToken).start;
|
82
|
+
stop = ((CommonToken)oldToken).stop;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
public int getType() {
|
87
|
+
return type;
|
88
|
+
}
|
89
|
+
|
90
|
+
public void setLine(int line) {
|
91
|
+
this.line = line;
|
92
|
+
}
|
93
|
+
|
94
|
+
public String getText() {
|
95
|
+
if ( text!=null ) {
|
96
|
+
return text;
|
97
|
+
}
|
98
|
+
if ( input==null ) {
|
99
|
+
return null;
|
100
|
+
}
|
101
|
+
if ( start<input.size() && stop<input.size() ) {
|
102
|
+
text = input.substring(start,stop);
|
103
|
+
}
|
104
|
+
else {
|
105
|
+
text = "<EOF>";
|
106
|
+
}
|
107
|
+
return text;
|
108
|
+
}
|
109
|
+
|
110
|
+
/** Override the text for this token. getText() will return this text
|
111
|
+
* rather than pulling from the buffer. Note that this does not mean
|
112
|
+
* that start/stop indexes are not valid. It means that that input
|
113
|
+
* was converted to a new string in the token object.
|
114
|
+
*/
|
115
|
+
public void setText(String text) {
|
116
|
+
this.text = text;
|
117
|
+
}
|
118
|
+
|
119
|
+
public int getLine() {
|
120
|
+
return line;
|
121
|
+
}
|
122
|
+
|
123
|
+
public int getCharPositionInLine() {
|
124
|
+
return charPositionInLine;
|
125
|
+
}
|
126
|
+
|
127
|
+
public void setCharPositionInLine(int charPositionInLine) {
|
128
|
+
this.charPositionInLine = charPositionInLine;
|
129
|
+
}
|
130
|
+
|
131
|
+
public int getChannel() {
|
132
|
+
return channel;
|
133
|
+
}
|
134
|
+
|
135
|
+
public void setChannel(int channel) {
|
136
|
+
this.channel = channel;
|
137
|
+
}
|
138
|
+
|
139
|
+
public void setType(int type) {
|
140
|
+
this.type = type;
|
141
|
+
}
|
142
|
+
|
143
|
+
public int getStartIndex() {
|
144
|
+
return start;
|
145
|
+
}
|
146
|
+
|
147
|
+
public void setStartIndex(int start) {
|
148
|
+
this.start = start;
|
149
|
+
}
|
150
|
+
|
151
|
+
public int getStopIndex() {
|
152
|
+
return stop;
|
153
|
+
}
|
154
|
+
|
155
|
+
public void setStopIndex(int stop) {
|
156
|
+
this.stop = stop;
|
157
|
+
}
|
158
|
+
|
159
|
+
public int getTokenIndex() {
|
160
|
+
return index;
|
161
|
+
}
|
162
|
+
|
163
|
+
public void setTokenIndex(int index) {
|
164
|
+
this.index = index;
|
165
|
+
}
|
166
|
+
|
167
|
+
public CharStream getInputStream() {
|
168
|
+
return input;
|
169
|
+
}
|
170
|
+
|
171
|
+
public void setInputStream(CharStream input) {
|
172
|
+
this.input = input;
|
173
|
+
}
|
174
|
+
|
175
|
+
public String toString() {
|
176
|
+
String channelStr = "";
|
177
|
+
if ( channel>0 ) {
|
178
|
+
channelStr=",channel="+channel;
|
179
|
+
}
|
180
|
+
String txt = getText();
|
181
|
+
if ( txt!=null ) {
|
182
|
+
txt = txt.replaceAll("\n","\\\\n");
|
183
|
+
txt = txt.replaceAll("\r","\\\\r");
|
184
|
+
txt = txt.replaceAll("\t","\\\\t");
|
185
|
+
}
|
186
|
+
else {
|
187
|
+
txt = "<no text>";
|
188
|
+
}
|
189
|
+
return "[@"+getTokenIndex()+","+start+":"+stop+"='"+txt+"',<"+type+">"+channelStr+","+line+":"+getCharPositionInLine()+"]";
|
190
|
+
}
|
191
|
+
}
|
@@ -0,0 +1,153 @@
|
|
1
|
+
/*
|
2
|
+
[The "BSD license"]
|
3
|
+
Copyright (c) 2005-2009 Terence Parr
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions
|
8
|
+
are met:
|
9
|
+
1. Redistributions of source code must retain the above copyright
|
10
|
+
notice, this list of conditions and the following disclaimer.
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright
|
12
|
+
notice, this list of conditions and the following disclaimer in the
|
13
|
+
documentation and/or other materials provided with the distribution.
|
14
|
+
3. The name of the author may not be used to endorse or promote products
|
15
|
+
derived from this software without specific prior written permission.
|
16
|
+
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
18
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
19
|
+
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
20
|
+
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
21
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
22
|
+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
23
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
24
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
26
|
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
*/
|
28
|
+
|
29
|
+
package org.antlr.runtime;
|
30
|
+
|
31
|
+
/** The most common stream of tokens where every token is buffered up
|
32
|
+
* and tokens are filtered for a certain channel (the parser will only
|
33
|
+
* see these tokens).
|
34
|
+
*
|
35
|
+
* Even though it buffers all of the tokens, this token stream pulls tokens
|
36
|
+
* from the tokens source on demand. In other words, until you ask for a
|
37
|
+
* token using consume(), LT(), etc. the stream does not pull from the lexer.
|
38
|
+
*
|
39
|
+
* The only difference between this stream and BufferedTokenStream superclass
|
40
|
+
* is that this stream knows how to ignore off channel tokens. There may be
|
41
|
+
* a performance advantage to using the superclass if you don't pass
|
42
|
+
* whitespace and comments etc. to the parser on a hidden channel (i.e.,
|
43
|
+
* you set $channel instead of calling skip() in lexer rules.)
|
44
|
+
*
|
45
|
+
* @see org.antlr.runtime.UnbufferedTokenStream
|
46
|
+
* @see org.antlr.runtime.BufferedTokenStream
|
47
|
+
*/
|
48
|
+
public class CommonTokenStream extends BufferedTokenStream {
|
49
|
+
/** Skip tokens on any channel but this one; this is how we skip whitespace... */
|
50
|
+
protected int channel = Token.DEFAULT_CHANNEL;
|
51
|
+
|
52
|
+
public CommonTokenStream() { ; }
|
53
|
+
|
54
|
+
public CommonTokenStream(TokenSource tokenSource) {
|
55
|
+
super(tokenSource);
|
56
|
+
}
|
57
|
+
|
58
|
+
public CommonTokenStream(TokenSource tokenSource, int channel) {
|
59
|
+
this(tokenSource);
|
60
|
+
this.channel = channel;
|
61
|
+
}
|
62
|
+
|
63
|
+
/** Always leave p on an on-channel token. */
|
64
|
+
public void consume() {
|
65
|
+
if ( p == -1 ) setup();
|
66
|
+
p++;
|
67
|
+
sync(p);
|
68
|
+
while ( tokens.get(p).getChannel()!=channel ) {
|
69
|
+
p++;
|
70
|
+
sync(p);
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
protected Token LB(int k) {
|
75
|
+
if ( k==0 || (p-k)<0 ) return null;
|
76
|
+
|
77
|
+
int i = p;
|
78
|
+
int n = 1;
|
79
|
+
// find k good tokens looking backwards
|
80
|
+
while ( n<=k ) {
|
81
|
+
// skip off-channel tokens
|
82
|
+
i = skipOffTokenChannelsReverse(i-1);
|
83
|
+
n++;
|
84
|
+
}
|
85
|
+
if ( i<0 ) return null;
|
86
|
+
return tokens.get(i);
|
87
|
+
}
|
88
|
+
|
89
|
+
public Token LT(int k) {
|
90
|
+
//System.out.println("enter LT("+k+")");
|
91
|
+
if ( p == -1 ) setup();
|
92
|
+
if ( k == 0 ) return null;
|
93
|
+
if ( k < 0 ) return LB(-k);
|
94
|
+
int i = p;
|
95
|
+
int n = 1; // we know tokens[p] is a good one
|
96
|
+
// find k good tokens
|
97
|
+
while ( n<k ) {
|
98
|
+
// skip off-channel tokens
|
99
|
+
i = skipOffTokenChannels(i+1);
|
100
|
+
n++;
|
101
|
+
}
|
102
|
+
if ( i>range ) range = i;
|
103
|
+
return tokens.get(i);
|
104
|
+
}
|
105
|
+
|
106
|
+
/** Given a starting index, return the index of the first on-channel
|
107
|
+
* token.
|
108
|
+
*/
|
109
|
+
protected int skipOffTokenChannels(int i) {
|
110
|
+
sync(i);
|
111
|
+
while ( tokens.get(i).getChannel()!=channel ) { // also stops at EOF (it's onchannel)
|
112
|
+
i++;
|
113
|
+
sync(i);
|
114
|
+
}
|
115
|
+
return i;
|
116
|
+
}
|
117
|
+
|
118
|
+
protected int skipOffTokenChannelsReverse(int i) {
|
119
|
+
while ( i>=0 && ((Token)tokens.get(i)).getChannel()!=channel ) {
|
120
|
+
i--;
|
121
|
+
}
|
122
|
+
return i;
|
123
|
+
}
|
124
|
+
|
125
|
+
protected void setup() {
|
126
|
+
p = 0;
|
127
|
+
sync(0);
|
128
|
+
int i = 0;
|
129
|
+
while ( tokens.get(i).getChannel()!=channel ) {
|
130
|
+
i++;
|
131
|
+
sync(i);
|
132
|
+
}
|
133
|
+
p = i;
|
134
|
+
}
|
135
|
+
|
136
|
+
/** Count EOF just once. */
|
137
|
+
public int getNumberOfOnChannelTokens() {
|
138
|
+
int n = 0;
|
139
|
+
fill();
|
140
|
+
for (int i = 0; i < tokens.size(); i++) {
|
141
|
+
Token t = tokens.get(i);
|
142
|
+
if ( t.getChannel()==channel ) n++;
|
143
|
+
if ( t.getType()==Token.EOF ) break;
|
144
|
+
}
|
145
|
+
return n;
|
146
|
+
}
|
147
|
+
|
148
|
+
/** Reset this token stream by setting its token source. */
|
149
|
+
public void setTokenSource(TokenSource tokenSource) {
|
150
|
+
super.setTokenSource(tokenSource);
|
151
|
+
channel = Token.DEFAULT_CHANNEL;
|
152
|
+
}
|
153
|
+
}
|