From ae9896c8a2db07be272c9002c0f7cb3e52ac0e9d Mon Sep 17 00:00:00 2001 From: Chris Wanstrath <2+defunkt@users.noreply.github.com> Date: Tue, 25 Nov 2025 16:50:25 -0800 Subject: [PATCH] switch bin/shrimp to new parser --- bin/shrimp | 4 ++-- src/index.ts | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bin/shrimp b/bin/shrimp index 6e5d502..0754565 100755 --- a/bin/shrimp +++ b/bin/shrimp @@ -1,7 +1,7 @@ #!/usr/bin/env bun import { colors, globals as prelude } from '../src/prelude' -import { treeToString } from '../src/utils/tree' +import { treeToString2 } from '../src/utils/tree' import { runCode, runFile, compileFile, parseCode } from '../src' import { resolve } from 'path' import { bytecodeToString } from 'reefvm' @@ -143,7 +143,7 @@ async function main() { process.exit(1) } const input = readFileSync(file, 'utf-8') - console.log(treeToString(parseCode(input), input)) + console.log(treeToString2(parseCode(input), input)) return } diff --git a/src/index.ts b/src/index.ts index 47f5444..f77f99b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,15 +1,15 @@ import { readFileSync } from 'fs' import { VM, fromValue, toValue, isValue, type Bytecode } from 'reefvm' -import { type Tree } from '@lezer/common' import { Compiler } from '#compiler/compiler' -import { parser } from '#parser/shrimp' +import { parse } from '#parser/parser2' +import { type SyntaxNode, Tree } from '#parser/node' import { globals as parserGlobals, setGlobals as setParserGlobals } from '#parser/tokenizer' import { globals as prelude } from '#prelude' export { Compiler } from '#compiler/compiler' -export { parser } from '#parser/shrimp' +export { parse } from '#parser/parser2' +export { type SyntaxNode, Tree } from '#parser/node' export { globals as prelude } from '#prelude' -export type { Tree } from '@lezer/common' export { type Value, type Bytecode } from 'reefvm' export { toValue, fromValue, isValue, Scope, VM, bytecodeToString } from 'reefvm' @@ -41,7 +41,7 @@ export class Shrimp { return isValue(result) ? fromValue(result, this.vm) : result } - parse(code: string): Tree { + parse(code: string): SyntaxNode { return parseCode(code, this.globals) } @@ -95,17 +95,17 @@ export function compileCode(code: string, globals?: Record): Byteco return compiler.bytecode } -export function parseFile(path: string, globals?: Record): Tree { +export function parseFile(path: string, globals?: Record): SyntaxNode { const code = readFileSync(path, 'utf-8') return parseCode(code, globals) } -export function parseCode(code: string, globals?: Record): Tree { +export function parseCode(code: string, globals?: Record): SyntaxNode { const oldGlobals = [...parserGlobals] const globalNames = [...Object.keys(prelude), ...(globals ? Object.keys(globals) : [])] setParserGlobals(globalNames) - const result = parser.parse(code) + const result = parse(code) setParserGlobals(oldGlobals) return result