Skip to content

Commit

Permalink
Add Python3 port. Does not work yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaby76 committed Jul 17, 2023
1 parent c2937fc commit 4af3d3c
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
29 changes: 29 additions & 0 deletions cpp/Python3/CPP14ParserBase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

from antlr4 import *

relativeImport = False
if __name__ is not None and "." in __name__:
relativeImport = True

class CPP14ParserBase(Parser):
@staticmethod
def parser():
if relativeImport:
from .CPP14Parser import CPP14Parser
else:
from CPP14Parser import CPP14Parser
return CPP14Parser

def IsPureSpecifierAllowed(self) -> bool:
try:
x = self.Context # memberDeclarator
c = x.get_child(0).get_child(0)
c2 = c.get_child(0)
p = c2.get_child(1)
if p is None:
return False
return isinstance(p, CPP14Parser.ParametersAndQualifiersContext)
except:
pass
return False

33 changes: 33 additions & 0 deletions cpp/Python3/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.' in x:
x = x.replace('this.', 'self.')
if '!this.' in x:
x = x.replace('!this.', 'not self.')
output_file.write(x)
output_file.flush()

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

if __name__ == '__main__':
main(sys.argv)
2 changes: 1 addition & 1 deletion cpp/desc.xml
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;Java;JavaScript</targets>
<targets>Cpp;CSharp;Dart;Java;JavaScript;Python3</targets>
</desc>

0 comments on commit 4af3d3c

Please sign in to comment.