ANTLR 规则表达除这些之外的所有符号
一个新手问题。比如说,我有一个词法分析器规则,简单地列出了所有可接受的符号:
ACCEPTED_SYMBOLS: ('~' |'!' |'@' |'#' |'$' |'%' |'^' |'\-' |'\+' | '=' |
'\\'|':' |'\"'|'\''|'<' |'>' |',' |'.' |'?' | '/' ) ;
但有时我想要另一个规则来接受除“=”之外的所有符号,
ACCEPTED_SYMBOLS_EXCEPT_EQUAL: ('~' |'!' |'@' |'#' |'$' |'%' |'^' |'\-' |'\+' |
'\\'|':' |'\"'|'\''|'<' |'>' |',' |'.' |'?' | '/' ) ;
基本上我只是重复不带“=”的列表。
但这听起来像是一种愚蠢的定义标记的方法。如果我得到另一个 ACCEPTED_SYMBOLS_EXCEPT_HASH/COLON/等等怎么办?
是否可以编写一个解析器规则来根据 ACCEPTED_SYMBOLS 派生匹配符号?语义谓词听起来像是一个选择,但我是 ANTLR 的新手,不知道如何使用它。
A newbie question. Say, I have a lexer rule simply listing all acceptable symbols :
ACCEPTED_SYMBOLS: ('~' |'!' |'@' |'#' |'
But sometimes I want another rule that accepts all symbols except, say, the '='
ACCEPTED_SYMBOLS_EXCEPT_EQUAL: ('~' |'!' |'@' |'#' |'
Basically i just repeat the list without '='.
But this sounds like a stupid way to define tokens. What if I got another ACCEPTED_SYMBOLS_EXCEPT_HASH/COLON/etc.
Is it possible to write a parser rule that derives the matching symbols based on ACCEPTED_SYMBOLS? Semantic predicate sounds like the choice but I am new to ANTLR and don't know how to use it.
|'%' |'^' |'\-' |'\+' | '=' |
'\\'|':' |'\"'|'\''|'<' |'>' |',' |'.' |'?' | '/' ) ;
But sometimes I want another rule that accepts all symbols except, say, the '='
Basically i just repeat the list without '='.
But this sounds like a stupid way to define tokens. What if I got another ACCEPTED_SYMBOLS_EXCEPT_HASH/COLON/etc.
Is it possible to write a parser rule that derives the matching symbols based on ACCEPTED_SYMBOLS? Semantic predicate sounds like the choice but I am new to ANTLR and don't know how to use it.
|'%' |'^' |'\-' |'\+' |
'\\'|':' |'\"'|'\''|'<' |'>' |',' |'.' |'?' | '/' ) ;
Basically i just repeat the list without '='.
But this sounds like a stupid way to define tokens. What if I got another ACCEPTED_SYMBOLS_EXCEPT_HASH/COLON/etc.
Is it possible to write a parser rule that derives the matching symbols based on ACCEPTED_SYMBOLS? Semantic predicate sounds like the choice but I am new to ANTLR and don't know how to use it.
|'%' |'^' |'\-' |'\+' | '=' | '\\'|':' |'\"'|'\''|'<' |'>' |',' |'.' |'?' | '/' ) ;But sometimes I want another rule that accepts all symbols except, say, the '='
Basically i just repeat the list without '='.
But this sounds like a stupid way to define tokens. What if I got another ACCEPTED_SYMBOLS_EXCEPT_HASH/COLON/etc.
Is it possible to write a parser rule that derives the matching symbols based on ACCEPTED_SYMBOLS? Semantic predicate sounds like the choice but I am new to ANTLR and don't know how to use it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设在您的
a
规则中,所有ACCEPTED_SYMBOLS
字符均有效,但在规则b
中,=
无效。您可以使用 谓词 来执行此操作,如下所示:
请注意,只有单个引号和反斜杠需要在 ANTLR 语法中的文字字符串内转义。
或者,没有谓词:
编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ; EQ : '=' ;编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;请注意,只有单个引号和反斜杠需要在 ANTLR 语法中的文字字符串内转义。
或者,没有谓词:
编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
|'%' |'^' |'-' |'+' | '\\'|':' |'"'|'\''|'<' |'>' |',' |'.' |'?' | '/' ) ;ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;请注意,只有单个引号和反斜杠需要在 ANTLR 语法中的文字字符串内转义。
或者,没有谓词:
编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ; EQ : '=' ;编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;请注意,只有单个引号和反斜杠需要在 ANTLR 语法中的文字字符串内转义。
或者,没有谓词:
编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
|'%' |'^' |'-' |'+' | '\\'|':' |'"'|'\''|'<' |'>' |',' |'.' |'?' | '/' ) ; ACCEPTED_SYMBOLS: ('~' |'!' |'@' |'#' |'那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;请注意,只有单个引号和反斜杠需要在 ANTLR 语法中的文字字符串内转义。
或者,没有谓词:
编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ; EQ : '=' ;编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;请注意,只有单个引号和反斜杠需要在 ANTLR 语法中的文字字符串内转义。
或者,没有谓词:
编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
|'%' |'^' |'-' |'+' | '=' | '\\'|':' |'"'|'\''|'<' |'>' |',' |'.' |'?' | '/' ) ; ACCEPTED_SYMBOLS_EXCEPT_EQUAL: ('~' |'!' |'@' |'#' |'ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;请注意,只有单个引号和反斜杠需要在 ANTLR 语法中的文字字符串内转义。
或者,没有谓词:
编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ; EQ : '=' ;编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;请注意,只有单个引号和反斜杠需要在 ANTLR 语法中的文字字符串内转义。
或者,没有谓词:
编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
|'%' |'^' |'-' |'+' | '\\'|':' |'"'|'\''|'<' |'>' |',' |'.' |'?' | '/' ) ;ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;请注意,只有单个引号和反斜杠需要在 ANTLR 语法中的文字字符串内转义。
或者,没有谓词:
编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ; EQ : '=' ;编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;请注意,只有单个引号和反斜杠需要在 ANTLR 语法中的文字字符串内转义。
或者,没有谓词:
编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
|'%' |'^' |'-' |'+' | '=' | '\\'|':' |'"'|'\''|'<' |'>' |',' |'.' |'?' | '/' ) ;那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;请注意,只有单个引号和反斜杠需要在 ANTLR 语法中的文字字符串内转义。
或者,没有谓词:
编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ; EQ : '=' ;编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;请注意,只有单个引号和反斜杠需要在 ANTLR 语法中的文字字符串内转义。
或者,没有谓词:
编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
|'%' |'^' |'-' |'+' | '=' | '\\'|':' |'"'|'\''|'<' |'>' |',' |'.' |'?' | '/' ) ; ACCEPTED_SYMBOLS_EXCEPT_EQUAL: ('~' |'!' |'@' |'#' |'ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;请注意,只有单个引号和反斜杠需要在 ANTLR 语法中的文字字符串内转义。
或者,没有谓词:
编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ; EQ : '=' ;编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;请注意,只有单个引号和反斜杠需要在 ANTLR 语法中的文字字符串内转义。
或者,没有谓词:
编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
|'%' |'^' |'-' |'+' | '\\'|':' |'"'|'\''|'<' |'>' |',' |'.' |'?' | '/' ) ;ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;请注意,只有单个引号和反斜杠需要在 ANTLR 语法中的文字字符串内转义。
或者,没有谓词:
编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ; EQ : '=' ;编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;请注意,只有单个引号和反斜杠需要在 ANTLR 语法中的文字字符串内转义。
或者,没有谓词:
编辑
请注意,您不能按以下顺序定义规则:
ANTLR 将抛出一个错误,表示永远无法创建令牌
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。如果您要切换规则:
那么规则
ACCEPTED_SYMBOLS
只能匹配'='
。所有其他字符将被标记为ACCEPTED_SYMBOLS_EXCEPT_EQUAL
标记。您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。
Let's say inside your
a
rule allACCEPTED_SYMBOLS
chars are valid but inside ruleb
the=
is not valid.You could do this using a predicate like this:
Note that only single quote and backslashes need to be escaped inside a literal-string in an ANTLR grammar.
Or, without a predicate:
EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ; EQ : '=' ;EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;Note that only single quote and backslashes need to be escaped inside a literal-string in an ANTLR grammar.
Or, without a predicate:
EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
|'%' |'^' |'-' |'+' | '\\'|':' |'"'|'\''|'<' |'>' |',' |'.' |'?' | '/' ) ;ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;Note that only single quote and backslashes need to be escaped inside a literal-string in an ANTLR grammar.
Or, without a predicate:
EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ; EQ : '=' ;EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;Note that only single quote and backslashes need to be escaped inside a literal-string in an ANTLR grammar.
Or, without a predicate:
EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
|'%' |'^' |'-' |'+' | '\\'|':' |'"'|'\''|'<' |'>' |',' |'.' |'?' | '/' ) ; ACCEPTED_SYMBOLS: ('~' |'!' |'@' |'#' |'then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;Note that only single quote and backslashes need to be escaped inside a literal-string in an ANTLR grammar.
Or, without a predicate:
EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ; EQ : '=' ;EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;Note that only single quote and backslashes need to be escaped inside a literal-string in an ANTLR grammar.
Or, without a predicate:
EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
|'%' |'^' |'-' |'+' | '=' | '\\'|':' |'"'|'\''|'<' |'>' |',' |'.' |'?' | '/' ) ; ACCEPTED_SYMBOLS_EXCEPT_EQUAL: ('~' |'!' |'@' |'#' |'ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;Note that only single quote and backslashes need to be escaped inside a literal-string in an ANTLR grammar.
Or, without a predicate:
EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ; EQ : '=' ;EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;Note that only single quote and backslashes need to be escaped inside a literal-string in an ANTLR grammar.
Or, without a predicate:
EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
|'%' |'^' |'-' |'+' | '\\'|':' |'"'|'\''|'<' |'>' |',' |'.' |'?' | '/' ) ;ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;Note that only single quote and backslashes need to be escaped inside a literal-string in an ANTLR grammar.
Or, without a predicate:
EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ; EQ : '=' ;EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;Note that only single quote and backslashes need to be escaped inside a literal-string in an ANTLR grammar.
Or, without a predicate:
EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
|'%' |'^' |'-' |'+' | '=' | '\\'|':' |'"'|'\''|'<' |'>' |',' |'.' |'?' | '/' ) ;then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;Note that only single quote and backslashes need to be escaped inside a literal-string in an ANTLR grammar.
Or, without a predicate:
EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ; EQ : '=' ;EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;Note that only single quote and backslashes need to be escaped inside a literal-string in an ANTLR grammar.
Or, without a predicate:
EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
|'%' |'^' |'-' |'+' | '=' | '\\'|':' |'"'|'\''|'<' |'>' |',' |'.' |'?' | '/' ) ; ACCEPTED_SYMBOLS_EXCEPT_EQUAL: ('~' |'!' |'@' |'#' |'ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;Note that only single quote and backslashes need to be escaped inside a literal-string in an ANTLR grammar.
Or, without a predicate:
EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ; EQ : '=' ;EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;Note that only single quote and backslashes need to be escaped inside a literal-string in an ANTLR grammar.
Or, without a predicate:
EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
|'%' |'^' |'-' |'+' | '\\'|':' |'"'|'\''|'<' |'>' |',' |'.' |'?' | '/' ) ;ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;Note that only single quote and backslashes need to be escaped inside a literal-string in an ANTLR grammar.
Or, without a predicate:
EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ; EQ : '=' ;EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.
| '%' | '^' | '-' | '+' | '=' | '\\' | ':' | '"' | '\'' | '<' | '>' | ',' | '.' | '?' | '/' ;Note that only single quote and backslashes need to be escaped inside a literal-string in an ANTLR grammar.
Or, without a predicate:
EDIT
Note that you cannot define the rules in the following order:
ANTLR will throw an error that the token
ACCEPTED_SYMBOLS_EXCEPT_EQUAL
can never be created since prior rule(s) will already match everythingACCEPTED_SYMBOLS_EXCEPT_EQUAL
can match.And if you'd switch the rules:
then the rule
ACCEPTED_SYMBOLS
can only ever match a'='
. All other characters will be tokenized asACCEPTED_SYMBOLS_EXCEPT_EQUAL
tokens.You must realize that the lexer operates independently from the parser: it simply creates tokens going through the lexer rules from top to bottom, trying to match as much as possible, and it does not care what the parser at that time is trying to match.