diff --git a/src/compiler/compiler.ts b/src/compiler/compiler.ts index fe18a09..b03b9b9 100644 --- a/src/compiler/compiler.ts +++ b/src/compiler/compiler.ts @@ -1,9 +1,10 @@ import { CompilerError } from '#compiler/compilerError.ts' +import { parse } from '#parser/parser2' +import { SyntaxNode, Tree } from '#parser/node' import { parser } from '#parser/shrimp.ts' import * as terms from '#parser/shrimp.terms' import { setGlobals } from '#parser/tokenizer' import { tokenizeCurlyString } from '#parser/curlyTokenizer' -import type { SyntaxNode, Tree } from '@lezer/common' import { assert, errorMessage } from '#utils/utils' import { toBytecode, type Bytecode, type ProgramItem, bytecodeToString } from 'reefvm' import { @@ -63,13 +64,14 @@ export class Compiler { constructor(public input: string, globals?: string[] | Record) { try { if (globals) setGlobals(Array.isArray(globals) ? globals : Object.keys(globals)) - const cst = parser.parse(input) - const errors = checkTreeForErrors(cst) + const ast = parse(input) + const cst = new Tree(ast) + // const errors = checkTreeForErrors(cst) - const firstError = errors[0] - if (firstError) { - throw firstError - } + // const firstError = errors[0] + // if (firstError) { + // throw firstError + // } this.#compileCst(cst, input) this.bytecode = toBytecode(this.instructions) diff --git a/src/compiler/utils.ts b/src/compiler/utils.ts index 446aab3..18dbda4 100644 --- a/src/compiler/utils.ts +++ b/src/compiler/utils.ts @@ -1,16 +1,17 @@ import { CompilerError } from '#compiler/compilerError.ts' import * as terms from '#parser/shrimp.terms' -import type { SyntaxNode, Tree } from '@lezer/common' +import type { SyntaxNode, Tree } from '#parser/node' export const checkTreeForErrors = (tree: Tree): CompilerError[] => { const errors: CompilerError[] = [] - tree.iterate({ - enter: (node) => { - if (node.type.isError) { - errors.push(new CompilerError(`Unexpected syntax.`, node.from, node.to)) - } - }, - }) + + // tree.iterate({ + // enter: (node) => { + // if (node.type.isError) { + // errors.push(new CompilerError(`Unexpected syntax.`, node.from, node.to)) + // } + // }, + // }) return errors }