|
|
Re: How do I capture all the text between two tokens? [message #638666 is a reply to message #638585] |
Fri, 12 November 2010 03:09 |
Henrik Lindberg Messages: 2509 Registered: July 2009 |
Senior Member |
|
|
Hi,
Search this forum for the topic "terminals gets my knickers in a twist
every time" where Sebastian helped me with something similar.
The question is if you want everything between a START and and END to be
the raw input (all spaces, newlines, etc. except END) in one string, or
if you want a sequence of strings/tokens separated by any amount of
(ignored) whitespace.
Sebastian helped with terminal definitions that I use for templates -
corresponding to %{ }% in your example, but where it is possible to
escape inside the %{ }%.
If you do not need to escape inside the %{ }% you could try the ->
operator (everything from lhs to rhs inclusive) in the terminal - as in
this rule:
terminal JAVADOC : '/**' -> '*/' ;
If you are interested in looking at the implementation in the b3
project, start with the rule called Template in BeeLang.xtext and drill
down towards the terminals. (This implementation is more advanced than
just getting the "raw" input between two special tokes, but may be of
value if you plan to switch between "modes").
If you want a sequence of tokens you can instead use a (non terminal)
rule - something like this:
Rule : '%{' (ID | INT | STRING | Keyword1 | Keyword2 | ...)* '%}' ;
with the drawback that you have to list all keywords that may appear.
- henrik
On 11/11/10 6:03 PM, Chris Ainsley wrote:
> Hi,
>
> I'm wondering what is the best way to consume the text between two
> tokens. The STRING terminator does not seem appropriate. I simply want
> all the characters until the '}%' token is reached. Do I need to define
> a new terminator category or is there some other way?
>
> Scriptlet:
> '%{' text=STRING '}%';
>
>
> Thanks,
>
> Chris
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.03329 seconds