假设我们有两个词汇定义:
lexical DQChr = ![\"] | [\"][\"];
lexical String = "\"" DQChr* "\"";
那么下面的案例就很好解析了:
parse(#String,"\"a\"");
parse(#String,"\"\u0001\"");
但是,空字符会给出解析错误:
parse(#String,"\u0000");
如何在引用的字符串中允许空字符?
看来你可以将
\u0000
添加到正则表达式中:
Version: 0.28.2
rascal>lexical DQChr = ([\u0000] | ![\"]) | [\"][\"];
ok
rascal>lexical String = "\"" DQChr* "\"";
ok
rascal>parse(#String,"\"a\"");
String: (String) `"a"`
rascal>parse(#String,"\"\u0001\"");
String: (String) `""`
rascal>parse(#String,"\"\u0000\"");
String: (String) `""`