Frage

I have the following (very simple) Ragel file scanner.rl:

void lex(string data) {
    int cs, act, top;
    auto p = data.ptr;
    typeof(p)
        pe = &data[$ -1],
        eof = pe,
        ts,
        te;

    %%{
        machine scanner;

        identifier = alpha . alnum**;

        main := |*
            identifier => { ("Identifier: " + data[ts..te]).writeln; };
            space;
        *|;

        write data;
        write init;
        write exec;
    }%%
}

void main() {
    "this is a test".lex;
}

I convert scanner.rl to scanner.d using ragel -D scanner.rl. When I try to compile the resulting D file with dmd scanner.d, I get the following error messages:

scanner.d(97): Error: cannot implicitly convert expression (&_scanner_actions[cast(ulong)_scanner_from_state_actions[cast(ulong)cs]]) of type const(byte)* to byte* scanner.d(110): Error: cannot implicitly convert expression (&_scanner_trans_keys[cast(ulong)_scanner_key_offsets[cast(ulong)cs]]) of type const(char)* to char* scanner.d(166): Error: cannot implicitly convert expression (&_scanner_actions[cast(ulong)_scanner_trans_actions[cast(ulong)_trans]]) of type const(byte)* to byte* scanner.rl(22): Error: cannot implicitly convert expression (ts) of type immutable(char)* to ulong scanner.d(186): Error: cannot implicitly convert expression (&_scanner_actions[cast(ulong)_scanner_to_state_actions[cast(ulong)cs]]) of type const(byte)* to byte*

Perhaps I'm missing something important?

War es hilfreich?

Lösung

Are you sure ragel is generating D2 code? Looks like it is missing const.... looking at ragel's source code, looks like ragel -D generates D1 and ragel -E generates D2, though this isn't documented in --help!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top