<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi, all.<br>
<pre>
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 <a moz-do-not-send="true"
 href="http://download.autodesk.com/us/maya/2009help/mr/manual/node61.html#SECTION59">shader declarations</a>.

In general input looks like this:

<tt>declare shader
    <dfn>[</dfn><i>type</i><dfn>]</dfn> "<i>shader_name</i>" (
        <i>type</i> "<i>parameter_name</i>",
        <i>type</i> "<i>parameter_name</i>",
              <dfn>...</dfn>
        <i>type</i> "<i>parameter_name</i>"<dfn></dfn>
    )
    <dfn>[</dfn>version <i>version</i><sub>int</sub><dfn>]</dfn>
end declare</tt>


My problem is that mental ray files are not restrictive to spaces and newlines, so two following declarations should be considered the same:
</pre>
<ol>
  <li><tt>declare shader "myShader" ( int "param1", boolean "param2" ) 
version 12 end declare</tt></li>
  <li>
    <pre>declare              shader      "myShader" (
    int     "param1"   ,
    boolean "param2"
    )
    version 12
end declare</pre>
  </li>
</ol>
Here's my machine declaration:<br>
<tt><br>
%%{<br>
    machine shader;<br>
    <br>
    sep = space+;<br>
    <br>
    shader_start = 'declare' . sep . 'shader' . sep;<br>
    shader_end = 'end' . sep . 'declare' . sep;<br>
    <br>
    string = '"' . (alnum | '_')+ . '"' . sep;<br>
    <br>
    type = ('boolean' | 'integer' | 'scalar') . sep;<br>
    version = 'version' . sep . digit+ . sep;<br>
    <br>
    parameter = string . type;<br>
    <br>
    parameter_block = parameter . (',' . sep . parameter)*;<br>
    shader =<br>
        shader_start .<br>
        type? . string .<br>
        '(' . sep? . parameter_block? . ')' . sep .<br>
        version? .<br>
        shader_end;<br>
    <br>
    main := shader;<br>
}%%<br>
<br>
</tt>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: <b>int "qwe" ,</b> (note the space between
a quote and a coma)<br>
<br>
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.<br>
<br>
Thanks, Ihor<br>
</body>
</html>