[ragel-users] ragel didn't rename data variable for C# code.

Denis Naumov alexander.me at gmail.com
Fri Mar 25 08:52:10 UTC 2011


Hi Adrian,

about
      %% variable  data
didn't rename access to data variable for C#.

To solve this problem i search ragel source code and found
"string CSharpCodeGen::GET_KEY()" function in cscodegen.cpp

simple patch:

==================================================================
 FILE     => cscodegen.cpp
 FUNCTION => string CSharpCodeGen::GET_KEY()
==================================================================
---- OLD CODE ----------------------------------------------------

string CSharpCodeGen::GET_KEY()
{
    ostringstream ret;
    if ( getKeyExpr != 0 ) {
        /* Emit the user supplied method of retrieving the key. */
        ret << "(";
        INLINE_LIST( ret, getKeyExpr, 0, false );
        ret << ")";
    }
    else {
        /* Expression for retrieving the key, use simple dereference. */
        ret << "data[" << P() << "]";
    }
    return ret.str();
}

---- NEW CODE ----------------------------------------------------

string CSharpCodeGen::GET_KEY()
{
    ostringstream ret;
    if ( getKeyExpr != 0 ) {
        /* Emit the user supplied method of retrieving the key. */
        ret << "(";
        INLINE_LIST( ret, getKeyExpr, 0, false );
        ret << ")";
    }
    else {
        /* Expression for retrieving the key, use simple dereference. */

        if ( dataExpr == 0 )
            ret << "data";
        else
            INLINE_LIST( ret, dataExpr, 0, false );

        ret << "[" << P() << "]";
    }
    return ret.str();
}

---- END ---------------------------------------------------------

Please, check this code. Is it right ? or i forgot something?

Best regards,
Denis Naumov.


2011/3/24 Denis Naumov <alexander.me at gmail.com>:
> Hi Adrian,
>
> A week ago i start ragel and found that it is a very usefull tool.
>
> I use it for generate C and C# code (from Microsoft Visual Studio).
>
> it seems that ragel didn't rename data variable for C# code.
>
> use:
>            %% variable  data   _ctx.data;
>            %% variable  p        _ctx.current;
>            %% variable  pe      _ctx.end;
>
> code will:
>
>  ...  if ( data[(      _ctx.current)] < _test_trans_keys[_mid] ) ...
>
>
> Also i have some feature request:
> 1.
> Sometime it would be very convenient to set options in rl file rathe
> than command line.
> something like:
>   %% option lang = C#                         (in addition to -C, -A ...)
>
>   %% option line  = on/off/1/0/yes/no   (-L)
>
>   %% option minimization = off/end/most/every   (-n/-m/-l/-e)
>
>   %% option mode = table/table1/flat/flat1/goto/goto1 ...  (-T0/-T1...)
>
>   %% option output = "<filename>"  (-o <filename>)
>
>   %% option error = gnu/msvc ...
>
>
> to change this from IDE more convenient than change project settings.
> This can be alternative way to set options and options from command
> line (if set) will have max priority.
>
> 2.
> Mode for option -o <filename>.
> -o -  (-o "-") - for output generated code into stdout.
> This usefull for VS custom tool (custom code generator extention for
> VisualStudio).
> Now i create temp file for output - read it to std-stream and delete
> temp file to work around this.
>
>
> Best regards,
> Denis Naumov.
>
>
> PS: sorry for my english :)
>

_______________________________________________
ragel-users mailing list
ragel-users at complang.org
http://www.complang.org/mailman/listinfo/ragel-users


More information about the ragel-users mailing list