我试图解析一个命令:LoadSdf 12 abc.ldf
,我试图在命令的每个阶段(,,,:LoadSdf
)12
得到错误abc.ldf
。但是我得到了不同的行为,如问题的后面部分所示。
以下是我的 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 语法非常困难并且解释非常有限。如果对当前案例提供任何建议,将有很大帮助。