[antlr-interest] multi-line chat messages
William H. Schultz
whschultz at cedrus.com
Wed Apr 15 10:26:58 PDT 2009
On Apr 14, 2009, at 1:45 PM, ian eyberg wrote:
> 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,
I'll warn that I haven't looked at the attached files, but I can
imagine all hell breaking loose with input like this:
sally sue slaps userX with a big fish
userX: I really like seeing when it says
sally sue slaps userX with a big fish
sally sue slaps userX with a big fish
It's completely ambiguous what the last two lines really are. We
might interpret that the first one is a comment and that the second is
information, but there's nothing in the grammar to clarify the
uncertainty. Instead of looking for a newline character at the end,
you could try looking for a token at the beginning. For example:
">>" As long as the token is something that isn't _allowed_ in user
input, you'll be fine.
>
>
> --
> ian eyberg
> <Chat.g><GTest.java>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
-------------------------------
Hank Schultz
Cedrus Corporation
http://www.cedrus.com/
More information about the antlr-interest
mailing list