-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that every inline parser literal has its corresponding lexer rule
By following ANTLR's practice, every inline parser rule literal is converted into a lexer rule. Either by finding an approrpiate existing lexer rule or by artificially creating one and assigning its reference to the literal usage.
- Loading branch information
1 parent
e376875
commit 1980d9e
Showing
3 changed files
with
69 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (c) 2023 Renata Hodovan, Akos Kiss. | ||
# | ||
# Licensed under the BSD 3-Clause License | ||
# <LICENSE.rst or https://opensource.org/licenses/BSD-3-Clause>. | ||
# This file may not be copied, modified, or distributed except | ||
# according to those terms. | ||
|
||
# This custom unparser is used by ImplicitLiteral.g4 | ||
|
||
from ImplicitLiteralGenerator import ImplicitLiteralGenerator | ||
|
||
|
||
class CustomImplicitLiteralGenerator(ImplicitLiteralGenerator): | ||
|
||
def HELLO(self, parent=None): | ||
super().HELLO(parent=parent) | ||
self.hello_called = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (c) 2023 Renata Hodovan, Akos Kiss. | ||
* | ||
* Licensed under the BSD 3-Clause License | ||
* <LICENSE.rst or https://opensource.org/licenses/BSD-3-Clause>. | ||
* This file may not be copied, modified, or distributed except | ||
* according to those terms. | ||
*/ | ||
|
||
/* | ||
* Tests handling of implicit literals in parser rules. | ||
*/ | ||
|
||
// TEST-PROCESS: {grammar}.g4 -o {tmpdir} | ||
// TEST-GENERATE: Custom{grammar}Generator.Custom{grammar}Generator -r start -j 1 -o {tmpdir}/{grammar}%d.txt | ||
|
||
|
||
grammar ImplicitLiteral; | ||
|
||
@members { | ||
def __init__(self, *, model=None, listeners=None, max_depth=inf): | ||
super().__init__(model=model, listeners=listeners, max_depth=max_depth) | ||
self.hello_called = False | ||
} | ||
|
||
|
||
start : 'hello' {assert self.hello_called, "Implicit lexer rule was not called."}; | ||
HELLO : 'hello' ; |