[ragel-users] Writing a Telnet parser

Jonathan Castello twisolar at gmail.com
Wed Sep 29 03:30:40 UTC 2010


I'm building a Telnet parser using Ragel, and I'm having an issue
making the actions do what I want. I've pasted the machine definition
to a gist: http://gist.github.com/602242

The issue is a little hard for me to describe, so I'll try to
illustrate it as best as I can. If I have a stream of input, and some
part of it is "abcdef<IAC><GA>ghi" (where <x> is a mnemonic for a
single byte), I want to emit events as such: text("abcdef"),
command("<GA>"), text("ghi"). The caller provides callbacks, and I
would pass the data to them as I interpret it.

The problem is that I can't figure out how to define actions that
would only trigger when the next character doesn't match plain_text
(or there's no more data left to parse in that particular packet), so
I can get that full stretch of characters. At the moment, I can only
get text("a"), text("b"), text("c") etc. to work, i.e. one plain_text
match at a time.

I suspect the problem is that cr_sequence and iac_sequence are
supposed to behave this way - they, too, match singular "terms" each
time before returning to the start - but here I am, wanting to give
plain_text special treatment. Am I even coming at this from the right

Thanks in advance for any advice!
~Jonathan Castello

ragel-users mailing list
ragel-users at complang.org

More information about the ragel-users mailing list