【发布时间】:2021-06-27 19:13:04
【问题描述】:
这个 Packcc 语法只是一个字符串字面量的列表。当发现语法错误时,即使错误出现在文件的最后一项,也会跳过操作。 这是一个问题,因为我想在空间解析期间计算行/列位置。
%source {
#include <stdio.h>
#include <stdlib.h>
}
line <-
list _ EOL
list <-
list _ ',' _ string
/ _ string
string <-
'"' ~{puts("unopened string");} (!'"' !EOL .)* '"'
# The error action here is not skipped
_ <-
[ \t]* {puts("_ match");}
# This action doesn't happens if there is an error. In my real project the cursor location is computed here.
EOL <-
('\n'
/ '\r\n'
/ '\r' )
%%
int main(void)
{
pcc_context_t* ctx = pcc_create(NULL);
while(pcc_parse(ctx, NULL));
pcc_destroy(ctx);
return 0;
}
测试文件“test.txt”只包含
"a", "b", c"
使用packcc theAboveFile.peg 创建解析器
然后编译生成的 .c 文件,然后使用管道将其运行到测试文件,如下所示./a.out < test.txt
如您所见,最后一个字符串中有错误,但我无法执行操作来计算行/列位置,因为由于某种原因跳过了这些操作。
【问题讨论】:
-
Ploum:请使用您正在使用的解析器生成器的标签(在本例中为packcc)标记解析问题,而不是依赖社区为您完成。谢谢。