【发布时间】:2019-10-27 22:05:01
【问题描述】:
我尝试解析包含多个“_”的字符串,但出现 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}?
顺便说一句:我正在使用最新的不稳定。安装和试用稳定版有意义吗?
【问题讨论】:
标签: parsing syntax-error dsl rascal