带有空字符的字符串

问题描述 投票:0回答:1

假设我们有两个词汇定义:

  lexical DQChr = ![\"] | [\"][\"];
  lexical String = "\"" DQChr* "\"";

那么下面的案例就很好解析了:

  parse(#String,"\"a\"");
  parse(#String,"\"\u0001\"");

但是,空字符会给出解析错误:

  parse(#String,"\u0000");

如何在引用的字符串中允许空字符?

rascal null-character
1个回答
0
投票

看来你可以将

\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) `""`

© www.soinside.com 2019 - 2024. All rights reserved.