[antlr-interest] spaces in name again

向秦贤 fyaoxy at gmail.com
Thu Aug 16 16:15:31 PDT 2007


suppose has a string like follows:
hello world
Grammar Unit Testing
Firstname lastname

I found not so good result after google or search in antlr site, and check
out jboss rules way, I return without more got, jboss rules had discard
inherited TokenStream class and its new version changed.
After times tries, I got a way:

grammar TestSpace;
words    :    WORDS;

WORDS    :    WORD (WS WORD)* WS?
    {
        $channel=0;
        setText($text.trim());
    };
fragment
WORD    :    CHAR+;
WS    :    SPACE+ {$channel=HIDDEN;};
fragment
CHAR    :    ~(COMMA | SEMI | COLON | LBAK | RBAK | SQUOTE | DQUOTE | SPACE
| CRLF);
fragment
SPACE    :    ' ' | '\t' | '\u000C';
COMMA    :    ',';
SEMI    :    ';';
COLON    :    ':';
LBAK    :    '{';
RBAK    :    '}';
SQUOTE    :    '\'';
DQUOTE    :    '"';
fragment
CRLF    :    '\r' | '\n';

default all whitespace ignored, but in some lexer phase, I recover it again.
In my grammar, it works fine.

Anyone some other idea?

-- 
致敬
向秦贤
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070817/c85737b3/attachment.html 


More information about the antlr-interest mailing list