【发布时间】:2018-02-18 09:27:23
【问题描述】:
我正在尝试更新遵循以下规范的 ANTLR 语法
https://github.com/facebook/graphql/pull/327/files
在逻辑上它定义为
StringValue ::
- `"` StringCharacter* `"`
- `"""` MultiLineStringCharacter* `"""`
StringCharacter ::
- SourceCharacter but not `"` or \ or LineTerminator
- \u EscapedUnicode
- \ EscapedCharacter
MultiLineStringCharacter ::
- SourceCharacter but not `"""` or `\"""`
- `\"""`
(不是上面的逻辑 - 不是 ANTLR 语法)
我在 ANTRL 4 中尝试了以下操作,但它无法识别三引号字符串中超过 1 个字符
string : triplequotedstring | StringValue ;
triplequotedstring: '"""' triplequotedstringpart? '"""';
triplequotedstringpart : EscapedTripleQuote* | SourceCharacter*;
EscapedTripleQuote : '\\"""';
SourceCharacter :[\u0009\u000A\u000D\u0020-\uFFFF];
StringValue: '"' (~(["\\\n\r\u2028\u2029])|EscapedChar)* '"';
使用这些规则,它会识别 '"""a"""' 但只要我添加更多字符,它就会失败
eg: '"""abc"""' 不会解析,ANTLR 的 IntelliJ 插件说
line 1:14 extraneous input 'abc' expecting {'"""', '\\"""', SourceCharacter}
如何在 ANTLR 中使用 '\"""' 转义三引号字符串?
【问题讨论】:
标签: java antlr antlr4 graphql graphql-java