Add equal-length constraints & implement UnaryExpressions (#35)

* add segLen help to lang std

* adding helpers functions to sketchConstraints

* update tokeniser tests because they were annoying me not being 100%

* compare async lexer with sync lexer instead

* add helper functions

* remove unneeded nesting

* update add ast modifier function for angledLine

* initial equal ast modification

It adds a tag to the primary line, and converts any secondary lines to angledLine, but doesn't reference the taged/primary line yet

* Update fn call with refernce to previous line using segLen

* add test for giveSketchFnCallTag

* fix excutor bug, executing call expression in array expression

* fix small issue in executor

* add CallExpressions to BinaryExpressions

* add unary Expressions

* tweaks to unaryExpression logic

* add recasting for unaryExpressions and CallExpressions in BinaryExpressions

* ensure pipe substitution info is passed down to unary expressions and others

* allow binary expressions in function argumentns

* inital setup, new way of organising sketch fn transforms

Starting with equal length

* overhaul equalLength button

* add equal length support for angledLine

* line with one variable supports signed legLength

* fix indentation when recasting long arrayExpressions in a pipeExpression

* improve modifyAst consision

* further modify ast tidy

* equalLength transfroms far angledLineOfXLength

* add transforms for line-yRelative

* add equal constraint for angledLineOfYLength

* quick test fix

* add equal length constrain transforms for lineTo

* add equal length constraints for angledLineToX

* add equalLength constraints for angledLineToY

* test tidy

* setup new vertical-horizontal constraints

* Add equal Length constraints for vertical/horizontal lines

* migrate old tests, and refactor callback tag

* tweaks and refactor horzVert component

* fix leg len with small negative leg length
This commit is contained in:
Kurt Hutten
2023-03-02 21:19:11 +11:00
committed by GitHub
parent f70f0f7bc3
commit 6446601a67
21 changed files with 2280 additions and 666 deletions

View File

@ -3,6 +3,9 @@ import {
Literal,
Identifier,
isNotCodeToken,
findClosingBrace,
CallExpression,
makeCallExpression,
} from './abstractSyntaxTree'
import { Token } from './tokeniser'
@ -12,10 +15,21 @@ export function reversePolishNotation(
operators: Token[] = []
): Token[] {
if (tokens.length === 0) {
return [...previousPostfix, ...operators.slice().reverse()] // reverse mutates, so clone is needed
return [...previousPostfix, ...operators.slice().reverse()] // reverse mutates, so slice/clone is needed
}
const currentToken = tokens[0]
if (
currentToken.type === 'word' &&
tokens?.[1]?.type === 'brace' &&
tokens?.[1]?.value === '('
) {
const closingBrace = findClosingBrace(tokens, 1)
return reversePolishNotation(
tokens.slice(closingBrace + 1),
[...previousPostfix, ...tokens.slice(0, closingBrace + 1)],
operators
)
} else if (
currentToken.type === 'number' ||
currentToken.type === 'word' ||
currentToken.type === 'string'
@ -88,6 +102,7 @@ const buildTree = (
| Literal
| Identifier
| ParenthesisToken
| CallExpression
)[] = []
): BinaryExpression => {
if (reversePolishNotationTokens.length === 0) {
@ -109,6 +124,16 @@ const buildTree = (
},
])
} else if (currentToken.type === 'word') {
if (
reversePolishNotationTokens?.[1]?.type === 'brace' &&
reversePolishNotationTokens?.[1]?.value === '('
) {
const closingBrace = findClosingBrace(reversePolishNotationTokens, 1)
return buildTree(reversePolishNotationTokens.slice(closingBrace + 1), [
...stack,
makeCallExpression(reversePolishNotationTokens, 0).expression,
])
}
return buildTree(reversePolishNotationTokens.slice(1), [
...stack,
{