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,323 @@
|
|
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.RecognitionException;
|
31
|
+
import org.antlr.runtime.Token;
|
32
|
+
|
33
|
+
/** All debugging events that a recognizer can trigger.
|
34
|
+
*
|
35
|
+
* I did not create a separate AST debugging interface as it would create
|
36
|
+
* lots of extra classes and DebugParser has a dbg var defined, which makes
|
37
|
+
* it hard to change to ASTDebugEventListener. I looked hard at this issue
|
38
|
+
* and it is easier to understand as one monolithic event interface for all
|
39
|
+
* possible events. Hopefully, adding ST debugging stuff won't be bad. Leave
|
40
|
+
* for future. 4/26/2006.
|
41
|
+
*/
|
42
|
+
public interface DebugEventListener {
|
43
|
+
/** Moved to version 2 for v3.1: added grammar name to enter/exit Rule */
|
44
|
+
public static final String PROTOCOL_VERSION = "2";
|
45
|
+
|
46
|
+
/** serialized version of true */
|
47
|
+
public static final int TRUE = 1;
|
48
|
+
public static final int FALSE = 0;
|
49
|
+
|
50
|
+
/** The parser has just entered a rule. No decision has been made about
|
51
|
+
* which alt is predicted. This is fired AFTER init actions have been
|
52
|
+
* executed. Attributes are defined and available etc...
|
53
|
+
* The grammarFileName allows composite grammars to jump around among
|
54
|
+
* multiple grammar files.
|
55
|
+
*/
|
56
|
+
public void enterRule(String grammarFileName, String ruleName);
|
57
|
+
|
58
|
+
/** Because rules can have lots of alternatives, it is very useful to
|
59
|
+
* know which alt you are entering. This is 1..n for n alts.
|
60
|
+
*/
|
61
|
+
public void enterAlt(int alt);
|
62
|
+
|
63
|
+
/** This is the last thing executed before leaving a rule. It is
|
64
|
+
* executed even if an exception is thrown. This is triggered after
|
65
|
+
* error reporting and recovery have occurred (unless the exception is
|
66
|
+
* not caught in this rule). This implies an "exitAlt" event.
|
67
|
+
* The grammarFileName allows composite grammars to jump around among
|
68
|
+
* multiple grammar files.
|
69
|
+
*/
|
70
|
+
public void exitRule(String grammarFileName, String ruleName);
|
71
|
+
|
72
|
+
/** Track entry into any (...) subrule other EBNF construct */
|
73
|
+
public void enterSubRule(int decisionNumber);
|
74
|
+
|
75
|
+
public void exitSubRule(int decisionNumber);
|
76
|
+
|
77
|
+
/** Every decision, fixed k or arbitrary, has an enter/exit event
|
78
|
+
* so that a GUI can easily track what LT/consume events are
|
79
|
+
* associated with prediction. You will see a single enter/exit
|
80
|
+
* subrule but multiple enter/exit decision events, one for each
|
81
|
+
* loop iteration.
|
82
|
+
*/
|
83
|
+
public void enterDecision(int decisionNumber, boolean couldBacktrack);
|
84
|
+
|
85
|
+
public void exitDecision(int decisionNumber);
|
86
|
+
|
87
|
+
/** An input token was consumed; matched by any kind of element.
|
88
|
+
* Trigger after the token was matched by things like match(), matchAny().
|
89
|
+
*/
|
90
|
+
public void consumeToken(Token t);
|
91
|
+
|
92
|
+
/** An off-channel input token was consumed.
|
93
|
+
* Trigger after the token was matched by things like match(), matchAny().
|
94
|
+
* (unless of course the hidden token is first stuff in the input stream).
|
95
|
+
*/
|
96
|
+
public void consumeHiddenToken(Token t);
|
97
|
+
|
98
|
+
/** Somebody (anybody) looked ahead. Note that this actually gets
|
99
|
+
* triggered by both LA and LT calls. The debugger will want to know
|
100
|
+
* which Token object was examined. Like consumeToken, this indicates
|
101
|
+
* what token was seen at that depth. A remote debugger cannot look
|
102
|
+
* ahead into a file it doesn't have so LT events must pass the token
|
103
|
+
* even if the info is redundant.
|
104
|
+
*/
|
105
|
+
public void LT(int i, Token t);
|
106
|
+
|
107
|
+
/** The parser is going to look arbitrarily ahead; mark this location,
|
108
|
+
* the token stream's marker is sent in case you need it.
|
109
|
+
*/
|
110
|
+
public void mark(int marker);
|
111
|
+
|
112
|
+
/** After an arbitrairly long lookahead as with a cyclic DFA (or with
|
113
|
+
* any backtrack), this informs the debugger that stream should be
|
114
|
+
* rewound to the position associated with marker.
|
115
|
+
*/
|
116
|
+
public void rewind(int marker);
|
117
|
+
|
118
|
+
/** Rewind to the input position of the last marker.
|
119
|
+
* Used currently only after a cyclic DFA and just
|
120
|
+
* before starting a sem/syn predicate to get the
|
121
|
+
* input position back to the start of the decision.
|
122
|
+
* Do not "pop" the marker off the state. mark(i)
|
123
|
+
* and rewind(i) should balance still.
|
124
|
+
*/
|
125
|
+
public void rewind();
|
126
|
+
|
127
|
+
public void beginBacktrack(int level);
|
128
|
+
|
129
|
+
public void endBacktrack(int level, boolean successful);
|
130
|
+
|
131
|
+
/** To watch a parser move through the grammar, the parser needs to
|
132
|
+
* inform the debugger what line/charPos it is passing in the grammar.
|
133
|
+
* For now, this does not know how to switch from one grammar to the
|
134
|
+
* other and back for island grammars etc...
|
135
|
+
*
|
136
|
+
* This should also allow breakpoints because the debugger can stop
|
137
|
+
* the parser whenever it hits this line/pos.
|
138
|
+
*/
|
139
|
+
public void location(int line, int pos);
|
140
|
+
|
141
|
+
/** A recognition exception occurred such as NoViableAltException. I made
|
142
|
+
* this a generic event so that I can alter the exception hierachy later
|
143
|
+
* without having to alter all the debug objects.
|
144
|
+
*
|
145
|
+
* Upon error, the stack of enter rule/subrule must be properly unwound.
|
146
|
+
* If no viable alt occurs it is within an enter/exit decision, which
|
147
|
+
* also must be rewound. Even the rewind for each mark must be unwount.
|
148
|
+
* In the Java target this is pretty easy using try/finally, if a bit
|
149
|
+
* ugly in the generated code. The rewind is generated in DFA.predict()
|
150
|
+
* actually so no code needs to be generated for that. For languages
|
151
|
+
* w/o this "finally" feature (C++?), the target implementor will have
|
152
|
+
* to build an event stack or something.
|
153
|
+
*
|
154
|
+
* Across a socket for remote debugging, only the RecognitionException
|
155
|
+
* data fields are transmitted. The token object or whatever that
|
156
|
+
* caused the problem was the last object referenced by LT. The
|
157
|
+
* immediately preceding LT event should hold the unexpected Token or
|
158
|
+
* char.
|
159
|
+
*
|
160
|
+
* Here is a sample event trace for grammar:
|
161
|
+
*
|
162
|
+
* b : C ({;}A|B) // {;} is there to prevent A|B becoming a set
|
163
|
+
* | D
|
164
|
+
* ;
|
165
|
+
*
|
166
|
+
* The sequence for this rule (with no viable alt in the subrule) for
|
167
|
+
* input 'c c' (there are 3 tokens) is:
|
168
|
+
*
|
169
|
+
* commence
|
170
|
+
* LT(1)
|
171
|
+
* enterRule b
|
172
|
+
* location 7 1
|
173
|
+
* enter decision 3
|
174
|
+
* LT(1)
|
175
|
+
* exit decision 3
|
176
|
+
* enterAlt1
|
177
|
+
* location 7 5
|
178
|
+
* LT(1)
|
179
|
+
* consumeToken [c/<4>,1:0]
|
180
|
+
* location 7 7
|
181
|
+
* enterSubRule 2
|
182
|
+
* enter decision 2
|
183
|
+
* LT(1)
|
184
|
+
* LT(1)
|
185
|
+
* recognitionException NoViableAltException 2 1 2
|
186
|
+
* exit decision 2
|
187
|
+
* exitSubRule 2
|
188
|
+
* beginResync
|
189
|
+
* LT(1)
|
190
|
+
* consumeToken [c/<4>,1:1]
|
191
|
+
* LT(1)
|
192
|
+
* endResync
|
193
|
+
* LT(-1)
|
194
|
+
* exitRule b
|
195
|
+
* terminate
|
196
|
+
*/
|
197
|
+
public void recognitionException(RecognitionException e);
|
198
|
+
|
199
|
+
/** Indicates the recognizer is about to consume tokens to resynchronize
|
200
|
+
* the parser. Any consume events from here until the recovered event
|
201
|
+
* are not part of the parse--they are dead tokens.
|
202
|
+
*/
|
203
|
+
public void beginResync();
|
204
|
+
|
205
|
+
/** Indicates that the recognizer has finished consuming tokens in order
|
206
|
+
* to resychronize. There may be multiple beginResync/endResync pairs
|
207
|
+
* before the recognizer comes out of errorRecovery mode (in which
|
208
|
+
* multiple errors are suppressed). This will be useful
|
209
|
+
* in a gui where you want to probably grey out tokens that are consumed
|
210
|
+
* but not matched to anything in grammar. Anything between
|
211
|
+
* a beginResync/endResync pair was tossed out by the parser.
|
212
|
+
*/
|
213
|
+
public void endResync();
|
214
|
+
|
215
|
+
/** A semantic predicate was evaluate with this result and action text */
|
216
|
+
public void semanticPredicate(boolean result, String predicate);
|
217
|
+
|
218
|
+
/** Announce that parsing has begun. Not technically useful except for
|
219
|
+
* sending events over a socket. A GUI for example will launch a thread
|
220
|
+
* to connect and communicate with a remote parser. The thread will want
|
221
|
+
* to notify the GUI when a connection is made. ANTLR parsers
|
222
|
+
* trigger this upon entry to the first rule (the ruleLevel is used to
|
223
|
+
* figure this out).
|
224
|
+
*/
|
225
|
+
public void commence();
|
226
|
+
|
227
|
+
/** Parsing is over; successfully or not. Mostly useful for telling
|
228
|
+
* remote debugging listeners that it's time to quit. When the rule
|
229
|
+
* invocation level goes to zero at the end of a rule, we are done
|
230
|
+
* parsing.
|
231
|
+
*/
|
232
|
+
public void terminate();
|
233
|
+
|
234
|
+
|
235
|
+
// T r e e P a r s i n g
|
236
|
+
|
237
|
+
/** Input for a tree parser is an AST, but we know nothing for sure
|
238
|
+
* about a node except its type and text (obtained from the adaptor).
|
239
|
+
* This is the analog of the consumeToken method. Again, the ID is
|
240
|
+
* the hashCode usually of the node so it only works if hashCode is
|
241
|
+
* not implemented. If the type is UP or DOWN, then
|
242
|
+
* the ID is not really meaningful as it's fixed--there is
|
243
|
+
* just one UP node and one DOWN navigation node.
|
244
|
+
* @param t
|
245
|
+
*/
|
246
|
+
public void consumeNode(Object t);
|
247
|
+
|
248
|
+
/** The tree parser lookedahead. If the type is UP or DOWN,
|
249
|
+
* then the ID is not really meaningful as it's fixed--there is
|
250
|
+
* just one UP node and one DOWN navigation node.
|
251
|
+
*/
|
252
|
+
public void LT(int i, Object t);
|
253
|
+
|
254
|
+
|
255
|
+
// A S T E v e n t s
|
256
|
+
|
257
|
+
/** A nil was created (even nil nodes have a unique ID...
|
258
|
+
* they are not "null" per se). As of 4/28/2006, this
|
259
|
+
* seems to be uniquely triggered when starting a new subtree
|
260
|
+
* such as when entering a subrule in automatic mode and when
|
261
|
+
* building a tree in rewrite mode.
|
262
|
+
*
|
263
|
+
* If you are receiving this event over a socket via
|
264
|
+
* RemoteDebugEventSocketListener then only t.ID is set.
|
265
|
+
*/
|
266
|
+
public void nilNode(Object t);
|
267
|
+
|
268
|
+
/** Upon syntax error, recognizers bracket the error with an error node
|
269
|
+
* if they are building ASTs.
|
270
|
+
* @param t
|
271
|
+
*/
|
272
|
+
public void errorNode(Object t);
|
273
|
+
|
274
|
+
/** Announce a new node built from token elements such as type etc...
|
275
|
+
*
|
276
|
+
* If you are receiving this event over a socket via
|
277
|
+
* RemoteDebugEventSocketListener then only t.ID, type, text are
|
278
|
+
* set.
|
279
|
+
*/
|
280
|
+
public void createNode(Object t);
|
281
|
+
|
282
|
+
/** Announce a new node built from an existing token.
|
283
|
+
*
|
284
|
+
* If you are receiving this event over a socket via
|
285
|
+
* RemoteDebugEventSocketListener then only node.ID and token.tokenIndex
|
286
|
+
* are set.
|
287
|
+
*/
|
288
|
+
public void createNode(Object node, Token token);
|
289
|
+
|
290
|
+
/** Make a node the new root of an existing root. See
|
291
|
+
*
|
292
|
+
* Note: the newRootID parameter is possibly different
|
293
|
+
* than the TreeAdaptor.becomeRoot() newRoot parameter.
|
294
|
+
* In our case, it will always be the result of calling
|
295
|
+
* TreeAdaptor.becomeRoot() and not root_n or whatever.
|
296
|
+
*
|
297
|
+
* The listener should assume that this event occurs
|
298
|
+
* only when the current subrule (or rule) subtree is
|
299
|
+
* being reset to newRootID.
|
300
|
+
*
|
301
|
+
* If you are receiving this event over a socket via
|
302
|
+
* RemoteDebugEventSocketListener then only IDs are set.
|
303
|
+
*
|
304
|
+
* @see org.antlr.runtime.tree.TreeAdaptor.becomeRoot()
|
305
|
+
*/
|
306
|
+
public void becomeRoot(Object newRoot, Object oldRoot);
|
307
|
+
|
308
|
+
/** Make childID a child of rootID.
|
309
|
+
*
|
310
|
+
* If you are receiving this event over a socket via
|
311
|
+
* RemoteDebugEventSocketListener then only IDs are set.
|
312
|
+
*
|
313
|
+
* @see org.antlr.runtime.tree.TreeAdaptor.addChild()
|
314
|
+
*/
|
315
|
+
public void addChild(Object root, Object child);
|
316
|
+
|
317
|
+
/** Set the token start/stop token index for a subtree root or node.
|
318
|
+
*
|
319
|
+
* If you are receiving this event over a socket via
|
320
|
+
* RemoteDebugEventSocketListener then only t.ID is set.
|
321
|
+
*/
|
322
|
+
public void setTokenBoundaries(Object t, int tokenStartIndex, int tokenStopIndex);
|
323
|
+
}
|
@@ -0,0 +1,88 @@
|
|
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.RecognitionException;
|
32
|
+
|
33
|
+
/** A simple event repeater (proxy) that delegates all functionality to the
|
34
|
+
* listener sent into the ctor. Useful if you want to listen in on a few
|
35
|
+
* debug events w/o interrupting the debugger. Just subclass the repeater
|
36
|
+
* and override the methods you want to listen in on. Remember to call
|
37
|
+
* the method in this class so the event will continue on to the original
|
38
|
+
* recipient.
|
39
|
+
*
|
40
|
+
* @see DebugEventHub
|
41
|
+
*/
|
42
|
+
public class DebugEventRepeater implements DebugEventListener {
|
43
|
+
protected DebugEventListener listener;
|
44
|
+
|
45
|
+
public DebugEventRepeater(DebugEventListener listener) {
|
46
|
+
this.listener = listener;
|
47
|
+
}
|
48
|
+
|
49
|
+
public void enterRule(String grammarFileName, String ruleName) { listener.enterRule(grammarFileName, ruleName); }
|
50
|
+
public void exitRule(String grammarFileName, String ruleName) { listener.exitRule(grammarFileName, ruleName); }
|
51
|
+
public void enterAlt(int alt) { listener.enterAlt(alt); }
|
52
|
+
public void enterSubRule(int decisionNumber) { listener.enterSubRule(decisionNumber); }
|
53
|
+
public void exitSubRule(int decisionNumber) { listener.exitSubRule(decisionNumber); }
|
54
|
+
public void enterDecision(int decisionNumber, boolean couldBacktrack) { listener.enterDecision(decisionNumber, couldBacktrack); }
|
55
|
+
public void exitDecision(int decisionNumber) { listener.exitDecision(decisionNumber); }
|
56
|
+
public void location(int line, int pos) { listener.location(line, pos); }
|
57
|
+
public void consumeToken(Token token) { listener.consumeToken(token); }
|
58
|
+
public void consumeHiddenToken(Token token) { listener.consumeHiddenToken(token); }
|
59
|
+
public void LT(int i, Token t) { listener.LT(i, t); }
|
60
|
+
public void mark(int i) { listener.mark(i); }
|
61
|
+
public void rewind(int i) { listener.rewind(i); }
|
62
|
+
public void rewind() { listener.rewind(); }
|
63
|
+
public void beginBacktrack(int level) { listener.beginBacktrack(level); }
|
64
|
+
public void endBacktrack(int level, boolean successful) { listener.endBacktrack(level, successful); }
|
65
|
+
public void recognitionException(RecognitionException e) { listener.recognitionException(e); }
|
66
|
+
public void beginResync() { listener.beginResync(); }
|
67
|
+
public void endResync() { listener.endResync(); }
|
68
|
+
public void semanticPredicate(boolean result, String predicate) { listener.semanticPredicate(result, predicate); }
|
69
|
+
public void commence() { listener.commence(); }
|
70
|
+
public void terminate() { listener.terminate(); }
|
71
|
+
|
72
|
+
// Tree parsing stuff
|
73
|
+
|
74
|
+
public void consumeNode(Object t) { listener.consumeNode(t); }
|
75
|
+
public void LT(int i, Object t) { listener.LT(i, t); }
|
76
|
+
|
77
|
+
// AST Stuff
|
78
|
+
|
79
|
+
public void nilNode(Object t) { listener.nilNode(t); }
|
80
|
+
public void errorNode(Object t) { listener.errorNode(t); }
|
81
|
+
public void createNode(Object t) { listener.createNode(t); }
|
82
|
+
public void createNode(Object node, Token token) { listener.createNode(node, token); }
|
83
|
+
public void becomeRoot(Object newRoot, Object oldRoot) { listener.becomeRoot(newRoot, oldRoot); }
|
84
|
+
public void addChild(Object root, Object child) { listener.addChild(root, child); }
|
85
|
+
public void setTokenBoundaries(Object t, int tokenStartIndex, int tokenStopIndex) {
|
86
|
+
listener.setTokenBoundaries(t, tokenStartIndex, tokenStopIndex);
|
87
|
+
}
|
88
|
+
}
|
data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugEventSocketProxy.java
ADDED
@@ -0,0 +1,358 @@
|
|
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.RecognitionException;
|
31
|
+
import org.antlr.runtime.Token;
|
32
|
+
import org.antlr.runtime.BaseRecognizer;
|
33
|
+
import org.antlr.runtime.tree.TreeAdaptor;
|
34
|
+
|
35
|
+
import java.io.*;
|
36
|
+
import java.net.ServerSocket;
|
37
|
+
import java.net.Socket;
|
38
|
+
|
39
|
+
/** A proxy debug event listener that forwards events over a socket to
|
40
|
+
* a debugger (or any other listener) using a simple text-based protocol;
|
41
|
+
* one event per line. ANTLRWorks listens on server socket with a
|
42
|
+
* RemoteDebugEventSocketListener instance. These two objects must therefore
|
43
|
+
* be kept in sync. New events must be handled on both sides of socket.
|
44
|
+
*/
|
45
|
+
public class DebugEventSocketProxy extends BlankDebugEventListener {
|
46
|
+
public static final int DEFAULT_DEBUGGER_PORT = 49100; // was 49153
|
47
|
+
protected int port = DEFAULT_DEBUGGER_PORT;
|
48
|
+
protected ServerSocket serverSocket;
|
49
|
+
protected Socket socket;
|
50
|
+
protected String grammarFileName;
|
51
|
+
protected PrintWriter out;
|
52
|
+
protected BufferedReader in;
|
53
|
+
|
54
|
+
private static final String TAG = "ANTLR:DEBUG:DebugEventSocketProxy";
|
55
|
+
|
56
|
+
/** Who am i debugging? */
|
57
|
+
protected BaseRecognizer recognizer;
|
58
|
+
|
59
|
+
/** Almost certainly the recognizer will have adaptor set, but
|
60
|
+
* we don't know how to cast it (Parser or TreeParser) to get
|
61
|
+
* the adaptor field. Must be set with a constructor. :(
|
62
|
+
*/
|
63
|
+
protected TreeAdaptor adaptor;
|
64
|
+
|
65
|
+
public DebugEventSocketProxy(BaseRecognizer recognizer, TreeAdaptor adaptor) {
|
66
|
+
this(recognizer, DEFAULT_DEBUGGER_PORT, adaptor);
|
67
|
+
}
|
68
|
+
|
69
|
+
public DebugEventSocketProxy(BaseRecognizer recognizer, int port, TreeAdaptor adaptor) {
|
70
|
+
this.grammarFileName = recognizer.getGrammarFileName();
|
71
|
+
this.adaptor = adaptor;
|
72
|
+
this.port = port;
|
73
|
+
}
|
74
|
+
|
75
|
+
public void handshake() throws IOException {
|
76
|
+
if ( serverSocket==null ) {
|
77
|
+
serverSocket = new ServerSocket(port);
|
78
|
+
socket = serverSocket.accept();
|
79
|
+
socket.setTcpNoDelay(true);
|
80
|
+
OutputStream os = socket.getOutputStream();
|
81
|
+
OutputStreamWriter osw = new OutputStreamWriter(os, "UTF8");
|
82
|
+
out = new PrintWriter(new BufferedWriter(osw));
|
83
|
+
InputStream is = socket.getInputStream();
|
84
|
+
InputStreamReader isr = new InputStreamReader(is, "UTF8");
|
85
|
+
in = new BufferedReader(isr);
|
86
|
+
out.println("ANTLR "+ DebugEventListener.PROTOCOL_VERSION);
|
87
|
+
out.println("grammar \""+ grammarFileName);
|
88
|
+
out.flush();
|
89
|
+
ack();
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
public void commence() {
|
94
|
+
// don't bother sending event; listener will trigger upon connection
|
95
|
+
}
|
96
|
+
|
97
|
+
public void terminate() {
|
98
|
+
transmit("terminate");
|
99
|
+
out.close();
|
100
|
+
try {
|
101
|
+
socket.close();
|
102
|
+
}
|
103
|
+
catch (IOException ioe) {
|
104
|
+
//ioe.printStackTrace(System.err);
|
105
|
+
android.util.Log.e(TAG, android.util.Log.getStackTraceString(ioe));
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
protected void ack() {
|
110
|
+
try {
|
111
|
+
in.readLine();
|
112
|
+
}
|
113
|
+
catch (IOException ioe) {
|
114
|
+
ioe.printStackTrace(System.err);
|
115
|
+
android.util.Log.e(TAG, android.util.Log.getStackTraceString(ioe));
|
116
|
+
}
|
117
|
+
}
|
118
|
+
|
119
|
+
protected void transmit(String event) {
|
120
|
+
out.println(event);
|
121
|
+
out.flush();
|
122
|
+
ack();
|
123
|
+
}
|
124
|
+
|
125
|
+
public void enterRule(String grammarFileName, String ruleName) {
|
126
|
+
transmit("enterRule\t"+grammarFileName+"\t"+ruleName);
|
127
|
+
}
|
128
|
+
|
129
|
+
public void enterAlt(int alt) {
|
130
|
+
transmit("enterAlt\t"+alt);
|
131
|
+
}
|
132
|
+
|
133
|
+
public void exitRule(String grammarFileName, String ruleName) {
|
134
|
+
transmit("exitRule\t"+grammarFileName+"\t"+ruleName);
|
135
|
+
}
|
136
|
+
|
137
|
+
public void enterSubRule(int decisionNumber) {
|
138
|
+
transmit("enterSubRule\t"+decisionNumber);
|
139
|
+
}
|
140
|
+
|
141
|
+
public void exitSubRule(int decisionNumber) {
|
142
|
+
transmit("exitSubRule\t"+decisionNumber);
|
143
|
+
}
|
144
|
+
|
145
|
+
public void enterDecision(int decisionNumber, boolean couldBacktrack) {
|
146
|
+
transmit("enterDecision\t"+decisionNumber+"\t"+couldBacktrack);
|
147
|
+
}
|
148
|
+
|
149
|
+
public void exitDecision(int decisionNumber) {
|
150
|
+
transmit("exitDecision\t"+decisionNumber);
|
151
|
+
}
|
152
|
+
|
153
|
+
public void consumeToken(Token t) {
|
154
|
+
String buf = serializeToken(t);
|
155
|
+
transmit("consumeToken\t"+buf);
|
156
|
+
}
|
157
|
+
|
158
|
+
public void consumeHiddenToken(Token t) {
|
159
|
+
String buf = serializeToken(t);
|
160
|
+
transmit("consumeHiddenToken\t"+buf);
|
161
|
+
}
|
162
|
+
|
163
|
+
public void LT(int i, Token t) {
|
164
|
+
if(t != null)
|
165
|
+
transmit("LT\t"+i+"\t"+serializeToken(t));
|
166
|
+
}
|
167
|
+
|
168
|
+
public void mark(int i) {
|
169
|
+
transmit("mark\t"+i);
|
170
|
+
}
|
171
|
+
|
172
|
+
public void rewind(int i) {
|
173
|
+
transmit("rewind\t"+i);
|
174
|
+
}
|
175
|
+
|
176
|
+
public void rewind() {
|
177
|
+
transmit("rewind");
|
178
|
+
}
|
179
|
+
|
180
|
+
public void beginBacktrack(int level) {
|
181
|
+
transmit("beginBacktrack\t"+level);
|
182
|
+
}
|
183
|
+
|
184
|
+
public void endBacktrack(int level, boolean successful) {
|
185
|
+
transmit("endBacktrack\t"+level+"\t"+(successful?TRUE:FALSE));
|
186
|
+
}
|
187
|
+
|
188
|
+
public void location(int line, int pos) {
|
189
|
+
transmit("location\t"+line+"\t"+pos);
|
190
|
+
}
|
191
|
+
|
192
|
+
public void recognitionException(RecognitionException e) {
|
193
|
+
StringBuffer buf = new StringBuffer(50);
|
194
|
+
buf.append("exception\t");
|
195
|
+
buf.append(e.getClass().getName());
|
196
|
+
// dump only the data common to all exceptions for now
|
197
|
+
buf.append("\t");
|
198
|
+
buf.append(e.index);
|
199
|
+
buf.append("\t");
|
200
|
+
buf.append(e.line);
|
201
|
+
buf.append("\t");
|
202
|
+
buf.append(e.charPositionInLine);
|
203
|
+
transmit(buf.toString());
|
204
|
+
}
|
205
|
+
|
206
|
+
public void beginResync() {
|
207
|
+
transmit("beginResync");
|
208
|
+
}
|
209
|
+
|
210
|
+
public void endResync() {
|
211
|
+
transmit("endResync");
|
212
|
+
}
|
213
|
+
|
214
|
+
public void semanticPredicate(boolean result, String predicate) {
|
215
|
+
StringBuffer buf = new StringBuffer(50);
|
216
|
+
buf.append("semanticPredicate\t");
|
217
|
+
buf.append(result);
|
218
|
+
serializeText(buf, predicate);
|
219
|
+
transmit(buf.toString());
|
220
|
+
}
|
221
|
+
|
222
|
+
// A S T P a r s i n g E v e n t s
|
223
|
+
|
224
|
+
public void consumeNode(Object t) {
|
225
|
+
StringBuffer buf = new StringBuffer(50);
|
226
|
+
buf.append("consumeNode");
|
227
|
+
serializeNode(buf, t);
|
228
|
+
transmit(buf.toString());
|
229
|
+
}
|
230
|
+
|
231
|
+
public void LT(int i, Object t) {
|
232
|
+
int ID = adaptor.getUniqueID(t);
|
233
|
+
String text = adaptor.getText(t);
|
234
|
+
int type = adaptor.getType(t);
|
235
|
+
StringBuffer buf = new StringBuffer(50);
|
236
|
+
buf.append("LN\t"); // lookahead node; distinguish from LT in protocol
|
237
|
+
buf.append(i);
|
238
|
+
serializeNode(buf, t);
|
239
|
+
transmit(buf.toString());
|
240
|
+
}
|
241
|
+
|
242
|
+
protected void serializeNode(StringBuffer buf, Object t) {
|
243
|
+
int ID = adaptor.getUniqueID(t);
|
244
|
+
String text = adaptor.getText(t);
|
245
|
+
int type = adaptor.getType(t);
|
246
|
+
buf.append("\t");
|
247
|
+
buf.append(ID);
|
248
|
+
buf.append("\t");
|
249
|
+
buf.append(type);
|
250
|
+
Token token = adaptor.getToken(t);
|
251
|
+
int line = -1;
|
252
|
+
int pos = -1;
|
253
|
+
if ( token!=null ) {
|
254
|
+
line = token.getLine();
|
255
|
+
pos = token.getCharPositionInLine();
|
256
|
+
}
|
257
|
+
buf.append("\t");
|
258
|
+
buf.append(line);
|
259
|
+
buf.append("\t");
|
260
|
+
buf.append(pos);
|
261
|
+
int tokenIndex = adaptor.getTokenStartIndex(t);
|
262
|
+
buf.append("\t");
|
263
|
+
buf.append(tokenIndex);
|
264
|
+
serializeText(buf, text);
|
265
|
+
}
|
266
|
+
|
267
|
+
|
268
|
+
// A S T E v e n t s
|
269
|
+
|
270
|
+
public void nilNode(Object t) {
|
271
|
+
int ID = adaptor.getUniqueID(t);
|
272
|
+
transmit("nilNode\t"+ID);
|
273
|
+
}
|
274
|
+
|
275
|
+
public void errorNode(Object t) {
|
276
|
+
int ID = adaptor.getUniqueID(t);
|
277
|
+
String text = t.toString();
|
278
|
+
StringBuffer buf = new StringBuffer(50);
|
279
|
+
buf.append("errorNode\t");
|
280
|
+
buf.append(ID);
|
281
|
+
buf.append("\t");
|
282
|
+
buf.append(Token.INVALID_TOKEN_TYPE);
|
283
|
+
serializeText(buf, text);
|
284
|
+
transmit(buf.toString());
|
285
|
+
}
|
286
|
+
|
287
|
+
public void createNode(Object t) {
|
288
|
+
int ID = adaptor.getUniqueID(t);
|
289
|
+
String text = adaptor.getText(t);
|
290
|
+
int type = adaptor.getType(t);
|
291
|
+
StringBuffer buf = new StringBuffer(50);
|
292
|
+
buf.append("createNodeFromTokenElements\t");
|
293
|
+
buf.append(ID);
|
294
|
+
buf.append("\t");
|
295
|
+
buf.append(type);
|
296
|
+
serializeText(buf, text);
|
297
|
+
transmit(buf.toString());
|
298
|
+
}
|
299
|
+
|
300
|
+
public void createNode(Object node, Token token) {
|
301
|
+
int ID = adaptor.getUniqueID(node);
|
302
|
+
int tokenIndex = token.getTokenIndex();
|
303
|
+
transmit("createNode\t"+ID+"\t"+tokenIndex);
|
304
|
+
}
|
305
|
+
|
306
|
+
public void becomeRoot(Object newRoot, Object oldRoot) {
|
307
|
+
int newRootID = adaptor.getUniqueID(newRoot);
|
308
|
+
int oldRootID = adaptor.getUniqueID(oldRoot);
|
309
|
+
transmit("becomeRoot\t"+newRootID+"\t"+oldRootID);
|
310
|
+
}
|
311
|
+
|
312
|
+
public void addChild(Object root, Object child) {
|
313
|
+
int rootID = adaptor.getUniqueID(root);
|
314
|
+
int childID = adaptor.getUniqueID(child);
|
315
|
+
transmit("addChild\t"+rootID+"\t"+childID);
|
316
|
+
}
|
317
|
+
|
318
|
+
public void setTokenBoundaries(Object t, int tokenStartIndex, int tokenStopIndex) {
|
319
|
+
int ID = adaptor.getUniqueID(t);
|
320
|
+
transmit("setTokenBoundaries\t"+ID+"\t"+tokenStartIndex+"\t"+tokenStopIndex);
|
321
|
+
}
|
322
|
+
|
323
|
+
|
324
|
+
// support
|
325
|
+
|
326
|
+
public void setTreeAdaptor(TreeAdaptor adaptor) { this.adaptor = adaptor; }
|
327
|
+
public TreeAdaptor getTreeAdaptor() { return adaptor; }
|
328
|
+
|
329
|
+
protected String serializeToken(Token t) {
|
330
|
+
StringBuffer buf = new StringBuffer(50);
|
331
|
+
buf.append(t.getTokenIndex()); buf.append('\t');
|
332
|
+
buf.append(t.getType()); buf.append('\t');
|
333
|
+
buf.append(t.getChannel()); buf.append('\t');
|
334
|
+
buf.append(t.getLine()); buf.append('\t');
|
335
|
+
buf.append(t.getCharPositionInLine());
|
336
|
+
serializeText(buf, t.getText());
|
337
|
+
return buf.toString();
|
338
|
+
}
|
339
|
+
|
340
|
+
protected void serializeText(StringBuffer buf, String text) {
|
341
|
+
buf.append("\t\"");
|
342
|
+
if ( text==null ) {
|
343
|
+
text = "";
|
344
|
+
}
|
345
|
+
// escape \n and \r all text for token appears to exist on one line
|
346
|
+
// this escape is slow but easy to understand
|
347
|
+
text = escapeNewlines(text);
|
348
|
+
buf.append(text);
|
349
|
+
}
|
350
|
+
|
351
|
+
protected String escapeNewlines(String txt) {
|
352
|
+
txt = txt.replaceAll("%","%25"); // escape all escape char ;)
|
353
|
+
txt = txt.replaceAll("\n","%0A"); // escape \n
|
354
|
+
txt = txt.replaceAll("\r","%0D"); // escape \r
|
355
|
+
return txt;
|
356
|
+
}
|
357
|
+
}
|
358
|
+
|