簡體   English   中英

Ragel可以執行單獨的命令解析並相應地引發錯誤嗎

[英]Can Ragel perform individual command parsing and throw errors accordingly

我正在嘗試解析命令:LoadSdf 12 abc.ldf我正在嘗試在命令的每個階段獲取錯誤( :LoadSdf12abc.ldf )。 但是我得到了不同的行為,如問題的后面部分所示。

以下是我的拉格爾偽代碼

    %%
    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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM