是否有一种方法可以这样做,使案件敏感性不是一个“全部或无”的选择?
lexer grammar TestLexer;
options { caseInsensitive=true; } // ok, but it's not supported in the VS Code editor ??
BOOL: (TRUE|FALSE);
// I want these two keywords to be case-insensitive
TRUE: 'true'; // true, True, TRUE, ...
FALSE: 'false'; // false, False, FALSE, ...
options { caseInsensitive=false; } // ok, but it's not supported in the VS Code editor ??
// This keyword must only match exact case
YIELD: 'yield'; // 'yield' ONLY如果没有,有什么可能做到这一点呢?我以前看到的--在我看来是最糟糕的选择--就是做这样的事情:
TRUE: T R U E // case-insensitive
YIELD: 'yield' // case-sensitive发布于 2022-08-11 01:39:09
基于文档这里,您似乎可以根据规则设置caseInsensitivity。
给出的例子如下:
options { caseInsensitive=true; }
STRING options { caseInsensitive=false; } : 'N'? '\'' (~'\'' | '\'\'')* '\''; // lower n is not allowed发布于 2022-08-11 19:06:43
从迈克的回答来看,这是对我有用的:
lexer grammar TestLexer;
options { caseInsensitive=true; }
BOOL: (TRUE|FALSE);
// I want these two keywords to be case-insensitive
TRUE: 'true';
FALSE: 'false';
// This keyword must only match exact case
YIELD options { caseInsensitive=false; }: 'yield';parser grammar TestParser;
options { tokenVocab = TestLexer; }
program
: statement EOF
;
statement
: YIELD SPACE BOOL
;换句话说,将options设置在顶部使其成为默认设置,除非它通过使用表单来覆盖特定的令牌:
TOKEN opens { caseInsensitive=true|false; }
: VALUE
;https://stackoverflow.com/questions/73313658
复制相似问题