[antlr-interest] multi-line chat messages
ian eyberg
ian at telematter.com
Tue Apr 14 13:45:17 PDT 2009
Hi,
I have some text that looks like this:
sally sue slaps userX with a big fish
userX: I like to chat and take up one line
and then I like to continue onto a second line
joe blow sneezes
joe blow blows his nose
There are three different users here:
sally sue, joe blow, userX
I have no problems with the various actions/commands
that the users do because they do not change
(slaps userX with a big fish, sneezes, blows his nose)
-- however, whenever one of them decides to chat all
hell breaks loose.. I usually have to rewrite some tokens
as parser rules.. not a huge problem -- just a pain..
anyway, multi-line chats are my big problem here as
my chatrule, as for now, accepts mostly anything EXCEPT
a newline character cause it uses that as the end part of
the rule
my question to you all is what would you do? as you can tell
I don't have quotes or any other bounding type of characters..
the best thing I can think of is to see if my next token would
be a username or one of my other tokens that would come at the
start of a newline
I've attached my test rig and simple grammar
Much appreciation in advance,
--
ian eyberg
-------------- next part --------------
grammar Chat;
options {language=Java;}
chatrule :
pl=player COLON_SPACE msg=chatmessage {
System.out.println("player: " + $pl.text);
System.out.println("message: " + $msg.text);
};
chatmessage : ~NEWLINE+;
fragment LOWER_LETTER : 'a'..'z' ;
fragment UPPER_LETTER : 'A'..'Z' ;
ALPHA : (LOWER_LETTER | UPPER_LETTER)+ ;
fragment DIGIT : ('0'..'9')+ ;
INT : DIGIT COMMA_SP?;
NEWLINE : '\r'? '\n' ;
UNDER : '_';
DASH : '-';
WS : ' '+;
COLON_SPACE : ': ';
COMMA_SP : ',' ' ' ;
JUNK : '.' | '$' | ':' | '(' | ')' | '*' | '?' | '[' | ']' | '|' | ',' | '#' | '-' | '/' | '\'';
player : (INT | ALPHA | DASH | UNDER | WS )+;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GTest.java
Type: text/x-java
Size: 417 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20090414/5f0b093e/attachment.bin
More information about the antlr-interest
mailing list