diff options
author | jaseg <git@jaseg.de> | 2023-11-14 21:43:22 +0100 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2023-11-14 21:54:04 +0100 |
commit | ea4c28e307622fd575d95d9d81b29820c6feff99 (patch) | |
tree | 29f093a15001cff7fb7c5189fa9db101de2aa36e /gerbonara/aperture_macros/parse.py | |
parent | 51ef4882a16cecb29bb643100b432b22e1f3f76f (diff) | |
download | gerbonara-ea4c28e307622fd575d95d9d81b29820c6feff99.tar.gz gerbonara-ea4c28e307622fd575d95d9d81b29820c6feff99.tar.bz2 gerbonara-ea4c28e307622fd575d95d9d81b29820c6feff99.zip |
Make new test files pass
Diffstat (limited to 'gerbonara/aperture_macros/parse.py')
-rw-r--r-- | gerbonara/aperture_macros/parse.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/gerbonara/aperture_macros/parse.py b/gerbonara/aperture_macros/parse.py index de84a9a..33c205e 100644 --- a/gerbonara/aperture_macros/parse.py +++ b/gerbonara/aperture_macros/parse.py @@ -8,6 +8,7 @@ import operator import re import ast import copy +import warnings import math from . import primitive as ap @@ -88,16 +89,22 @@ class ApertureMacro: block = re.sub(r'\s', '', block) if block[0] == '$': # variable definition - name, expr = block.partition('=') - number = int(name[1:]) - if number in variables: - raise SyntaxError(f'Re-definition of aperture macro variable ${number} inside macro. Previous definition of ${number} was ${variables[number]}.') - variables[number] = _parse_expression(expr, variables, parameters) + try: + name, _, expr = block.partition('=') + number = int(name[1:]) + if number in variables: + warnings.warn(f'Re-definition of aperture macro variable ${number} inside macro. Previous definition of ${number} was ${variables[number]}.') + variables[number] = _parse_expression(expr, variables, parameters) + except Exception as e: + raise SyntaxError(f'Error parsing variable definition {block!r}') from e else: # primitive primitive, *args = block.split(',') args = [ _parse_expression(arg, variables, parameters) for arg in args ] - primitives.append(ap.PRIMITIVE_CLASSES[int(primitive)].from_arglist(unit, args)) + try: + primitives.append(ap.PRIMITIVE_CLASSES[int(primitive)].from_arglist(unit, args)) + except KeyError as e: + raise SyntaxError(f'Unknown aperture macro primitive code {int(primitive)}') return kls(macro_name, max(parameters, default=0), tuple(primitives), tuple(comments)) |