Skip to content

Commit c54f57f

Browse files
committed
antlr postprocessor: replace Generated from abs path with relative path
1 parent 40b7f90 commit c54f57f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

graalpython/com.oracle.graal.python.parser.antlr/postprocess.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"""
7777

7878
PTRN_SUPPRESS_WARNINGS = re.compile(r"@SuppressWarnings.*")
79+
PTRN_GEN_FROM = r"// Generated from .*(?P<path>graalpython/com\.oracle\.graal\.python.*Python3\.g4) by ANTLR (?P<antlr>.*)"
7980

8081

8182
def replace_suppress_warnings(line):
@@ -85,13 +86,20 @@ def replace_suppress_warnings(line):
8586
def replace_rulectx(line):
8687
return line.replace("(RuleContext)_localctx", "_localctx")
8788

89+
8890
def replace_localctx(line):
8991
return re.sub(r'\(\((([a-zA-Z]*?_?)*[a-zA-Z]*)\)_localctx\)', '_localctx', line)
9092

93+
94+
def replace_generate_from(line):
95+
return re.sub(PTRN_GEN_FROM, "// Generated from \g<path> by ANTLR \g<antlr>", line)
96+
97+
9198
TRANSFORMS = [
9299
replace_suppress_warnings,
93100
replace_rulectx,
94101
replace_localctx,
102+
replace_generate_from,
95103
]
96104

97105

0 commit comments

Comments
 (0)