ANTLR 规则表达除这些之外的所有符号

发布于 2024-12-05 04:59:34 字数 643 浏览 1 评论 0原文

一个新手问题。比如说,我有一个词法分析器规则,简单地列出了所有可接受的符号:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

星軌x 2024-12-12 04:59:34

假设在您的 a 规则中,所有 ACCEPTED_SYMBOLS 字符均有效,但在规则 b 中,= 无效。

您可以使用 谓词 来执行此操作,如下所示:

a
  :  ACCEPTED_SYMBOLS
  ; 

b
  :  t=ACCEPTED_SYMBOLS {!$t.text.equals("=")}?
  ;

ACCEPTED_SYMBOLS
  :  '~'  | '!' | '@' | '#'  | '

请注意,只有单个引号和反斜杠需要在 ANTLR 语法中的文字字符串内转义。

或者,没有谓词:

a
  :  any
  ; 

b
  :  SYMBOLS
  ;

any
  :  SYMBOLS 
  |  EQ
  ;

SYMBOLS
  :  '~'  | '!' | '@' | '#'  | '

编辑

请注意,您不能按以下顺序定义规则:

ACCEPTED_SYMBOLS:   ('~' |'!' |'@' |'#' |'

ANTLR 将抛出一个错误,表示永远无法创建令牌ACCEPTED_SYMBOLS_EXCEPT_EQUAL,因为先前的规则已经匹配所有内容< code>ACCEPTED_SYMBOLS_EXCEPT_EQUAL 可以匹配。

如果您要切换规则:

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 标记。

您必须意识到词法分析器独立于解析器运行:它只是创建从上到下遍历词法分析器规则的标记,尝试尽可能多地匹配,并且它不关心解析器当时尝试匹配的内容。

|'%' |'^' |'-' |'+' | '\\'|':' |'"'|'\''|'<' |'>' |',' |'.' |'?' | '/' ) ; 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 all ACCEPTED_SYMBOLS chars are valid but inside rule b the = is not valid.

You could do this using a predicate like this:

a
  :  ACCEPTED_SYMBOLS
  ; 

b
  :  t=ACCEPTED_SYMBOLS {!$t.text.equals("=")}?
  ;

ACCEPTED_SYMBOLS
  :  '~'  | '!' | '@' | '#'  | '

Note that only single quote and backslashes need to be escaped inside a literal-string in an ANTLR grammar.

Or, without a predicate:

a
  :  any
  ; 

b
  :  SYMBOLS
  ;

any
  :  SYMBOLS 
  |  EQ
  ;

SYMBOLS
  :  '~'  | '!' | '@' | '#'  | '

EDIT

Note that you cannot define the rules in the following order:

ACCEPTED_SYMBOLS:   ('~' |'!' |'@' |'#' |'

ANTLR will throw an error that the token ACCEPTED_SYMBOLS_EXCEPT_EQUAL can never be created since prior rule(s) will already match everything ACCEPTED_SYMBOLS_EXCEPT_EQUAL can match.

And if you'd switch the rules:

ACCEPTED_SYMBOLS_EXCEPT_EQUAL: ('~' |'!' |'@' |'#' |'

then the rule ACCEPTED_SYMBOLS can only ever match a '='. All other characters will be tokenized as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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 everything ACCEPTED_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 as ACCEPTED_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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文