Skip to content
33 changes: 33 additions & 0 deletions rust/CSharp/transformGrammar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import sys, os, re, shutil
from glob import glob
from pathlib import Path

def main(argv):
for file in glob("*.g4"):
fix(file)

def fix(file_path):
print("Altering " + file_path)
if not os.path.exists(file_path):
print(f"Could not find file: {file_path}")
sys.exit(1)
parts = os.path.split(file_path)
file_name = parts[-1]

shutil.move(file_path, file_path + ".bak")
input_file = open(file_path + ".bak",'r')
output_file = open(file_path, 'w')
for x in input_file:
if 'this._input' in x:
x = x.replace("this._input", "this.InputStream")


output_file.write(x)
output_file.flush()

print("Writing ...")
input_file.close()
output_file.close()

if __name__ == '__main__':
main(sys.argv)
4 changes: 3 additions & 1 deletion rust/RustLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ OUTER_BLOCK_DOC:

BLOCK_COMMENT_OR_DOC: ( BLOCK_COMMENT | INNER_BLOCK_DOC | OUTER_BLOCK_DOC) -> channel (HIDDEN);

SHEBANG: {this.SOF()}? '\ufeff'? '#!' ~[\r\n]* -> channel(HIDDEN);
SHEBANG: {this.SOF()}? '\ufeff'? '#!' {this._input.LA(1) != 97}? ~[\r\n]* -> channel(HIDDEN);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly speaking, this is not "target agnostic" (#4286 (comment)) because != is a target-specific operator. The entire expression should go in a base class, which is already done for both lexer and parser. Please add a "is...()" method, reference that here, and implement the methods for each of the targets.

// Shebang not in first line and #! cannot be followed by a '[' character shebang


//ISOLATED_CR
// : '\r' {_input.LA(1)!='\n'}// not followed with \n ;
Expand Down