Skip to content

Commit 7c5f15c

Browse files
committed
allow even more special characters #330
1 parent 2c497a8 commit 7c5f15c

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/canmatrix/formats/dbc.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ def add_frame_by_id(frame): # type: (canmatrix.Frame) -> None
761761
substring = decoded[7:].strip()
762762
define_type = substring[:3]
763763
substring = substring[3:].strip()
764-
pattern = r"^\"([A-Za-z0-9\-_\ ]+)\" +(.+);"
764+
pattern = r"^\"(.+)\" +(.+);"
765765
regexp = re.compile(pattern)
766766
regexp_raw = re.compile(pattern.encode(dbcImportEncoding))
767767
temp = regexp.match(substring)
@@ -778,7 +778,7 @@ def add_frame_by_id(frame): # type: (canmatrix.Frame) -> None
778778
db.add_env_defines(temp.group(1), temp_raw.group(2).decode(dbcImportEncoding))
779779

780780
elif decoded.startswith("BA_DEF_ "):
781-
pattern = r"^BA_DEF_ +\"([A-Za-z0-9\-_]+)\" +(.+);"
781+
pattern = r"^BA_DEF_ +\"(.+)\" +(.+);"
782782
regexp = re.compile(pattern)
783783
regexp_raw = re.compile(pattern.encode(dbcImportEncoding))
784784
temp = regexp.match(decoded)
@@ -792,7 +792,7 @@ def add_frame_by_id(frame): # type: (canmatrix.Frame) -> None
792792
tempba = regexp.match(decoded)
793793

794794
if tempba.group(1).strip().startswith("BO_ "):
795-
regexp = re.compile(r"^BA_ +\"(.*)\" +BO_ +(\w+) +(.+);")
795+
regexp = re.compile(r"^BA_ +\"(.*)\" +BO_ +(.+) +(.+);")
796796
temp = regexp.match(decoded)
797797
get_frame_by_id(canmatrix.ArbitrationId.from_compound_integer(int(temp.group(2)))).add_attribute(
798798
temp.group(1), temp.group(3))
@@ -816,7 +816,7 @@ def add_frame_by_id(frame): # type: (canmatrix.Frame) -> None
816816
temp.group(3))
817817
else:
818818
regexp = re.compile(
819-
r"^BA_ +\"([A-Za-z0-9\-_]+)\" +([\"A-Za-z0-9\-_\.]+);")
819+
r"^BA_ +\"([A-Za-z0-9\-_]+)\" +([\"\w\-\.]+);")
820820
temp = regexp.match(decoded)
821821
if temp:
822822
db.add_attribute(temp.group(1), temp.group(2))
@@ -839,7 +839,7 @@ def add_frame_by_id(frame): # type: (canmatrix.Frame) -> None
839839
# SIG_VALTYPE_ 0 float : 1;
840840

841841
elif decoded.startswith("BA_DEF_DEF_ "):
842-
pattern = r"^BA_DEF_DEF_ +\"([A-Za-z0-9\-_\.]+)\" +(.+)\;"
842+
pattern = r"^BA_DEF_DEF_ +\"([\w\-\.]+)\" +(.+)\;"
843843
regexp = re.compile(pattern)
844844
regexp_raw = re.compile(pattern.encode(dbcImportEncoding))
845845
temp = regexp.match(decoded)
@@ -848,7 +848,7 @@ def add_frame_by_id(frame): # type: (canmatrix.Frame) -> None
848848
db.add_define_default(temp.group(1),
849849
temp_raw.group(2).decode(dbcImportEncoding))
850850
elif decoded.startswith("SG_MUL_VAL_ "):
851-
pattern = r"^SG_MUL_VAL_ +([0-9]+) +([A-Za-z0-9\-_]+) +([A-Za-z0-9\-_]+) +([0-9]+)\-([0-9]+) *;"
851+
pattern = r"^SG_MUL_VAL_ +([0-9]+) +([\w\-]+) +([\w\-]+) +([0-9]+)\-([0-9]+) *;"
852852
regexp = re.compile(pattern)
853853
regexp_raw = re.compile(pattern.encode(dbcImportEncoding))
854854
temp = regexp.match(decoded)
@@ -867,7 +867,7 @@ def add_frame_by_id(frame): # type: (canmatrix.Frame) -> None
867867
signal.mux_val_min = muxValMin
868868
signal.mux_val_max = muxValMax
869869
elif decoded.startswith("EV_ "):
870-
pattern = r"^EV_ +([A-Za-z0-9\-_]+) *\: +([0-9]+) +\[([0-9.+\-eE]+)\|([0-9.+\-eE]+)\] +\"(\w*)\" +([0-9.+\-eE]+) +([0-9.+\-eE]+) +([A-Za-z0-9\-_]+) +(.*);"
870+
pattern = r"^EV_ +([\w\-]+) *\: +([0-9]+) +\[([0-9.+\-eE]+)\|([0-9.+\-eE]+)\] +\"(\w*)\" +([0-9.+\-eE]+) +([0-9.+\-eE]+) +([\w\-]+) +(.*);"
871871
regexp = re.compile(pattern)
872872
temp = regexp.match(decoded)
873873

src/canmatrix/tests/test_dbc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,6 @@ def test_defines_with_spaces():
243243
assert matrix.ecu_defines["Node Address"].min == 0
244244
assert matrix.ecu_defines["Node Address"].max == 255
245245
assert matrix.frame_defines["Period [ms]"].min == 0
246-
assert matrix.frame_defines["Period [ms]"].max == 3000
247-
246+
assert matrix.frame_defines["Period [ms]"].max == 5000
247+
assert matrix.frames[0].attributes["Period [ms]"] == '3000'
248248

0 commit comments

Comments
 (0)