Compagnie Gaspard Buma
enfr

News

Workshop lubyk

Workshop interne avec l’équipe de l’EPFL-ECAL-lab pour évaluer lubyk. Si tout va bien, on aura quelques démos à mettre en ligne…

Prochain spectacle

Nous travaillons actuellement sur le spectacle des bateaux pour nulle part prévu pour l’automne 2012.

Ragel state machine

Well, lemon was nice but it was too hard for me to grasp how to glue it with flex and my C++ classes. So here we go with ragel, a finite state machine compiler.

dotRagel

Ragel is a tool to create finite state machines. We use it to parse rubyk’s patches and for the command line.

The main site for Ragel is here. Ragel is nice because it lets you write code (your own things) and insert the ragel rules inside. It is very easy to embed, fast and works like my mind (see picture above). Here is the structure of a program using ragel :

#define blah

void parse(const char* pStr)
{
  // some of your code

  %%{
  here comes the ragel rules and actions
  }%%

  // some more code
}

When rendering the ragel file, it leaves your own code untouched and inserts a parser in place of the rules.

I do not have time to write a tutorial on how to use ragel, but I have created a simple example that outputs the input phrase, replacing all words by [WORD], digits by [DIGITS] and so on.

Here is the file :

document txt

921 octets

wordsAndDigits

Simple example of a ‘ragel’ definition file.

Compile and run with:

# ragel wordsAndDigits.rl | rlgen-cd -o words.cpp
# g++ words.cpp -o test
# ./test

I have also created a small ruby script to wrap the commands for creating the transitions diagram :

document rb

753 octets

ragel dot wrapper

Simple wrapper to generate the graphviz image from a ragel definition.