Skip to content

Commit

Permalink
b1scad add support for union operator
Browse files Browse the repository at this point in the history
  • Loading branch information
bat52 committed Dec 25, 2024
1 parent 400954f commit 6fa4775
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/b1scad/scad/model04.scad
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
union() {
cube(20);
sphere(30);
}
3 changes: 2 additions & 1 deletion src/b1scad/scad2ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class OpenSCADLexer(Lexer):
tokens = (
CUBE, SPHERE, CYLINDER,
TRANSLATE, ROTATE, SCALE,
TRANSLATE, ROTATE, SCALE, UNION,
LBRACE, RBRACE, LPAREN, RPAREN, LSQUARE, RSQUARE, COMMA, SEMICOLON,
NUMBER
)
Expand All @@ -23,6 +23,7 @@ class OpenSCADLexer(Lexer):
CUBE = r'cube'
SPHERE = r'sphere'
CYLINDER = r'cylinder'
UNION = r'union'
TRANSLATE = r'translate'
ROTATE = r'rotate'
SCALE = r'scale'
Expand Down
4 changes: 4 additions & 0 deletions src/b1scad/scad2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def expr(self, t):
def op(self, p):
return f"{p.shape_set}.mv({p.vector})"

@_('UNION LPAREN RPAREN LBRACE shape_set RBRACE')
def op(self, p):
return f"{p.shape_set}"

@_('ROTATE LPAREN vector RPAREN LBRACE shape_set RBRACE')
def op(self, p):
return f"{p.shape_set}.rotate({p.vector})"
Expand Down
2 changes: 1 addition & 1 deletion src/b1scad/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class B1scadTestMethods(unittest.TestCase):
"""Pylele Test Class"""
def test_all_scad(self):
scaddir = os.path.join(os.path.abspath(os.path.dirname(__file__)),"scad")
for idx in range(4):
for idx in range(5):
fname = f"model{idx:02}"
scadfname = f"{fname}.scad"
fullscadfile = os.path.join(scaddir,scadfname)
Expand Down

0 comments on commit 6fa4775

Please sign in to comment.