From 7d23a861219fbac39b7a7ddc627c1d80e518469e Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 2 Oct 2025 15:25:04 -0700 Subject: [PATCH] wip --- src/editor/plugins/inlineHints.tsx | 10 +--------- src/evaluator/evaluator.ts | 24 ++++++++++++++++++++++++ src/parser/tokenizers.ts | 10 +++++----- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/editor/plugins/inlineHints.tsx b/src/editor/plugins/inlineHints.tsx index 5128cab..e96e491 100644 --- a/src/editor/plugins/inlineHints.tsx +++ b/src/editor/plugins/inlineHints.tsx @@ -201,15 +201,7 @@ export const inlineHints = [ child = child.nextSibling } - console.log( - `🌭`, - availableArgs.map((a) => a.name) - ) - - return { - commandShape, - availableArgs, - } + return { commandShape, availableArgs } } }, { diff --git a/src/evaluator/evaluator.ts b/src/evaluator/evaluator.ts index 9dc6c3e..d79a7a3 100644 --- a/src/evaluator/evaluator.ts +++ b/src/evaluator/evaluator.ts @@ -139,6 +139,30 @@ const evaluateNode = (node: SyntaxNode, input: string, context: Context): any => } } + case terms.CommandCall: { + const commandNode = assertNode(node.firstChild, 'Command') + const commandIdentifier = assertNode(commandNode.firstChild, 'Identifier') + const command = input.slice(commandIdentifier.from, commandIdentifier.to) + + const args = getChildren(node) + .slice(1) + .map((argNode) => { + if (argNode.type.id === terms.Arg) { + return evaluateNode(argNode, input, context) + } else if (argNode.type.id === terms.NamedArg) { + return evaluateNode(argNode, input, context) + } else { + throw new RuntimeError( + `Unexpected argument type: ${argNode.type.name}`, + input, + argNode.from, + argNode.to + ) + } + }) + const commandName = input.slice(commandIdentifier.from, commandIdentifier.to) + } + default: const isLowerCase = node.type.name[0] == node.type.name[0]?.toLowerCase() diff --git a/src/parser/tokenizers.ts b/src/parser/tokenizers.ts index 01cb73f..0db93eb 100644 --- a/src/parser/tokenizers.ts +++ b/src/parser/tokenizers.ts @@ -1,4 +1,4 @@ -import { ExternalTokenizer, InputStream } from '@lezer/lr' +import { ExternalTokenizer, InputStream, Stack } from '@lezer/lr' import { CommandPartial, Command, Identifier, UnquotedArg, insertedSemi } from './shrimp.terms' import { matchingCommands } from '#editor/commands' @@ -88,15 +88,15 @@ export const insertSemicolon = new ExternalTokenizer((input: InputStream, stack: } }) -function isLowercaseLetter(ch: number): boolean { +const isLowercaseLetter = (ch: number): boolean => { return ch >= 97 && ch <= 122 // a-z } -function isDigit(ch: number): boolean { +const isDigit = (ch: number): boolean => { return ch >= 48 && ch <= 57 // 0-9 } -function getFullCodePoint(input: InputStream, pos: number): number { +const getFullCodePoint = (input: InputStream, pos: number): number => { const ch = input.peek(pos) // Check if this is a high surrogate (0xD800-0xDBFF) @@ -112,7 +112,7 @@ function getFullCodePoint(input: InputStream, pos: number): number { return ch // Single code unit } -function isEmoji(ch: number): boolean { +const isEmoji = (ch: number): boolean => { return ( // Basic Emoticons (ch >= 0x1f600 && ch <= 0x1f64f) ||