0
我試圖解析命令:LoadSdf 12 abc.ldf
我想在命令的每個階段(:LoadSdf
,12
,abc.ldf
)來獲取錯誤。 但是我得到了不同的問題,如問題的後面部分所示。燦Ragel執行各個命令解析和拋出錯誤相應
以下是我Ragel僞代碼
%%
machine ldf;
LOAD_CMD = ":LoadSdf" $!(cmd_error);
CHANNEL_NR = [digit]+ $!(channel_error);
FILENAME = [a-zA-Z0-9\.\-\_]+ $!(filename_error);
SPACE = ' ';
main:= (LOAD_CMD.SPACE+.CHANNEL_NR.SPACE.FILENAME) %/job_done;
%%
預期輸出:
./a.out ":Load"
incorrect command //corresponding actions contain these error messages
./a.out ":LoadSdf"
whitespace missing //corresponding actions contain these error messages
./a.out ":LoadSdf "
channel number missing //corresponding actions contain these error messages
./a.out ":LoadSdf 12 "
file name missing //corresponding actions contain these error messages
./a.out ":LoadSdf 12 abc.ldf"
parsing success //corresponding actions contain these messages
觀察輸出:
./a.out ":Load"
incorrect command
./a.out ":LoadSdf"
whitespace missing
./a.out ":LoadSdf "
whitespace missing
channel number missing
./a.out ":LoadSdf 12 "
whitespace missing
file name missing
./a.out ":LoadSdf 12"
channel number missing
./a.out ":LoadSdf 12 abc.ldf"
parsing success
用於錯誤處理的Ragel語法是相當困難的,非常有限地解釋。如果提供有關當前案件的任何建議,這將會非常有幫助。