See the attached code. Note the "| any*". This is a trick to make ragel accept any prefix of the machine. But it only works in this case because you want the machine to accept any string at all. What is really needed is an any-prefix operator (in the TODO for years).

If this is too cryptic, you may want to consider using state charts.

-Adrian

On 04/06/2011 06:47 AM, Wilson Barros wrote:
main:='O'@init ((any-[CTRDH])*
('C'$ccaOn(any-'c')*'c'$ccaOff
|'T'$txOn(any-'t')*'t'$txOff
|'R'$rxOn(any-'r')*'r'$rxOff
|'D'$dozeOn(any-'A')*'A'$dozeOff
|'H'$hibOn(any-'A')*'A'$hibOff #)
)*;

--
Adrian D. Thurston
http://www.complang.org/thurston/
%%{
        machine modem;

        action init {}
        action ccaOn {}
        action ccaOff {}
        action txOn {}
        action txOff {}
        action rxOn {}
        action rxOff {}
        action dozeOn {}
        action dozeOff {}
        action hibOn {}
        action hibOff {}

        modem =
                (
                        [^CTRDH]*
                        (
                                'C' @ccaOn   (any-'c')*'c' @ccaOff |
                                'T' @txOn    (any-'t')*'t' @txOff |
                                'R' @rxOn    (any-'r')*'r' @rxOff |
                                'D' @dozeOn  (any-'A')*'A' @dozeOff |
                                'H' @hibOn   (any-'A')*'A' @hibOff
                        )
                )*;

        main := (
                'O' @init 
                ( modem | any* )
        )?;

}%%
_______________________________________________
ragel-users mailing list
[email protected]
http://www.complang.org/mailman/listinfo/ragel-users

Reply via email to