parsing - Rascal:解析具有多个 "_"s 的字符串

标签 parsing syntax-error dsl rascal

我尝试解析包含多个“_”的字符串,但出现 CallFailed 异常。

我试图创建一个尽可能小的问题语法示例。

layout Layout = WhitespaceAndComment* !>> [\ \t\n\r#];
lexical WhitespaceAndComment = [\ \t\n\r] | @category="Comment" "#" ![\n]* $;

syntax SourceList = sourceList: "$"? "{"? Id sourceFile "}"?;
lexical Id = ([a-zA-Z/.\-][a-zA-Z0-9_/.]* !>> [a-zA-Z0-9_/.]) \ Reserved;
keyword Reserved = 
"$" | "{" | "}" ; 

我无法解析这个小例子。
rascal>try { parse(#SourceList, "test"); } catch CallFailed(m, e): println("<m> : <e>");
|prompt:///|(25,9,<1,25>,<1,34>) : [type(sort("SourceList"),(sort("SourceList"):choice(sort("SourceList"),{prod(label("sourceList",sort("SourceList")),[opt(lit("$")),layouts("$default$"),opt(lit("{")),layouts("$default$"),label("sourceFile",lex("Id")),layouts("$default$"),opt(lit("}"))],{})}),layouts("$default$"):choice(layouts("$default$"),{prod(layouts("$default$"),[],{})}),empty():choice(empty(),{prod(empty(),[],{})}),lex("Id"):choice(lex("Id"),{prod(lex("Id"),[conditional(seq([\char-class([range(45,47),range(65,90),range(97,122)]),conditional(\iter-star(\char-class([range(46,57),range(65,90),range(95,95),range(97,122)])),{\not-follow(\char-class([range(46,57),range(65,90),range(95,95),range(97,122)]))})]),{delete(keywords("Reserved"))})],{})}),keywords("Reserved"):choice(keywords("Reserved"),{prod(keywords("Reserved"),[lit("$")],{}),prod(keywords("Reserved"),[lit("}")],{}),prod(keywords("Reserved"),[lit("{")],{})}))),"${test}"]
ok

从“test”更改为“${test}”的源文件会给出完全相同的输出。

嵌入 SourceList 的完整语法有更多规则。但后来我得到以下结果。
set(${TARGET_NAME}_DEPS
    GenConfiguration_OBJ_TN_Common # accept
    ${COMMON_BB_PCMDEPS}  # reject
    COMMON_BB_PCMDEPS # accept
    COMMON_BB_PCM_DEPS # reject
)

我想有一个解决方案。

最小的例子有什么问题?为什么 test 或 ${test} 不被接受?

顺便说一句:我正在使用最新的不稳定。安装和尝试稳定版本有意义吗?

最佳答案

我试图重现您的问题,但它似乎在这里工作:

rascal>parse(#SourceList, "test")
SourceList: (SourceList) `test`

不稳定版本目前很好。事实上,现在是发布稳定版本的时候了。所以现在你最好使用不稳定的版本。
CallFailed异常令人困惑。这意味着调用了一个无法匹配或找不到的函数。所以也许 parse不导入 ParseTree 不在范围内, 或者你有一个不同的函数叫做 parse没有 type[Tree]str作为范围内的预期参数。只要导入 ParseTree 模块,就会调用 parse应该没事。

如果您取得了进展,请告诉我。也许重新启动 Eclipse 也可能会清除一些问题。

关于parsing - Rascal:解析具有多个 "_"s 的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56578332/

相关文章:

javascript - 解析 URL 参数并返回带有数组的 javascript 对象

python - 与 python 无关的应用程序输出奇怪的错误消息 : SyntaxError: invalid syntax

java - 使用特定的 "Root"对象在 Java 中执行 Groovy 脚本

scala - 使用Elastic4s进行GeoDistance查询

parsing - 具有存在量化的解析器的类型签名

parsing - 解析器错误消息 : The server tag is not well formed

Java:如何向每个数组项添加文本?

oracle - pl/sql中数字的阶乘

java - 错误: incompatible types Object Could not be converted [ArrayList]

python - 如何调用 python 声明属性模式