Hi Ihor, Unless you require the speed of an integrated lexer and parser I would suggest using the traditional lexing then parsing approach. That would avoid having to put whitespace the grammar.
-Adrian Ihor Kaharlichenko wrote: > Hi, all. > > I'm very new to ragel and the solution to my problem may seem obvious, but I > googled a lot and could not find a solution to it. > > I need to parse simplified mental ray shader declarations > <http://download.autodesk.com/us/maya/2009help/mr/manual/node61.html#SECTION59>. > > In general input looks like this: > > declare shader > [/type/] "/shader_name/" ( > /type/ "/parameter_name/", > /type/ "/parameter_name/", > ... > /type/ "/parameter_name/" > ) > [version /version/_int ] > end declare > > > My problem is that mental ray files are not restrictive to spaces and > newlines, so two following declarations should be considered the same: > > 1. declare shader "myShader" ( int "param1", boolean "param2" ) > version 12 end declare > 2. > > declare shader "myShader" ( > int "param1" , > boolean "param2" > ) > version 12 > end declare > > Here's my machine declaration: > > %%{ > machine shader; > > sep = space+; > > shader_start = 'declare' . sep . 'shader' . sep; > shader_end = 'end' . sep . 'declare' . sep; > > string = '"' . (alnum | '_')+ . '"' . sep; > > type = ('boolean' | 'integer' | 'scalar') . sep; > version = 'version' . sep . digit+ . sep; > > parameter = string . type; > > parameter_block = parameter . (',' . sep . parameter)*; > shader = > shader_start . > type? . string . > '(' . sep? . parameter_block? . ')' . sep . > version? . > shader_end; > > main := shader; > }%% > > As you can see there are too many "sep"s used in the declaration. They > seem to be a total mess to me, as I don't cannot even match the > following with my machine: *int "qwe" ,* (note the space between a quote > and a coma) > > Can anybody suggest a better way to define my machine in order to parse > such this kind of declarations? Maybe scanners could help me, but I'm > not sure whether they are capable to detect format errors or not. > > Thanks, Ihor > > > ------------------------------------------------------------------------ > > _______________________________________________ > ragel-users mailing list > [email protected] > http://www.complang.org/mailman/listinfo/ragel-users _______________________________________________ ragel-users mailing list [email protected] http://www.complang.org/mailman/listinfo/ragel-users
