Reserve syntax for units of measure (#4783)

* Allow underscores but only for un-referenced names

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Support numeric suffixes for UoM types

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* UoM type arguments

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* warnings -> non-fatal errors

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* type ascription

Signed-off-by: Nick Cameron <nrc@ncameron.org>

---------

Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
Nick Cameron
2024-12-17 09:01:51 +13:00
committed by GitHub
parent 1d39983b08
commit fa22c14723
6 changed files with 249 additions and 47 deletions

View File

@ -27,7 +27,7 @@ fn Gte = (a, b) => { return Not(Lt(a, b)) }
deg = pi()*2 / 360
fn setSketch = (state, _q) => {
fn setSketch = (state, q) => {
return {
depthMax: state.depthMax,
depth: state.depth + 1,
@ -35,43 +35,43 @@ fn setSketch = (state, _q) => {
factor: state.factor,
currentAngle: state.currentAngle,
angle: state.angle,
_q: _q
q
}
}
fn setDepth = (state, _q) => {
fn setDepth = (state, q) => {
return {
depthMax: state.depthMax,
depth: _q,
depth: q,
currentLength: state.currentLength,
factor: state.factor,
currentAngle: state.currentAngle,
angle: state.angle,
_q: state._q
q: state.q
}
}
fn setAngle = (state, _q) => {
fn setAngle = (state, q) => {
return {
depthMax: state.depthMax,
depth: state.depth,
currentLength: state.currentLength,
factor: state.factor,
currentAngle: _q,
currentAngle: q,
angle: state.angle,
_q: state._q
q: state.q
}
}
fn setLength = (state, _q) => {
fn setLength = (state, q) => {
return {
depthMax: state.depthMax,
depth: state.depth,
currentLength: _q,
currentLength: q,
factor: state.factor,
currentAngle: state.currentAngle,
angle: state.angle,
_q: state._q
q: state.q
}
}
@ -95,7 +95,7 @@ fn F = (state, F) => {
} else {
// Pass onto the next instruction
state |> setSketch(%, angledLine({ angle: state.currentAngle, length: state.currentLength }, state._q))
state |> setSketch(%, angledLine({ angle: state.currentAngle, length: state.currentLength }, state.q))
}
}
@ -107,7 +107,7 @@ fn LSystem = (args, axioms) => {
factor: args.factor,
currentAngle: 0,
angle: args.angle,
_q: startSketchAt([0, 0]),
q: startSketchAt([0, 0]),
})
}
@ -115,7 +115,7 @@ LSystem({
iterations: 1,
factor: 1.36,
angle: 60,
}, (_q) => {
result = _q |> F(%, F) |> Add(%) |> Add(%) |> F(%, F) |> Add(%) |> Add(%) |> F(%, F)
return result._q
}, (q) => {
result = q |> F(%, F) |> Add(%) |> Add(%) |> F(%, F) |> Add(%) |> Add(%) |> F(%, F)
return result.q
})