-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
79 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { CommonToken, Lexer, CharStream, Token } from "antlr4ng"; | ||
import { BisonLexer } from './BisonLexer.js'; | ||
|
||
export default abstract class BisonLexerBase extends Lexer { | ||
percent_percent_count: number; | ||
|
||
constructor(input: CharStream) { | ||
super(input); | ||
this.percent_percent_count = 0; | ||
} | ||
|
||
reset() { | ||
this.percent_percent_count = 0; | ||
super.reset(); | ||
} | ||
|
||
NextMode() | ||
{ | ||
++this.percent_percent_count; | ||
if (this.percent_percent_count == 1) | ||
{ | ||
return; | ||
} else if (this.percent_percent_count == 2) | ||
{ | ||
this.pushMode(BisonLexer.EpilogueMode); | ||
return; | ||
} else | ||
{ | ||
this.type = BisonLexer.PercentPercent; | ||
return; | ||
} | ||
} | ||
} | ||
|
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,31 @@ | ||
"""The script transforms the grammar to fit for the c++ target """ | ||
import sys | ||
import re | ||
import shutil | ||
from glob import glob | ||
from pathlib import Path | ||
|
||
def main(): | ||
"""Executes the script.""" | ||
for file in glob("./*.g4"): | ||
transform_grammar(file) | ||
|
||
def transform_grammar(file_path): | ||
"""Transforms the grammar to fit for the target""" | ||
print("Altering " + file_path) | ||
if not Path(file_path).is_file: | ||
print(f"Could not find file: {file_path}") | ||
sys.exit(1) | ||
|
||
shutil.move(file_path, file_path + ".bak") | ||
with open(file_path + ".bak",'r', encoding="utf-8") as input_file: | ||
with open(file_path, 'w', encoding="utf-8") as output_file: | ||
for line in input_file: | ||
line = re.sub(r"(\/\/ Insert here @header for C\+\+ lexer\.)",\ | ||
'@header {import BisonLexerBase from "./BisonLexerBase.js"}', line) | ||
output_file.write(line) | ||
|
||
print("Writing ...") | ||
|
||
if __name__ == '__main__': | ||
main() |
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<desc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../_scripts/desc.xsd"> | ||
<targets>Cpp;CSharp;Dart;Go;Java;JavaScript;Python3</targets> | ||
<targets>Antlr4ng;Cpp;CSharp;Dart;Go;Java;JavaScript;Python3;TypeScript</targets> | ||
</desc> |