Live data from Hacker News

Ragel State Machine Compiler

colm.net

11–20 of 22 posts

Re: Ragel State Machine Compiler

#11
post #2

How is this different from Lex, written in 1975? Even the syntax looks fairly similar. https://en.wikipedia.org/wiki/Lex_(software)

I tried to find a good quote to summarize, but really, it's probably just worth reading the "Motivation" section of the guide[0], if your question is asked in good faith.

Note also that Ragel isn't some new-fangled thing. It was first released in January of 2002, and is very mature.

[0]: http://www.colm.net/files/ragel/ragel-guide-6.9.pdf

Re: Ragel State Machine Compiler

#12
post #4

Are you aware of anyone working to add Python as a target language? Will Ragel 7's intermediate codegen language make that easier?

Not at this time. But yes Ragel 7 will make it much easier. The first round of new languages I added helped me polish the technique. Once 7 is out and vetted it will make sense to add more.

Re: Ragel State Machine Compiler

#14
post #2

How is this different from Lex, written in 1975? Even the syntax looks fairly similar. https://en.wikipedia.org/wiki/Lex_(software)

Lex solves a restricted subset of state machine code generation problems; Ragel aims to solve all state machine code generation problems generally. You can do anything you can do in Lex in Ragel. The reverse is not true. Lex is simpler, but less powerful than Ragel. It's sort of like awk versus Perl.

I'd rather use Lex where Lex is good enough.

Re: Ragel State Machine Compiler

#17
post #16

Seems like Lua would be a perfect target for Ragel. Do you know if anyone is working in this direction ? How does it compare with LPeg[1] ? This is what I currently use for all my parsing needs. [1] http://www.inf.puc-rio.br/~roberto/lpeg/

Ragel doesn't support recursion (last I checked), so it's not suitable for many parsing jobs. I considered it for MoonScript's parser at one point but it didn't seem like it could do it. I've been experimenting with this project as a replacement for LPEG for the MoonScript parser: http://piumarta.com/software/peg/

I've made an LPEG style syntax that compiles to the peg syntax for that tool, which is then compiled to c and linked into a Lua module, you can see how the parser is written here: https://github.com/leafo/moonparse/blob/master/parse.peg.moo...

Re: Ragel State Machine Compiler

#18

Earlier quoted context omitted.

Why would you want to do that?

There are a lot of advantages to a declarative approach, and a lot of risks and problems with hand written parsers and state machines. A good example is the http code Zed wrote with ragel. From what I remember it was contracted by verisign because they wanted an implementation that actually followed the spec in detail, unlike all other code available at the time. That ragel code has been reused by a lot of embedded h…

The thing I keep finding problematic about declarative approaches is that nobody knows them. That means if you're not a lone wolf on a project, the people editing your declarative state machine are going to be unfamiliar with it. Aside from the complaints that gives (and the "look I rewrote it" issues), that means they make mistakes and don't understand what happens.

So they don't last. They're not all that maintainable in real teams. My experiences are mostly with ANTLR code (which has a debugger and lots of tooling and isn't that hard at all).

I'm at a loss for how to overcome this.

Re: Ragel State Machine Compiler

#19
post #16

Seems like Lua would be a perfect target for Ragel. Do you know if anyone is working in this direction ? How does it compare with LPeg[1] ? This is what I currently use for all my parsing needs. [1] http://www.inf.puc-rio.br/~roberto/lpeg/

At their core they target different language classes. Ragel deals with regular, whereas LPeg deals with context-free grammars.

Re: Ragel State Machine Compiler

#20
post #18

Earlier quoted context omitted.

There are a lot of advantages to a declarative approach, and a lot of risks and problems with hand written parsers and state machines. A good example is the http code Zed wrote with ragel. From what I remember it was contracted by verisign because they wanted an implementation that actually followed the spec in detail, unlike all other code available at the time. That ragel code has been reused by a lot of embedded h…

The thing I keep finding problematic about declarative approaches is that nobody knows them. That means if you're not a lone wolf on a project, the people editing your declarative state machine are going to be unfamiliar with it. Aside from the complaints that gives (and the "look I rewrote it" issues), that means they make mistakes and don't understand what happens. So they don't last. They're not all that maintaina…

Keep using them is how you overcome this ;)
Post reply on HN