Ragel 可以执行单独的命令解析并相应地抛出错误吗

Can Ragel perform individual command parsing and throw errors accordingly

我正在尝试解析命令 :LoadSdf 12 abc.ldf 我试图在命令的每个阶段(:LoadSdf12abc.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 语法非常困难并且解释非常有限。如果对当前的案例有什么建议的话,会很有帮助。

在状态机的帮助下进行更多调试,我可以得出答案。 基本上 >! 仅可用于启动条件下的错误处理。

LOAD_CMD = ":LoadSdf" @!(cmd_error);
CHANNEL_NR = [digit]+ >!(channel_error);
FILENAME = [a-zA-Z0-9\.\-\_]+ $!(filename_error);
SPACE = ' ' >!(whitespace_error);