summaryrefslogtreecommitdiff
path: root/gerbonara/gerber/utils.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2022-01-19 13:40:04 +0100
committerjaseg <git@jaseg.de>2022-01-19 13:40:04 +0100
commit6c924609416b82e6be68680874d86447cffa9fd9 (patch)
tree9b5803acfb5850a56f1c3f485569867b8df7c019 /gerbonara/gerber/utils.py
parent40286fc92fc05ce82cbad4615f497ba389ac9457 (diff)
downloadgerbonara-6c924609416b82e6be68680874d86447cffa9fd9.tar.gz
gerbonara-6c924609416b82e6be68680874d86447cffa9fd9.tar.bz2
gerbonara-6c924609416b82e6be68680874d86447cffa9fd9.zip
Matcher WIP
Diffstat (limited to 'gerbonara/gerber/utils.py')
-rw-r--r--gerbonara/gerber/utils.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/gerbonara/gerber/utils.py b/gerbonara/gerber/utils.py
index 060aa0b..d1045ad 100644
--- a/gerbonara/gerber/utils.py
+++ b/gerbonara/gerber/utils.py
@@ -27,6 +27,21 @@ import os
from enum import Enum
from math import radians, sin, cos, sqrt, atan2, pi
+class RegexMatcher:
+ def __init__(self):
+ self.mapping = {}
+
+ def match(self, regex):
+ def wrapper(fun):
+ nonlocal self
+ self.mapping[regex] = fun
+ return fun
+ return wrapper
+
+ def handle(self, inst, line):
+ for regex, handler in self.mapping.items():
+ if (match := re.fullmatch(regex, line)):
+ handler(match)
class LengthUnit:
def __init__(self, name, shorthand, this_in_mm):
@@ -73,7 +88,7 @@ MILLIMETERS_PER_INCH = 25.4
Inch = LengthUnit('inch', 'in', MILLIMETERS_PER_INCH)
MM = LengthUnit('millimeter', 'mm', 1)
units = {'inch': Inch, 'mm': MM, None: None}
-to_unit = lambda name: units[name]
+to_unit = lambda name: units[name.lower() if name else None]
class InterpMode(Enum):