summaryrefslogtreecommitdiff
path: root/gerbonara/aperture_macros
diff options
context:
space:
mode:
Diffstat (limited to 'gerbonara/aperture_macros')
-rw-r--r--gerbonara/aperture_macros/expression.py4
-rw-r--r--gerbonara/aperture_macros/parse.py6
-rw-r--r--gerbonara/aperture_macros/primitive.py4
3 files changed, 9 insertions, 5 deletions
diff --git a/gerbonara/aperture_macros/expression.py b/gerbonara/aperture_macros/expression.py
index 7c291cb..2926aa7 100644
--- a/gerbonara/aperture_macros/expression.py
+++ b/gerbonara/aperture_macros/expression.py
@@ -180,6 +180,9 @@ class ConstantExpression(Expression):
@dataclass(frozen=True, slots=True)
class VariableExpression(Expression):
+ ''' An expression that encapsulates some other complex expression and will replace all occurences of it with a newly
+ allocated variable at export time.
+ '''
expr: Expression
def optimized(self, variable_binding={}):
@@ -201,6 +204,7 @@ class VariableExpression(Expression):
@dataclass(frozen=True, slots=True)
class ParameterExpression(Expression):
+ ''' An expression that refers to a macro variable or parameter '''
number: int
def optimized(self, variable_binding={}):
diff --git a/gerbonara/aperture_macros/parse.py b/gerbonara/aperture_macros/parse.py
index 33c205e..9f6375f 100644
--- a/gerbonara/aperture_macros/parse.py
+++ b/gerbonara/aperture_macros/parse.py
@@ -20,8 +20,8 @@ def rad_to_deg(x):
return (x / math.pi) * 180
def _map_expression(node, variables={}, parameters=set()):
- if isinstance(node, ast.Num):
- return ConstantExpression(node.n)
+ if isinstance(node, ast.Constant):
+ return ConstantExpression(node.value)
elif isinstance(node, ast.BinOp):
op_map = {ast.Add: operator.add, ast.Sub: operator.sub, ast.Mult: operator.mul, ast.Div: operator.truediv}
@@ -93,7 +93,7 @@ class ApertureMacro:
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]}.')
+ warnings.warn(f'Re-definition of aperture macro variable ${number} inside aperture macro "{macro_name}". 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
diff --git a/gerbonara/aperture_macros/primitive.py b/gerbonara/aperture_macros/primitive.py
index 31c5cb9..0c0d54c 100644
--- a/gerbonara/aperture_macros/primitive.py
+++ b/gerbonara/aperture_macros/primitive.py
@@ -97,8 +97,8 @@ class Circle(Primitive):
exposure : Expression
diameter : UnitExpression
# center x/y
- x : UnitExpression
- y : UnitExpression
+ x : UnitExpression = 0
+ y : UnitExpression = 0
rotation : Expression = 0
def to_graphic_primitives(self, offset, rotation, variable_binding={}, unit=None, polarity_dark=True):