Page:
Can I see a more complete example?
Sure you can! This is a real example from Tapestry 5, which includes a simple property expression grammar. In Tapestry 5.0, this is ad-hoc based on regular expressions; in 5.1 it will be ANTLR based …
|
Page:
How can I allow keywords as identifiers?
This grammar allows "if if call call;" and "call if;". grammar Pred; prog: stat+ ; stat: keyIF expr stat | keyCALL ID ';' | ';' ; expr: ID ; keyIF : {input.LT(1).getText().equals("if")}? ID ; keyCALL …
Other labels:
faq_parsing
|
Page:
How can I emit an error token upon lexical error?
v3.1 required (but change state to "this" and should be ok in 3.0.1) Sometimes you want the lexer to emit error tokens to the parser rather than consume the bad input and throw it away. To do this, we…
|
Page:
How can I make the lexer exit upon first lexical error?
v3.1 required (but change state to "this" and should be ok in 3.0.1) You need to override the default behavior which tries to recover and keep lexing. There are two approaches depending upon if you ca…
|
Page:
How do I access hidden tokens from parser?
Rules in the lexer can send tokens to the parser on different "channels". See How do I track whitespace, comments, and other hidden channels during AST construction? For example, COMMENT : '/*' .* '*/…
Other labels:
faq_translation
|
Page:
How do I combine fuzzy parsing and stream rewriting?
If you want to parse just pieces of, say, a Java file using filter mode (fuzzy parsing) and do some replacement like TokenRewriteStream does, how can you do it? TokenRewriteStream requires use of a pa…
Other labels:
faq_translation
|
Page:
How do I get case insensitivity?
Discussions There is some discussion about this subject (ANTLR v3) here: http://www.antlr.org/pipermail/antlr-interest/2006-May/016269.html In summary, there is no ANTLR option that enables case insen…
|
Page:
How do I handle abbreviated keywords?
Given a language that accepts abbreviated forms of the following keywords: Keyword Abbreviations print pr, pri, prin, print read re, rea, read fold fo, fol, fold apply ap, app, appl, apply There are t…
|
Page:
How do I implement include files?
Stacked Input Streams - "include" files Java Here is sample Java-code for implementation 'include' directive. Thanks Terence Parr for important notices and Tim Clark for improvements. @lexer::members …
Other labels:
c
|
Page:
How do I match multi-line comments?
The way to parse and probably ignore the usual c-style comments found in many programming languages has changed from ANTLR 2. Instead of: // ANTLR 2 ML_COMMENT : "/*" ( /* '\r' '\n' can be matched in …
|