Skip to content

Commit

Permalink
Refactor 'custom' to 'relative'
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed Jan 10, 2019
1 parent 7e49b86 commit 1c98227
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 45 deletions.
8 changes: 8 additions & 0 deletions pydbc/db/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ def insertValues(self, tree):
defaults = tree['attributeDefaults']
self.insertAttributeDefinitions(cur, tree['attributeDefinitions'], defaults)
self.insertAttributes(cur, tree['attributeValues'])
defaults = tree['relativeAttributeDefaults']

self.insertRelativeAttributeDefinitions(cur, tree['relativeAttributeDefinitions'], defaults)
self.insertCategoryDefinitions(cur, tree['categoryDefinitions'])
self.insertCategoryValues(cur, tree['categories'])
self.db.commitTransaction()
Expand Down Expand Up @@ -244,6 +247,11 @@ def insertCategoryValues(self, cur, catagories):
rid = self.queries.fetchEnvVarId(envVarname)
self.db.insertStatement(cur, "Category_Value", "Object_ID,Category_Definition,Objecttype", rid, catId, objType)


def insertRelativeAttributeDefinitions(self, cur, attrs, defaults):
print("C-A-D: {}\n\n{}".format(attrs, defaults))


def insertAttributeDefinitions(self, cur, attrs, defaults):
for attr in attrs:
attrType = attr['type']
Expand Down
68 changes: 34 additions & 34 deletions pydbc/dbc.g4
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,31 @@
grammar dbc;

dbcfile:
version // VERSION
newSymbols // NS_
bitTiming // BS_
nodes // BU_
valueTables // VAL_TABLE_
messages // BO_
messageTransmitters // BO_TX_BU_
environmentVariables // EV_
environmentVariablesData // ENVVAR_DATA_
signalTypes // SGTYPE_
// SGTYPE_VAL_
// BA_DEF_SGTYPE_
// BA_SGTYPE_
// SIG_TYPE_REF_
comments // CM_
attributeDefinitions // BA_DEF_
customAttributeDefinitions // BA_DEF_REL_
attributeDefaults // BA_DEF_DEF_
customAttributeDefaults // BA_DEF_DEF_REL_
attributeValues // BA_
customAttributeValues // BA_REL_
valueDescriptions // VAL_
signalGroups // SIG_GROUP_
categoryDefinitions // CAT_DEF_
categories // CAT_
version // VERSION
newSymbols // NS_
bitTiming // BS_
nodes // BU_
valueTables // VAL_TABLE_
messages // BO_
messageTransmitters // BO_TX_BU_
environmentVariables // EV_
environmentVariablesData // ENVVAR_DATA_
signalTypes // SGTYPE_
// SGTYPE_VAL_
// BA_DEF_SGTYPE_
// BA_SGTYPE_
// SIG_TYPE_REF_
comments // CM_
attributeDefinitions // BA_DEF_
relativeAttributeDefinitions // BA_DEF_REL_
attributeDefaults // BA_DEF_DEF_
relativeAttributeDefaults // BA_DEF_DEF_REL_
attributeValues // BA_
relativeAttributeValues // BA_REL_
valueDescriptions // VAL_
signalGroups // SIG_GROUP_
categoryDefinitions // CAT_DEF_
categories // CAT_
//filter
//signalTypeRefs
//signalGroups
Expand Down Expand Up @@ -204,11 +204,11 @@ attributeDefinition:
'BA_DEF_' objectType = ('BU_' | 'BO_' | 'SG_' | 'EV_')? attrName = stringValue attrValue = attributeValueType ';'
;

customAttributeDefinitions:
(items += customAttributeDefinition)*
relativeAttributeDefinitions:
(items += relativeAttributeDefinition)*
;

customAttributeDefinition:
relativeAttributeDefinition:
'BA_DEF_REL_' objectType = ('BU_SG_REL_'| 'BU_EV_REL_'| 'BU_BO_REL_')? attrName = stringValue attrValue = attributeValueType ';'
;

Expand All @@ -228,11 +228,11 @@ attributeDefault:
'BA_DEF_DEF_' n = stringValue v = attributeValue ';'
;

customAttributeDefaults:
(items += customAttributeDefault)*
relativeAttributeDefaults:
(items += relativeAttributeDefault)*
;

customAttributeDefault:
relativeAttributeDefault:
'BA_DEF_DEF_REL_' n = stringValue v = attributeValue ';'
;

Expand All @@ -256,11 +256,11 @@ attributeValueForObject:
;

///
customAttributeValues:
(items += customAttributeValueForObject)*
relativeAttributeValues:
(items += relativeAttributeValueForObject)*
;

customAttributeValueForObject:
relativeAttributeValueForObject:
'BA_REL_' attributeName = stringValue (
( attrType = 'BU_BO_REL_' nodeName = identifierValue nodeAddress = intValue attrValue = attributeValue)
| (attrType = 'BU_SG_REL_' nodeName = identifierValue 'SG_' messageID = intValue signalName = identifierValue attrValue = attributeValue)
Expand Down
22 changes: 11 additions & 11 deletions pydbc/dbcListener.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ def exitDbcfile(self, ctx):
signalTypes = ctx.signalTypes().value,
comments = ctx.comments().value,
attributeDefinitions = ctx.attributeDefinitions().value,
customAttributeDefinitions = ctx.customAttributeDefinitions().value,
relativeAttributeDefinitions = ctx.relativeAttributeDefinitions().value,
attributeDefaults = ctx.attributeDefaults().value,
customAttributeDefaults = ctx.customAttributeDefaults().value,
relativeAttributeDefaults = ctx.relativeAttributeDefaults().value,
attributeValues = ctx.attributeValues().value,
customAttributeValues = ctx.customAttributeValues().value,
relativeAttributeValues = ctx.relativeAttributeValues().value,
valueDescriptions = ctx.valueDescriptions().value,
categoryDefinitions = ctx.categoryDefinitions().value,
categories = ctx.categories().value,
Expand Down Expand Up @@ -236,10 +236,10 @@ def exitAttributeDefinition(self, ctx):
attributeValue = ctx.attrValue.value
ctx.value = dict(type = objectType, name = attributeName, value = attributeValue)

def exitCustomAttributeDefinitions(self, ctx):
def exitRelativeAttributeDefinitions(self, ctx):
ctx.value = [x.value for x in ctx.items]

def exitCustomAttributeDefinition(self, ctx):
def exitRelativeAttributeDefinition(self, ctx):
objectType = ctx.objectType.text if ctx.objectType else None
attributeName = ctx.attrName.value
attributeValue = ctx.attrValue.value
Expand Down Expand Up @@ -277,14 +277,14 @@ def exitAttributeDefault(self, ctx):
value = ctx.v.value
ctx.value = (name, value)

def exitCustomAttributeDefaults(self, ctx):
def exitRelativeAttributeDefaults(self, ctx):
defaults = {}
for item in ctx.items:
name, value = item.value
defaults[name] = value
ctx.value = defaults

def exitCustomAttributeDefault(self, ctx):
def exitRelativeAttributeDefault(self, ctx):
name = ctx.n.value
value = ctx.v.value
ctx.value = (name, value)
Expand Down Expand Up @@ -323,13 +323,13 @@ def exitAttributeValueForObject(self, ctx):
di = dict(type = "NETWORK", value = evValue)
ctx.value = dict(name = attributeName, **di)

def exitCustomAttributeValues(self, ctx):
print("CustomAttributeValues", ctx.items)
def exitRelativeAttributeValues(self, ctx):
print("RelativeAttributeValues", ctx.items)
items = [x.value for x in ctx.items]
ctx.value = items

def exitCustomAttributeValueForObject(self, ctx):
print("customAttributeValueForObject", ctx.attrType.value)
def exitRelativeAttributeValueForObject(self, ctx):
print("relativeAttributeValueForObject", ctx.attrType.value)

def exitSignalGroups(self, ctx):
items = [x.value for x in ctx.items]
Expand Down

0 comments on commit 1c98227

Please sign in to comment.