部分跳过ANTLR4中的字符
我试图匹配以下短语:部分跳过ANTLR4中的字符,antlr,Antlr,我试图匹配以下短语: <svg/onload="alert(1);"> 错误是 error(133): HTML.g4:35:11: ->command in lexer rule Attribute must be last element of single outermost alt 有什么想法吗?错误消息几乎可以告诉您问题所在。skip命令必须位于规则末尾。不能跳过中间标记,只能跳过整个规则 然而,我想知道你为什么要跳过斜杠。为什么不让lexer扫描所有东西(无论
<svg/onload="alert(1);">
错误是
error(133): HTML.g4:35:11: ->command in lexer rule Attribute must be last element of single outermost alt
有什么想法吗?错误消息几乎可以告诉您问题所在。
skip
命令必须位于规则末尾。不能跳过中间标记,只能跳过整个规则
然而,我想知道你为什么要跳过斜杠。为什么不让lexer扫描所有东西(无论如何它必须扫描),然后忽略你不需要的标记呢?另外,我不会使用lexer规则,而是使用解析器规则来允许元素之间的任意空格。尝试lexer的setText(getText().replace(“/”,“”))
或任何其他匹配的字符串操作
Attribute
: ('/' -> skip) Identifier '=' StringLiteral?
;
error(133): HTML.g4:35:11: ->command in lexer rule Attribute must be last element of single outermost alt