Skip to content

Commit

Permalink
antlr4 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed Jul 20, 2024
1 parent f67ad82 commit 1e80738
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
14 changes: 5 additions & 9 deletions pya2l/classes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__copyright__ = """
pySART - Simplified AUTOSAR-Toolkit for Python.
Expand All @@ -25,8 +24,6 @@

from collections import namedtuple

import six

from pya2l.utils import SingletonBase


Expand All @@ -36,11 +33,11 @@ def camel_case(name, upper_first=True):
result.append(splitty[0])
if len(splitty) > 1:
for part in splitty[1:]:
xxx = "{0}{1}".format(part[0].upper(), part[1:])
xxx = f"{part[0].upper()}{part[1:]}"
result.append(xxx)
result = "".join(result)
if upper_first:
result = "{}{}".format(result[0].upper(), result[1:])
result = f"{result[0].upper()}{result[1:]}"
return result


Expand Down Expand Up @@ -165,8 +162,7 @@ def getClass(metacls, name):
return result


@six.add_metaclass(KeywordType)
class Keyword(object):
class Keyword(metaclass=KeywordType):

multiple = False
block = False
Expand All @@ -180,7 +176,7 @@ def attributeNames(cls):
return [attr[1] for attr in cls.attrs if MULTIPLE not in attr]

def __str__(self):
return "< %s @%0X >" % (self.__class__.__name__, id(self))
return f"< {self.__class__.__name__} @{id(self):0X} >"

@classmethod
def class_name(cls):
Expand Down Expand Up @@ -2073,7 +2069,7 @@ class RootElement(Keyword):
}


class A2LElement(object):
class A2LElement:
def __str__(self):
result = []
result.append("%s {" % self.__class__.__name__)
Expand Down
18 changes: 10 additions & 8 deletions pya2l/parserlib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__copyright__ = """
pySART - Simplified AUTOSAR-Toolkit for Python.
Expand Down Expand Up @@ -27,20 +26,22 @@
__author__ = "Christoph Schueler"
__version__ = "0.1.0"

from collections import namedtuple
import importlib
import sys

import antlr4
from antlr4.error.ErrorListener import ErrorListener
from antlr4.atn.ParserATNSimulator import ParserATNSimulator
from collections import namedtuple

from pya2l import model


# import antlr4
# from antlr4.error.ErrorListener import ErrorListener
# from antlr4.atn.ParserATNSimulator import ParserATNSimulator


ResultType = namedtuple("ResultType", "db listener_result")


'''
class MyErrorListener(ErrorListener):
""" """
Expand All @@ -58,6 +59,7 @@ def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e):
)
else:
print("line " + str(line) + ":" + str(column) + " " + msg, file=sys.stderr)
'''


class ParserWrapper:
Expand All @@ -82,8 +84,8 @@ def __init__(
self.listener = listener

def _load(self, name):
className = "{0}{1}".format(self.grammarName, name)
moduleName = "pya2l.{0}".format(className)
className = f"{self.grammarName}{name}"
moduleName = f"pya2l.{className}"
module = importlib.import_module(moduleName)
klass = getattr(module, className)
return (
Expand Down
10 changes: 6 additions & 4 deletions pya2l/parsers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__copyright__ = """
pySART - Simplified AUTOSAR-Toolkit for Python.
Expand All @@ -26,10 +25,13 @@
"""
__author__ = "Christoph Schueler"

from pya2l.aml.listener import AMLListener
from pya2l.parserlib import ParserWrapper
from pya2l.a2lparser import A2LParser
from pya2l.if_data_parser import IfDataParser

# from pya2l.aml.listener import AMLListener
from pya2l.parserlib import ParserWrapper


# from pya2l.if_data_parser import IfDataParser


def aml(debug: bool = False, prepro_result=None):
Expand Down

0 comments on commit 1e80738

Please sign in to comment.