Terence Parr
a9e74ce399
Merge branch 'failed-predicate-message' of git://github.com/sharwell/antlr4
2012-03-06 13:28:47 -08:00
Sam Harwell
5deab167a1
ParseTreeVisitor.visit takes a ParseTree... only visitChildren takes a RuleNode
2012-03-04 12:52:43 -06:00
Sam Harwell
b570641e2b
Simplify ParseTree.visitChildren; ParseTree.visit and visitChildren take a RuleNode parameter; update comments
2012-03-04 12:17:43 -06:00
Sam Harwell
a948736729
TerminalNodeImpl.isErrorNode now tests for ErrorNode interface instead of ErrorNodeImpl implementation
2012-03-03 21:57:49 -06:00
Sam Harwell
80b3ec8c62
Dispatch accept() for terminal nodes to visitor
2012-03-03 21:57:08 -06:00
Terence Parr
0375f8318a
rename a parameter
2012-03-01 18:01:27 -08:00
Terence Parr
2ba5a1f12a
Made the parse tree visitor walk ParseTree objects not ParserRuleContext objects. This necessitated pulling up the accept() and toStringTree(Parser) methods into ParseTree.
2012-03-01 17:57:49 -08:00
Sam Harwell
fa9ec191bd
Add TrimToSizeListener and Parser.get/setTrimParseTrees
2012-02-29 11:22:54 -06:00
Sam Harwell
c3cd99858c
Reduce size of generated code by emitting predicate text instead of full failed predicate message
2012-02-29 08:14:42 -06:00
Terence Parr
dd69a7532d
getToken/s returns TerminalNode now per Sam's suggestion. altered tests. seems correct.
2012-02-27 21:39:30 -08:00
Terence Parr
9ae92a5cef
reformat
2012-02-27 21:32:25 -08:00
Terence Parr
67b2e6d7c1
forgot to move Pair etc...
2012-02-26 21:55:23 -08:00
Terence Parr
e9a3de645a
add useful method to get a->b pairs out
2012-02-26 15:55:46 -08:00
Terence Parr
41be88dcd5
mv to runtime
2012-02-26 15:49:45 -08:00
Sam Harwell
bedc502d33
Set the listeners list back to null if all listeners are removed from it
2012-02-26 17:33:52 -06:00
Terence Parr
1e438746be
added interface for error nodes, method in terminalnode.
2012-02-26 15:32:18 -08:00
Terence Parr
db1b86af91
alter visitTerminal interface, add visitErrorNode.
2012-02-25 17:03:41 -08:00
Terence Parr
528e9c7b86
fix cut/paste error
2012-02-25 16:09:29 -08:00
Terence Parr
600c4bbd91
crap. sun already made IdentityHashMap; rm'ing my version
2012-02-25 16:07:34 -08:00
Terence Parr
73ae2b0bfc
Added ParseTreeProperty and added generically useful Map that ignores key.hashCode and equals() and simply uses key identity instead. In particular, this is useful for ANTLR because parse trees are actually interfaces laid on top of the rule context objects used by ANTLR's grammar analysis. These context objects use special equals methods and so on. Plus, when we want to annotate trees with values, we want a specific note to have a value. Identity is what we intend.
2012-02-25 13:43:32 -08:00
Sam Harwell
a74da2df60
Use ==ParserRuleContext.EMPTY instead of .isEmpty()
2012-02-24 15:57:43 -06:00
Sam Harwell
9bf6f284df
Code cleanup (little things like using .isEmpty() and StringBuilder, and specify some small-scale generic arguments)
2012-02-23 16:42:36 -06:00
Sam Harwell
1e3e092326
Fix unchecked warnings in clone()
2012-02-23 16:13:15 -06:00
Sam Harwell
e400f5b1a1
Move Recognizer._errHandler to Parser class
2012-02-23 16:13:14 -06:00
Sam Harwell
1c8efd6a48
Allow contravariant error listeners
2012-02-23 16:13:13 -06:00
Sam Harwell
6c26917b90
Use generic List instead of generic array for listeners
2012-02-23 16:13:12 -06:00
Sam Harwell
7dcb148d73
CommonTokenStream now extends BufferedTokenStream<Token> instead of BufferedTokenStream<CommonToken>. Token interface provides the same information and the change helps the work on improving generics.
2012-02-23 16:13:11 -06:00
Sam Harwell
d7dbef2782
Can get token start and stop index from Token interface now
2012-02-23 16:13:11 -06:00
Sam Harwell
1492648d26
Add missing @Override annotations
2012-02-23 16:13:06 -06:00
Sam Harwell
96c08bec52
Remove unused imports
2012-02-23 16:12:02 -06:00
Terence Parr
b459dafeb9
empty alternatives didn't trigger listener events. overrode getParent in ParserRuleContext to make type more specific.
2012-02-23 12:16:14 -08:00
Terence Parr
8a34176d82
added listener unit tests. fixed bug that didn't create ctx getters properly for recursive rules. added Symbol extends Token to parse tree stuff. added visitTerminal to Visitor. recursive alts now track their original, unedited AltAST subtree so we can properly count rule refs etc... later. dup of RuleRefAST was making wrong node. don't gen dispatch methods if no listener.
2012-02-22 12:44:33 -08:00
Terence Parr
58ef729be5
renamed next to target. factored out to methods, commented code.
2012-02-21 12:47:34 -08:00
Terence Parr
0e23c7e2a3
Merge commit '611728a3806d6a8c9fe44a538d34b448784986c1'
2012-02-21 12:14:11 -08:00
Sam Harwell
5fb389b6e4
Improve lexer performance during warm-up by tracking DFA states within exec (ATN) and using existing edges when available
2012-02-20 19:20:50 -06:00
Sam Harwell
611728a380
Update testPerformance to show information about DFA states in the lexer
2012-02-20 18:51:26 -06:00
Sam Harwell
a81b1a17eb
Extract abstract method in Recognizer for Parser.getGrammarFileName() and generated lexer's getGrammarFileName(). Make Recognizer.getTokenNames(), getRuleNames(), and getATN() abstract - implementations are always generated.
2012-02-20 17:18:57 -06:00
Sam Harwell
2982f4b5a6
Add comments describing the semantics of an ATNConfig set with partially predicated alts in ParserATNSimulator
2012-02-20 15:43:02 -06:00
Sam Harwell
16fa8ba4f4
Add comments describing the context depth latch in ParserATNSimulator.closure
2012-02-20 15:25:58 -06:00
Terence Parr
e9122cafa3
Merge commit '46d5458'
2012-02-20 12:22:37 -08:00
Terence Parr
1a2094b2dd
merging Sam\'s fix to full ctx pred etc...; effectively did pull parrt/antlr4#15 , includes fixes antlr/antlr4#14 , includes fixes antlr/antlr4#15
2012-02-20 11:48:03 -08:00
Terence Parr
4e8931519c
added -parse-listener option and generated code if option on. parse listener differs from tree listener
2012-02-18 16:49:05 -08:00
Terence Parr
725b105135
Added visitor gen mechanism, runtime support
2012-02-16 17:49:57 -08:00
Sam Harwell
27806dc490
Merge remote-tracking branch 'parrt/master'
2012-02-15 14:58:16 -06:00
Sam Harwell
28919bbdc5
Fix ParserATNSimulator.execDFA consuming an unnecessary symbol after an accept or context-sensitive state is reached
2012-02-15 14:02:50 -06:00
Sam Harwell
685cf7b7d5
Further improvements to auto-label generic usage, return Collections.emptyList() instead of null when no children are found
2012-02-15 12:31:43 -06:00
Sam Harwell
0bbb7101ba
Include input character in LexerNoViableAltException.toString()
2012-02-15 12:02:44 -06:00
Sam Harwell
bc87562aff
Remove unused exception LexerRecognitionExeption [sic]
2012-02-15 11:01:01 -06:00
Sam Harwell
5ab082967f
Fix generic usage
2012-02-15 10:50:37 -06:00
Terence Parr
fa3a664696
got some good examples working that play around with the getter methods.
2012-02-14 16:33:12 -08:00
Terence Parr
cdb420fdde
got implementation of getters in! Fixes #8
2012-02-14 15:01:03 -08:00
Sam Harwell
9600a70724
Fix NPE in CommonToken when TokenSource is not available
2012-02-13 08:41:57 -06:00
Terence Parr
6e4cba131a
Allow var args in ctor of IntervalSet
2012-02-11 15:30:54 -08:00
Terence Parr
f278d3b453
add unit test for left-recur grammars
2012-02-11 11:35:27 -08:00
Sam Harwell
cd3adb140d
Fix ParserATNSimulator.execDFA adding incorrect error edges in the DFA
2012-02-10 00:52:24 -06:00
Sam Harwell
30c58bf8eb
Specify <?> type parameter on raw types
2012-02-10 00:51:23 -06:00
Sam Harwell
99ce3cba5c
Fix ParserATNSimulator.closure not tracking proper context for context-sensitive predicates during full-context parsing
2012-02-09 19:47:56 -06:00
Sam Harwell
467797785f
Fix generics in ParserATNSimulator
2012-02-09 15:37:56 -06:00
Sam Harwell
ddf946b067
Token.EOF instead of -1, add <?> to generic type usage, make getUniqueAlt an instance method (need to override it for some apps), @NotNull annotations
2012-02-09 15:33:03 -06:00
Sam Harwell
7fb73a3849
Construct DFA instances with the decision number
2012-02-09 13:29:14 -06:00
Sam Harwell
bf5df30708
Remove unnecessary initializations, use isEmpty() instead of size()==0
2012-02-09 12:45:46 -06:00
sharwell
46d5458617
Fix handling of alts with some configs predicated and some configs unpredicated (should be treated as always true)
2012-02-09 01:11:09 -06:00
sharwell
9c554a002b
Add LexerATNSimulator.copyState (allows copying state information from another simulator instance)
2012-02-09 00:15:30 -06:00
sharwell
40a8759276
Add LexerATNSimulator.getTraceStream
2012-02-09 00:14:37 -06:00
sharwell
3b4ae2a742
Use trivial implementation of mark/release for BufferedTokenStream
2012-02-08 18:58:57 -06:00
sharwell
f43f9f2218
Override CommonTokenStream.reset() to make sure the stream is left on an on-channel token
2012-02-08 18:58:19 -06:00
sharwell
a34fd6330b
Use isEmpty() instead of size()==0
2012-02-08 18:57:32 -06:00
sharwell
a9e44f3aab
Use isEmpty() instead of size()==0, use StringBuilder instead of StringBuffer, use chained append() calls instead of string concatenation, add @Override annotations
2012-02-08 18:57:05 -06:00
sharwell
d181b230dc
Specify generic type parameter
2012-02-08 18:55:57 -06:00
sharwell
64203312ac
Improved SemanticContext.hashCode(), add @Override annotations
2012-02-08 18:54:40 -06:00
sharwell
773e9e1c7e
Add generic type argument
2012-02-08 18:12:01 -06:00
sharwell
dcdfac4bcd
Improved implementation of equals() and hashCode() for ATNConfig
2012-02-08 18:09:32 -06:00
sharwell
64210f4b72
Add @NotNull annotations, make ATNConfig.semanticContext field final
2012-02-08 17:21:09 -06:00
sharwell
71e0c66477
Rename NUM_EDGES to MAX_DFA_EDGE, reduce max value to 127
2012-02-08 17:15:34 -06:00
sharwell
2249135c21
Specify generic type parameters
2012-02-08 17:12:22 -06:00
sharwell
1df70924f5
Use ATNConfigSet instead of OrderedHashSet<ATNConfig>
2012-02-08 17:06:41 -06:00
sharwell
52256044a9
Use for each instead of indexed for; use isEmpty() instead of size()==0
2012-02-08 17:06:03 -06:00
sharwell
326cb259a0
Construct Parser with TokenStream (restriction from IntStream)
2012-02-08 16:34:04 -06:00
sharwell
18a6414fb3
Use ATNConfigSet for parameter instead of OrderedHashSet<ATNConfig>
2012-02-08 16:26:14 -06:00
sharwell
a6524d8b38
Add pom.xml to support maven builds
2012-02-08 15:07:06 -06:00
Terence Parr
894a77168d
rename atn sim, add error message to TestRig
2012-02-05 10:14:04 -08:00
Terence Parr
1cc7ac3410
added -trace to TestRig. fixed code gen issue for trace listener
2012-01-30 16:51:55 -08:00
parrt
e90b322dd4
~[] stuff is allowed and works inside sets etc...
...
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9926]
2012-01-28 14:36:46 -08:00
parrt
09da63cfd4
rollback and do a real fix for whitespace escaping
...
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9911]
2012-01-27 12:00:30 -08:00
parrt
7498908d62
rollback and do a real fix for whitespace escaping
...
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9906]
2012-01-26 14:18:57 -08:00
parrt
adcf72b9a2
whitespace was being escaped to special characters even when printing to string should only do so when doing GUI tree
...
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9904]
2012-01-26 14:11:30 -08:00
parrt
9fd280b30e
Lexer fields mv from x to _x
...
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9883]
2012-01-21 15:36:20 -08:00
parrt
6013c4c97d
Added modeNames to gen'd lexers
...
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9878]
2012-01-21 15:10:46 -08:00
parrt
dc82edad02
Summary: we can have lexer commands like -> skip now.
...
moved model.actions package to chunk
type(foo) didn't match.
ATNBuilder.g now tracks the outer alternative number and calls new factory commands on the lexer commands.
Removed unnecessary resolveWithPredicate field from ATNConfig
Added lexerActionIndex field to ATNConfig since we need to track whether we passed an action in an alternative will rule in the lexer.
Renamed ruleIndex in DFAState and added the lexer action index so that we can execute lexer actions from the DFA.
added functions to the grammar tree visitor for the lexer commands.
Added templates for the lexer commands.
Augmented the lexer ATN factory so that it constructs plain old actions from the lexer commands it finds. That way, the code generator doesn't know any different and generates an action.
Augmented the lexer ATN simulator so that it fires a proper action index now. previously it only used the rule index, which of course doesn't work when you have more than one action in a rule.
rm'd dup code from OutputModelController
altered the epsilon edge removal optimization so that it could not remove actions in lexer rules.
Added list of valid lexer commands in Rule.
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9877]
2012-01-21 15:01:05 -08:00
parrt
093a4f951b
leave start/stop char index alone in CommonTokenFactory; refers to original text.
...
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9867]
2012-01-14 11:18:23 -08:00
parrt
5bd780c235
in tree views, spaces/newlines were blanks. I converted to \n and middle dot
...
for space.
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9857]
2012-01-11 17:25:44 -08:00
parrt
848c6e4313
This change is a major restructuring of how left recursive rules are transformed. Previously I simply rewrote the grammar and ANTLR was none the wiser. However, it quickly became apparent that ANTLR needed to do many different things for recursive rules so I had to insert transformation later in the pipeline. Specifically, I needed it after Rule object creation. I made a special LeftRecursiveRule object that track information collected during transformation so that I could use it later. I made major changes to the left recursion templates as well as the little code snippets in Java.stg. I created a new template called LeftRecursiveRuleFunction an accompanying model object that handles the special case, even though there is some duplication. the biggest difference in the grammar is the introduction of => ID notation on any outermost alternative. This information is not added to the tree, instead the ALT node is annotated with the ID. Rule.getAltLabels() now looks also in the LeftRecursiveRuleAltInfo objects. I have moved to the left recursion transformation to its own object and have moved some objects into the analysis package. Further, I have split out the Rule object creation into its own RuleCollector. I renamed discoverAlt in the grammar tree visitor to be discoverOuterAlt an added discoverAlt so we can get information about individual alts even inside subrules. Listeners always get an event for the generic rule context, which is used if there is no specific label for an alternative. Added a list of iteration operations for LL(*) subrules. Split buildRuleFunction into buildLeftRecursiveRuleFunction and one for normal rule function creation. I have to insert lots of extra code to manage the contexts, but of course it's all done using the templates. As long as those templates are correct, this code generation mechanism will work. I removed the st field from the parser rule context. I injected the left recursion transformation inside the SemanticPipeline. Visitor dispatch methods are always added to the generated context structures. Fixed some unit tests. About 24 fail.
...
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9854]
2012-01-11 11:00:05 -08:00
sharwell
742a08862f
Merging dev changes to main
...
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9853]
2012-01-09 10:26:23 -08:00
parrt
4ae23f4a64
* 1+2*3 now gives new parse tree: (e (e 1) + (e (e 2) * (e 3))) See CHANGES.txt now too
...
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9833]
2012-01-05 12:27:14 -08:00
parrt
cab41e41e3
had non-ascii char
...
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9812]
2012-01-04 09:05:31 -08:00
parrt
963ccd2700
added comment
...
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9797]
2012-01-03 12:46:51 -08:00
parrt
224a4bc9e1
changed formatting
...
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9796]
2012-01-03 12:46:39 -08:00
parrt
8099cec3bd
Added ctx to visitTerminal in parse tree listener. That should be useful information. made commensurate change in the parse tree walker to make sure I have a proper context to send to the visitTerminal method. renamed a few fields of parser/lexer to have _ in front to avoid name collisions with user actions. change the name of the listener method so that they're more explicit using the terms Error and Parser to identify what kind of listener we are adding or removing. Added a default TraceListener to Parser so that we can call setTrace(true) to have it start dumping out information as a first step in the debugging process. there are now multiple parse tree listeners possible because I made a list. we may want to pass in multiple actions to the parser.
...
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9795]
2012-01-03 12:46:18 -08:00
parrt
5c328c7e3f
Bug: didn't stop at end of stream during consume()
...
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9794]
2012-01-03 12:40:42 -08:00
parrt
5d60e85617
rm trace ATN state stuff. Will think about when we do debugging.
...
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9792]
2012-01-03 11:07:49 -08:00