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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---
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 )+;
import java.io.*;
import java.util.*;
import org.antlr.runtime.*;
public class GTest {
public static void main(String[] args) throws Exception {
ANTLRInputStream input = new ANTLRInputStream(System.in);
ChatLexer lexer = new ChatLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
ChatParser parser = new ChatParser(tokens);
parser.chatrule();
}
}
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address