2013-09-30 35 views
0

我有以下的(很簡單)Ragel文件scanner.rl:使用ragel -D scanner.rl爲什麼這個Ragel文件會產生隱式轉換錯誤? (Ragel與d)

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; 
} 

我轉換scanner.rlscanner.d。當我嘗試編譯生成的文件Ddmd scanner.d,我收到以下錯誤信息:

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*

也許我失去了一些重要的東西?

+1

你確定ragel正在生成D2代碼嗎?看起來它缺少const ....看着ragel的源代碼,看起來像ragel -D生成D1和ragel -E生成D2,雖然這在--help中沒有記錄!我試過了,得到了另一個錯誤,但現在得走了,所以再也看不到了...... –

+1

感謝ton @ AdamD.Ruppe!這是問題。我將向上遊提交關於'-E'的錯誤報告。如果您將重新發布您的評論作爲答案,我會接受它。 – Jordan

回答

2

你確定ragel正在生成D2代碼嗎?看起來它缺少const ....看着ragel的源代碼,看起來像ragel -D生成D1和ragel -E生成D2,雖然這在--help中沒有記錄!