Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
部分跳过ANTLR4中的字符_Antlr - Fatal编程技术网

部分跳过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