fmt
This commit is contained in:
@ -56,7 +56,11 @@ export const SketchPlane = () => {
|
|||||||
} else if (guiMode.axis === 'yz') {
|
} else if (guiMode.axis === 'yz') {
|
||||||
addLinePoint = [point.z, point.y]
|
addLinePoint = [point.z, point.y]
|
||||||
}
|
}
|
||||||
const { modifiedAst } = addLine(_ast, guiMode.pathToNode, addLinePoint)
|
const { modifiedAst } = addLine(
|
||||||
|
_ast,
|
||||||
|
guiMode.pathToNode,
|
||||||
|
addLinePoint
|
||||||
|
)
|
||||||
updateAst(modifiedAst)
|
updateAst(modifiedAst)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
@ -1214,7 +1214,6 @@ export function addLine(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function isCallExpression(tokens: Token[], index: number): number {
|
function isCallExpression(tokens: Token[], index: number): number {
|
||||||
const currentToken = tokens[index]
|
const currentToken = tokens[index]
|
||||||
const veryNextToken = tokens[index + 1] // i.e. no whitespace
|
const veryNextToken = tokens[index + 1] // i.e. no whitespace
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
import { Program, BinaryPart, BinaryExpression, PipeExpression } from './abstractSyntaxTree'
|
import {
|
||||||
|
Program,
|
||||||
|
BinaryPart,
|
||||||
|
BinaryExpression,
|
||||||
|
PipeExpression,
|
||||||
|
} from './abstractSyntaxTree'
|
||||||
import { Path, Transform, sketchFns } from './sketch'
|
import { Path, Transform, sketchFns } from './sketch'
|
||||||
import { BufferGeometry } from 'three'
|
import { BufferGeometry } from 'three'
|
||||||
|
|
||||||
@ -108,7 +113,8 @@ export const executor = (
|
|||||||
_programMemory.root[variableName] = result.currentPath
|
_programMemory.root[variableName] = result.currentPath
|
||||||
} else if ('rx' === fnName || 'ry' === fnName || 'rz' === fnName) {
|
} else if ('rx' === fnName || 'ry' === fnName || 'rz' === fnName) {
|
||||||
const sketch = declaration.init.arguments[1]
|
const sketch = declaration.init.arguments[1]
|
||||||
if(sketch.type !== 'Identifier') throw new Error('rx must be called with an identifier')
|
if (sketch.type !== 'Identifier')
|
||||||
|
throw new Error('rx must be called with an identifier')
|
||||||
const sketchVal = _programMemory.root[sketch.name]
|
const sketchVal = _programMemory.root[sketch.name]
|
||||||
const result = sketchFns[fnName](
|
const result = sketchFns[fnName](
|
||||||
_programMemory,
|
_programMemory,
|
||||||
@ -198,14 +204,22 @@ function getPipeExpressionResult(
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
function executePipeBody(body: PipeExpression['body'], programMemory: ProgramMemory, expressionIndex = 0, previousResults: any[] = []): any[] {
|
function executePipeBody(
|
||||||
|
body: PipeExpression['body'],
|
||||||
|
programMemory: ProgramMemory,
|
||||||
|
expressionIndex = 0,
|
||||||
|
previousResults: any[] = []
|
||||||
|
): any[] {
|
||||||
if (expressionIndex === body.length) {
|
if (expressionIndex === body.length) {
|
||||||
return previousResults
|
return previousResults
|
||||||
}
|
}
|
||||||
const expression = body[expressionIndex]
|
const expression = body[expressionIndex]
|
||||||
if (expression.type === 'BinaryExpression') {
|
if (expression.type === 'BinaryExpression') {
|
||||||
const result = getBinaryExpressionResult(expression, programMemory)
|
const result = getBinaryExpressionResult(expression, programMemory)
|
||||||
return executePipeBody(body, programMemory, expressionIndex + 1, [...previousResults, result])
|
return executePipeBody(body, programMemory, expressionIndex + 1, [
|
||||||
|
...previousResults,
|
||||||
|
result,
|
||||||
|
])
|
||||||
} else if (expression.type === 'CallExpression') {
|
} else if (expression.type === 'CallExpression') {
|
||||||
const fnName = expression.callee.name
|
const fnName = expression.callee.name
|
||||||
const fnArgs = expression.arguments.map((arg) => {
|
const fnArgs = expression.arguments.map((arg) => {
|
||||||
@ -214,7 +228,7 @@ function executePipeBody(body: PipeExpression['body'], programMemory: ProgramMem
|
|||||||
} else if (arg.type === 'Identifier') {
|
} else if (arg.type === 'Identifier') {
|
||||||
return programMemory.root[arg.name]
|
return programMemory.root[arg.name]
|
||||||
} else if (arg.type === 'PipeSubstitution') {
|
} else if (arg.type === 'PipeSubstitution') {
|
||||||
return previousResults[expressionIndex-1]
|
return previousResults[expressionIndex - 1]
|
||||||
}
|
}
|
||||||
throw new Error('Invalid argument type')
|
throw new Error('Invalid argument type')
|
||||||
})
|
})
|
||||||
@ -225,10 +239,16 @@ function executePipeBody(body: PipeExpression['body'], programMemory: ProgramMem
|
|||||||
fnArgs[0],
|
fnArgs[0],
|
||||||
fnArgs[1]
|
fnArgs[1]
|
||||||
)
|
)
|
||||||
return executePipeBody(body, programMemory, expressionIndex + 1, [...previousResults, result])
|
return executePipeBody(body, programMemory, expressionIndex + 1, [
|
||||||
|
...previousResults,
|
||||||
|
result,
|
||||||
|
])
|
||||||
}
|
}
|
||||||
const result = programMemory.root[fnName](...fnArgs)
|
const result = programMemory.root[fnName](...fnArgs)
|
||||||
return executePipeBody(body, programMemory, expressionIndex + 1, [...previousResults, result])
|
return executePipeBody(body, programMemory, expressionIndex + 1, [
|
||||||
|
...previousResults,
|
||||||
|
result,
|
||||||
|
])
|
||||||
} else if (expression.type === 'SketchExpression') {
|
} else if (expression.type === 'SketchExpression') {
|
||||||
const sketchBody = expression.body
|
const sketchBody = expression.body
|
||||||
const fnMemory: ProgramMemory = {
|
const fnMemory: ProgramMemory = {
|
||||||
@ -251,13 +271,15 @@ function executePipeBody(body: PipeExpression['body'], programMemory: ProgramMem
|
|||||||
_sketch = newProgramMemory._sketch
|
_sketch = newProgramMemory._sketch
|
||||||
}
|
}
|
||||||
// _programMemory.root[variableName] = _sketch
|
// _programMemory.root[variableName] = _sketch
|
||||||
return executePipeBody(body, programMemory, expressionIndex + 1, [...previousResults, _sketch])
|
return executePipeBody(body, programMemory, expressionIndex + 1, [
|
||||||
|
...previousResults,
|
||||||
|
_sketch,
|
||||||
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error('Invalid pipe expression')
|
throw new Error('Invalid pipe expression')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type SourceRange = [number, number]
|
type SourceRange = [number, number]
|
||||||
|
|
||||||
export type ViewerArtifact =
|
export type ViewerArtifact =
|
||||||
@ -277,12 +299,11 @@ type PreviousTransforms = {
|
|||||||
transform: [number, number, number]
|
transform: [number, number, number]
|
||||||
}[]
|
}[]
|
||||||
|
|
||||||
export const processShownObjects =
|
export const processShownObjects = (
|
||||||
(
|
|
||||||
programMemory: ProgramMemory,
|
programMemory: ProgramMemory,
|
||||||
geoMeta: Path[] | Transform,
|
geoMeta: Path[] | Transform,
|
||||||
previousTransforms: PreviousTransforms = []
|
previousTransforms: PreviousTransforms = []
|
||||||
): ViewerArtifact[] => {
|
): ViewerArtifact[] => {
|
||||||
if (Array.isArray(geoMeta)) {
|
if (Array.isArray(geoMeta)) {
|
||||||
return geoMeta.map(({ geo, sourceRange }) => {
|
return geoMeta.map(({ geo, sourceRange }) => {
|
||||||
const newGeo = geo.clone()
|
const newGeo = geo.clone()
|
||||||
@ -316,4 +337,4 @@ export const processShownObjects =
|
|||||||
}
|
}
|
||||||
|
|
||||||
throw new Error('Unknown geoMeta type')
|
throw new Error('Unknown geoMeta type')
|
||||||
}
|
}
|
||||||
|
@ -30,9 +30,12 @@ export function recast(
|
|||||||
(declaration.init.type === 'PipeExpression' &&
|
(declaration.init.type === 'PipeExpression' &&
|
||||||
declaration.init.body[0].type === 'SketchExpression')
|
declaration.init.body[0].type === 'SketchExpression')
|
||||||
|
|
||||||
const assignmentString = isSketchOrFirstPipeExpressionIsSketch ? ' ' : ' = '
|
const assignmentString = isSketchOrFirstPipeExpressionIsSketch
|
||||||
return `${indentation}${statement.kind} ${declaration.id.name}${assignmentString}${recastValue(declaration.init)}`
|
? ' '
|
||||||
|
: ' = '
|
||||||
|
return `${indentation}${statement.kind} ${
|
||||||
|
declaration.id.name
|
||||||
|
}${assignmentString}${recastValue(declaration.init)}`
|
||||||
})
|
})
|
||||||
.join('')
|
.join('')
|
||||||
} else if (statement.type === 'ReturnStatement') {
|
} else if (statement.type === 'ReturnStatement') {
|
||||||
@ -104,7 +107,6 @@ ${recast(expression.body, '', indentation + ' ')}
|
|||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function recastValue(node: Value, indentation = ''): string {
|
function recastValue(node: Value, indentation = ''): string {
|
||||||
if (node.type === 'BinaryExpression') {
|
if (node.type === 'BinaryExpression') {
|
||||||
return recastBinaryExpression(node)
|
return recastBinaryExpression(node)
|
||||||
@ -117,9 +119,9 @@ function recastValue(node: Value, indentation = ''): string {
|
|||||||
} else if (node.type === 'SketchExpression') {
|
} else if (node.type === 'SketchExpression') {
|
||||||
return recastSketchExpression(node, indentation)
|
return recastSketchExpression(node, indentation)
|
||||||
} else if (node.type === 'PipeExpression') {
|
} else if (node.type === 'PipeExpression') {
|
||||||
return node.body.map((statement): string =>
|
return node.body
|
||||||
recastValue(statement, indentation)
|
.map((statement): string => recastValue(statement, indentation))
|
||||||
).join('\n |> ')
|
.join('\n |> ')
|
||||||
}
|
}
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
@ -299,7 +299,6 @@ describe('testing lexer', () => {
|
|||||||
"whitespace ' ' from 6 to 7",
|
"whitespace ' ' from 6 to 7",
|
||||||
"number '2.5' from 7 to 10",
|
"number '2.5' from 7 to 10",
|
||||||
])
|
])
|
||||||
|
|
||||||
})
|
})
|
||||||
it('testing piping operator', () => {
|
it('testing piping operator', () => {
|
||||||
const result = stringSummaryLexer(`sketch mySketch {
|
const result = stringSummaryLexer(`sketch mySketch {
|
||||||
@ -330,7 +329,7 @@ describe('testing lexer', () => {
|
|||||||
"comma ',' from 51 to 52",
|
"comma ',' from 51 to 52",
|
||||||
"whitespace ' ' from 52 to 53",
|
"whitespace ' ' from 52 to 53",
|
||||||
"operator '%' from 53 to 54",
|
"operator '%' from 53 to 54",
|
||||||
"brace ')' from 54 to 55"
|
"brace ')' from 54 to 55",
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user