我在将 EBNF 语法转换为 Antlr4 语法时遇到问题
I am having trouble translating an EBNF grammar to an Antlr4 grammar
我有以下 EBNF 语法:
StringConstructor ::= "``[" StringConstructorContent "]``"
StringConstructorContent ::= StringConstructorChars (StringConstructorInterpolation StringConstructorChars)*
StringConstructorChars ::= (Char* - (Char* ('`{' | ']``') Char*))
StringConstructorInterpolation ::= "`{" Expr? "}`"
Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
我正在 xqDoc GitHub repository 的 Antlr4 中尝试以下操作:
XQueryParser.g4
stringConstructor: '`' '`' '[' stringConstructorContent ']' '`' '`' ;
stringConstructorContent: stringConstructorChars (stringConstructorInterpolation stringConstructorChars)* ;
stringConstructorChars: ( CHAR* ~ ( CHAR* (('`' '{') | (']' '`' '`')) CHAR* ) ) ;
stringConstructorInterpolation: '`' '{' expr '}' '`' ;
XQueryLexer.g4
CHAR: ( '\t' | '\n' | '\r' | '\u0020'..'\u0039' | '\u003B'..'\uD7FF' | '\uE000'..'\uFFFD' ) ;
用于解析以下内容:
for $s in ("one", "two", "red", "blue")
return ``[`{$s}` fish]``
并计算序列 ("one fish"、"two fish"、"red fish"、"blue fish")。
我收到以下错误:
error(50): :494:38: syntax error: missing RPAREN at '*' while looking for rule element
error(50): :494:70: syntax error: extraneous input ')' expecting SEMI while matching a rule
有没有人有解决这个问题的建议?我已经注释掉了那部分语法,以便它可以编译。
我最终创建了自己的 Antlr4 语法,而不是尝试自动将 EBNF 转换为 Antlr4。
我有以下 EBNF 语法:
StringConstructor ::= "``[" StringConstructorContent "]``"
StringConstructorContent ::= StringConstructorChars (StringConstructorInterpolation StringConstructorChars)*
StringConstructorChars ::= (Char* - (Char* ('`{' | ']``') Char*))
StringConstructorInterpolation ::= "`{" Expr? "}`"
Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
我正在 xqDoc GitHub repository 的 Antlr4 中尝试以下操作:
XQueryParser.g4
stringConstructor: '`' '`' '[' stringConstructorContent ']' '`' '`' ;
stringConstructorContent: stringConstructorChars (stringConstructorInterpolation stringConstructorChars)* ;
stringConstructorChars: ( CHAR* ~ ( CHAR* (('`' '{') | (']' '`' '`')) CHAR* ) ) ;
stringConstructorInterpolation: '`' '{' expr '}' '`' ;
XQueryLexer.g4
CHAR: ( '\t' | '\n' | '\r' | '\u0020'..'\u0039' | '\u003B'..'\uD7FF' | '\uE000'..'\uFFFD' ) ;
用于解析以下内容:
for $s in ("one", "two", "red", "blue")
return ``[`{$s}` fish]``
并计算序列 ("one fish"、"two fish"、"red fish"、"blue fish")。
我收到以下错误:
error(50): :494:38: syntax error: missing RPAREN at '*' while looking for rule element
error(50): :494:70: syntax error: extraneous input ')' expecting SEMI while matching a rule
有没有人有解决这个问题的建议?我已经注释掉了那部分语法,以便它可以编译。
我最终创建了自己的 Antlr4 语法,而不是尝试自动将 EBNF 转换为 Antlr4。