Skip to content

Commit

Permalink
feat: handle colons in ghdl sim parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
glencoe committed Sep 4, 2023
1 parent f905bbf commit f485531
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
20 changes: 20 additions & 0 deletions elasticai/creator/vhdl/_ghdl_report_parsing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def parse(text):
lines = text.split("\n")[:-1]

def split_first_five_colons(line):
all_split = line.split(":")
reassembled = all_split[0:5] + [":".join(all_split[5:])]
return reassembled

separated = [split_first_five_colons(line) for line in lines]
fields = ("source", "line", "column", "time", "type", "content")

def parse_line(line):
parsed = dict(zip(fields, line))
parsed["type"] = parsed["type"][1:-1]
parsed["time"] = parsed["time"][1:]
parsed["line"] = int(parsed["line"])
parsed["column"] = int(parsed["column"])
return parsed

return [parse_line(line) for line in separated]
54 changes: 54 additions & 0 deletions elasticai/creator/vhdl/_ghdl_report_parsing_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from ._ghdl_report_parsing import parse


def test_parse_ghdl_simulation_results_one_liner():
simulation_output = "my_test_bench.vhd:64:17:@4ps:(report note):my report message\n"
expected = [
{
"source": "my_test_bench.vhd",
"line": 64,
"column": 17,
"time": "4ps",
"type": "report note",
"content": "my report message",
}
]
assert expected == parse(simulation_output)


def test_parse_ghdl_another_line():
simulation_output = "A:1:2:@B:(C):D\n"
expected = [
{
"source": "A",
"line": 1,
"column": 2,
"time": "B",
"type": "C",
"content": "D",
}
]
assert expected == parse(simulation_output)


def test_parse_two_lines():
simulation_output = (
"source:1:1:@time:(type):content\nsource:1:1:@time:(type):content\nignored last"
" line"
)
expected = [
{
"source": "source",
"line": 1,
"column": 1,
"time": "time",
"type": "type",
"content": "content",
}
] * 2
assert expected == parse(simulation_output)


def test_put_colon_content_in_content_field():
simulation_output = "A:1:2:@B:(C):D:e:f\n"
assert "D:e:f" == parse(simulation_output)[0]["content"]

0 comments on commit f485531

Please sign in to comment.