This commit is contained in:
Corey Johnson 2025-10-02 15:25:04 -07:00
parent d89130b169
commit 7d23a86121
3 changed files with 30 additions and 14 deletions

View File

@ -201,15 +201,7 @@ export const inlineHints = [
child = child.nextSibling child = child.nextSibling
} }
console.log( return { commandShape, availableArgs }
`🌭`,
availableArgs.map((a) => a.name)
)
return {
commandShape,
availableArgs,
}
} }
}, },
{ {

View File

@ -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: default:
const isLowerCase = node.type.name[0] == node.type.name[0]?.toLowerCase() const isLowerCase = node.type.name[0] == node.type.name[0]?.toLowerCase()

View File

@ -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 { CommandPartial, Command, Identifier, UnquotedArg, insertedSemi } from './shrimp.terms'
import { matchingCommands } from '#editor/commands' 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 return ch >= 97 && ch <= 122 // a-z
} }
function isDigit(ch: number): boolean { const isDigit = (ch: number): boolean => {
return ch >= 48 && ch <= 57 // 0-9 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) const ch = input.peek(pos)
// Check if this is a high surrogate (0xD800-0xDBFF) // 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 return ch // Single code unit
} }
function isEmoji(ch: number): boolean { const isEmoji = (ch: number): boolean => {
return ( return (
// Basic Emoticons // Basic Emoticons
(ch >= 0x1f600 && ch <= 0x1f64f) || (ch >= 0x1f600 && ch <= 0x1f64f) ||