Steven Klusener
Steven Klusener

Reputation: 159

String with null-character

Suppose we have the two lexical definitions:

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

Then the following cases parse well:

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

However, the null-character gives a parse error:

  parse(#String,"\u0000");

How can I allow a null-character in my quoted string?

Upvotes: 2

Views: 63

Answers (1)

Marijn
Marijn

Reputation: 1915

It seems you can just add \u0000 to the regex:

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

Upvotes: 1

Related Questions