Skip to content

Commit 6d6787c

Browse files
committed
New RegExp based approach.
1 parent dd1fe71 commit 6d6787c

File tree

7 files changed

+586
-585
lines changed

7 files changed

+586
-585
lines changed

.github/workflows/Pipeline.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
package_namespace: 'pyEDAA'
1515
package_name: 'OutputFilter'
1616
unittest_python_version_list: '3.11 3.12 3.13 3.14 pypy-3.11'
17+
unittest_disable_list: 'macos:* windows-arm:pypy-3.11'
1718
bandit: 'true'
1819
pylint: 'false'
1920
codecov: 'true'

pyEDAA/OutputFilter/Xilinx/Common2.py

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
from pyEDAA.OutputFilter.Xilinx.Exception import ProcessorException
4444

4545

46+
MAJOR = r"(?P<major>\d+)"
47+
MAJOR_MINOR = r"(?P<major>\d+)\.(?P<minor>\d+)"
48+
MAJOR_MINOR_MICRO = r"(?P<major>\d+)\.(?P<minor>\d+)\.(?P<micro>\d+)"
49+
MAJOR_MINOR_MICRO_NANO = r"(?P<major>\d+)\.(?P<minor>\d+)\.(?P<micro>\d+)\.(?P<nano>\d+)"
50+
51+
4652
@export
4753
class VivadoMessagesMixin(metaclass=ExtendedType, mixin=True):
4854
_infoMessages: List[VivadoInfoMessage]
@@ -447,7 +453,7 @@ def Generator(self, line: Line) -> Generator[Line, Line, Line]:
447453
self._AddMessage(line)
448454
elif line.StartsWith("Phase "):
449455
for parser in activeParsers: # type: Phase
450-
if line.StartsWith(parser._START):
456+
if (match := parser._START.match(line._message)) is not None:
451457
line = yield next(phase := parser.Generator(line))
452458
break
453459
else:
@@ -487,29 +493,33 @@ class Phase(BaseParser, VivadoMessagesMixin, metaclass=ExtendedType, slots=True)
487493
_TIME: ClassVar[str] = "Time (s):"
488494
_FINAL: ClassVar[Nullable[str]] = None
489495

490-
_task: TaskWithPhases
491-
_duration: float
496+
_task: TaskWithPhases
497+
_phaseIndex: int
498+
_duration: float
492499

493500
def __init__(self, task: TaskWithPhases):
494501
super().__init__()
495502
VivadoMessagesMixin.__init__(self)
496503

504+
self._phaseIndex = None
497505
self._task = task
498506

499507
@readonly
500508
def Task(self) -> TaskWithPhases:
501509
return self._task
502510

503511
def _PhaseStart(self, line: Line) -> Generator[Line, Line, Line]:
504-
if not line.StartsWith(self._START):
512+
if (match := self._START.match(line._message)) is None:
505513
raise ProcessorException(f"{self.__class__.__name__}._PhaseStart(): Expected '{self._START}' at line {line._lineNumber}.")
506514

515+
self._phaseIndex = int(match["major"])
516+
507517
line._kind = LineKind.PhaseStart
508518
nextLine = yield line
509519
return nextLine
510520

511521
def _PhaseFinish(self, line: Line) -> Generator[Line, Line, None]:
512-
if not line.StartsWith(self._FINISH):
522+
if (match := self._FINISH.match(line._message)) is None:
513523
raise ProcessorException(f"{self.__class__.__name__}._PhaseFinish(): Expected '{self._FINISH}' at line {line._lineNumber}.")
514524

515525
line._kind = LineKind.PhaseEnd
@@ -546,7 +556,7 @@ def Generator(self, line: Line) -> Generator[Line, Line, Line]:
546556
continue
547557
elif isinstance(line, VivadoMessage):
548558
self._AddMessage(line)
549-
elif line.StartsWith(self._FINISH):
559+
elif self._FINISH.match(line._message):
550560
break
551561

552562
line = yield line
@@ -581,22 +591,24 @@ def Generator(self, line: Line) -> Generator[Line, Line, Line]:
581591

582592
activeParsers: List[Phase] = list(self._subphases.values())
583593

594+
SUBPHASE_PREFIX = self._SUBPHASE_PREFIX.format(phase=1)
595+
584596
while True:
585597
while True:
586598
if line._kind is LineKind.Empty:
587599
line = yield line
588600
continue
589601
elif isinstance(line, VivadoMessage):
590602
self._AddMessage(line)
591-
elif line.StartsWith(self._SUBPHASE_PREFIX):
603+
elif line.StartsWith(SUBPHASE_PREFIX):
592604
for parser in activeParsers: # type: Section
593-
if line.StartsWith(parser._START):
605+
if (match := parser._START.match(line._message)) is not None:
594606
line = yield next(phase := parser.Generator(line))
595607
break
596608
else:
597609
raise Exception(f"Unknown subphase: {line!r}")
598610
break
599-
elif line.StartsWith(self._FINISH):
611+
elif self._FINISH.match(line._message):
600612
nextLine = yield from self._PhaseFinish(line)
601613
return nextLine
602614

@@ -632,15 +644,15 @@ def __init__(self, phase: Phase):
632644
self._phase = phase
633645

634646
def _SubPhaseStart(self, line: Line) -> Generator[Line, Line, Line]:
635-
if not line.StartsWith(self._START):
647+
if (match := self._START.match(line._message)) is None:
636648
raise ProcessorException(f"{self.__class__.__name__}._SubPhaseStart(): Expected '{self._START}' at line {line._lineNumber}.")
637649

638650
line._kind = LineKind.SubPhaseStart
639651
nextLine = yield line
640652
return nextLine
641653

642654
def _SubPhaseFinish(self, line: Line) -> Generator[Line, Line, None]:
643-
if not line.StartsWith(self._FINISH):
655+
if (match := self._FINISH.match(line._message)) is None:
644656
raise ProcessorException(f"{self.__class__.__name__}._SubPhaseFinish(): Expected '{self._FINISH}' at line {line._lineNumber}.")
645657

646658
if self._TIME is None:
@@ -666,7 +678,7 @@ def Generator(self, line: Line) -> Generator[Line, Line, Line]:
666678
if line._kind is LineKind.Empty:
667679
line = yield line
668680
continue
669-
elif line.StartsWith(self._FINISH):
681+
elif self._FINISH.match(line._message):
670682
break
671683
elif isinstance(line, VivadoMessage):
672684
self._AddMessage(line)
@@ -692,15 +704,15 @@ def __init__(self, subphase: SubPhase):
692704
self._subphase = subphase
693705

694706
def _SubSubPhaseStart(self, line: Line) -> Generator[Line, Line, Line]:
695-
if not line.StartsWith(self._START):
707+
if (match := self._START.match(line._message)) is None:
696708
raise ProcessorException()
697709

698710
line._kind = LineKind.SubSubPhaseStart
699711
nextLine = yield line
700712
return nextLine
701713

702714
def _SubSubPhaseFinish(self, line: Line) -> Generator[Line, Line, None]:
703-
if not line.StartsWith(self._FINISH):
715+
if (match := self._FINISH.match(line._message)) is None:
704716
raise ProcessorException()
705717

706718
line._kind = LineKind.SubSubPhaseEnd
@@ -723,7 +735,7 @@ def Generator(self, line: Line) -> Generator[Line, Line, Line]:
723735
if line._kind is LineKind.Empty:
724736
line = yield line
725737
continue
726-
elif line.StartsWith(self._FINISH):
738+
elif self._FINISH.match(line._message):
727739
break
728740
elif isinstance(line, VivadoMessage):
729741
self._AddMessage(line)
@@ -749,15 +761,15 @@ def __init__(self, subsubphase: SubSubPhase):
749761
self._subsubphase = subsubphase
750762

751763
def _SubSubSubPhaseStart(self, line: Line) -> Generator[Line, Line, Line]:
752-
if not line.StartsWith(self._START):
764+
if (match := self._START.match(line._message)) is None:
753765
raise ProcessorException()
754766

755767
line._kind = LineKind.SubSubSubPhaseStart
756768
nextLine = yield line
757769
return nextLine
758770

759771
def _SubSubSubPhaseFinish(self, line: Line) -> Generator[Line, Line, None]:
760-
if not line.StartsWith(self._FINISH):
772+
if (match := self._FINISH.match(line._message)) is None:
761773
raise ProcessorException()
762774

763775
line._kind = LineKind.SubSubSubPhaseEnd
@@ -780,7 +792,7 @@ def Generator(self, line: Line) -> Generator[Line, Line, Line]:
780792
if line._kind is LineKind.Empty:
781793
line = yield line
782794
continue
783-
elif line.StartsWith(self._FINISH):
795+
elif self._FINISH.match(line._message):
784796
break
785797
elif isinstance(line, VivadoMessage):
786798
self._AddMessage(line)

0 commit comments

Comments
 (0)