Skip to content

Commit

Permalink
Fix parser
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed Jan 17, 2019
1 parent 9e7cc49 commit bdbd317
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
15 changes: 15 additions & 0 deletions pydbc/db/load/dbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@
from pydbc.types import AttributeType, ValueType, CategoryType
from .base import BaseLoader

"""
FIBEX elements CANdb object type
---------------------------------------------
CLUSTER, CHANNEL Network
ECU, CONTROLLER, CONNECTOR Network Node
FRAME, FRAME-TRIGGERING Message
SIGNAL, SIGNAL-INSTANCE Message Signals
The following information has no equivalent description in CANdb:
- PDUs and Functions aren't used in CANdb.
- Controller information isn't used in CANdb databases. This information may be stored as node attributes.
- CAN remote frames aren't stored in CANdb databases. This information isn't generated during export and
will be ignored during import.
"""

class Comments:
"""This class contains the comments found in .dbc files.
"""
Expand Down
6 changes: 4 additions & 2 deletions pydbc/ldfListener.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ def exitLogical_value(self, ctx):
def exitPhysical_range(self, ctx):
minValue = ctx.minValue.value
maxValue = ctx.maxValue.value
scale = ctx.scale
offset = ctx.offset
scale = ctx.scale.value if ctx.scale else None
offset = ctx.offset.value
ctx.value = dict(min = minValue, max = maxValue, scale = scale, offset = offset)

def exitBcd_value(self, ctx):
Expand All @@ -420,6 +420,8 @@ def exitMax_value(self, ctx):
ctx.value = ctx.i.value

def exitScale(self, ctx):
print("SCALE:", ctx.n.value)
#print("SCALE#2:", ctx.n)
ctx.value = ctx.n.value

def exitOffset(self, ctx):
Expand Down
33 changes: 28 additions & 5 deletions pydbc/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
__copyright__ = """
pySART - Simplified AUTOSAR-Toolkit for Python.
(C) 2010-2018 by Christoph Schueler <cpu12.gems.googlemail.com>
(C) 2010-2019 by Christoph Schueler <cpu12.gems.googlemail.com>
All Rights Reserved
Expand Down Expand Up @@ -68,12 +68,20 @@ def exitIntValue(self, ctx):
ctx.value = int(ctx.i.text, 10)
elif ctx.h:
ctx.value = int(ctx.h.text, 16)
else:
ctx.value = None

def exitFloatValue(self, ctx):
ctx.value = float(ctx.f.text) if ctx.f else None

def exitNumber(self, ctx):
ctx.value = ctx.i.value if ctx.i else ctx.f.value
if ctx.i:
value = ctx.i.value
elif ctx.f:
value = ctx.f.value
else:
value = None
ctx.value = value

def exitStringValue(self, ctx):
ctx.value = ctx.s.text.strip('"') if ctx.s else None
Expand All @@ -83,7 +91,8 @@ def exitIdentifierValue(self, ctx):


class ParserWrapper(object):

"""
"""
def __init__(self, grammarName, startSymbol, listener = None):
self.grammarName = grammarName
self.startSymbol = startSymbol
Expand Down Expand Up @@ -117,8 +126,8 @@ def parse(self, input, trace = False):
def parseFromFile(self, fileName, encoding = 'latin-1', trace = False):
return self.parse(ParserWrapper.stringStream(fileName, encoding), trace)

def parseFromString(self, buffer, encoding = 'latin-1', trace = False):
return self.parse(antlr4.InputStream(buffer), trace)
def parseFromString(self, buf, encoding = 'latin-1', trace = False):
return self.parse(antlr4.InputStream(buf), trace)

@staticmethod
def stringStream(fname, encoding = 'latin-1'):
Expand All @@ -129,3 +138,17 @@ def _getNumberOfSyntaxErrors(self):

numberOfSyntaxErrors = property(_getNumberOfSyntaxErrors)


class Parser:
"""
"""

def __init__(self, grammar, startSymbol, listener):
self.pw = ParserWrapper(grammar, startSymbol, listener)

def parseFromString(self, buf, encoding = 'latin-1', trace = False):
return self.pw.parseFromString(buf, encoding, trace)

def parseFromFile(self, fileName, encoding = 'latin-1', trace = False):
return self.pw.parseFromString(fileName, encoding, trace)

0 comments on commit bdbd317

Please sign in to comment.