topNode.topNode

This commit is contained in:
Chris Wanstrath 2025-11-06 21:30:50 -08:00
parent b7a65e07dc
commit c127566abe
2 changed files with 7 additions and 7 deletions

View File

@ -786,7 +786,7 @@ export class Compiler {
instructions.push(['PUSH', node]) instructions.push(['PUSH', node])
} else { } else {
const [input, topNode] = node const [input, topNode] = node
let child = topNode.topNode.firstChild let child = topNode.firstChild
while (child) { while (child) {
instructions.push(...this.#compileNode(child, input)) instructions.push(...this.#compileNode(child, input))
child = child.nextSibling child = child.nextSibling

View File

@ -1,13 +1,13 @@
import { parser } from '#parser/shrimp.ts' import { parser } from '#parser/shrimp.ts'
import type { Tree } from '@lezer/common' import type { SyntaxNode } from '@lezer/common'
import { isIdentStart, isIdentChar } from './tokenizer' import { isIdentStart, isIdentChar } from './tokenizer'
// Turns a { curly string } into separate tokens for interpolation // Turns a { curly string } into strings and nodes for interpolation
export const tokenizeCurlyString = (value: string): (string | [string, Tree])[] => { export const tokenizeCurlyString = (value: string): (string | [string, SyntaxNode])[] => {
let pos = 1 let pos = 1
let start = 1 let start = 1
let char = value[pos] let char = value[pos]
const tokens: (string | [string, Tree])[] = [] const tokens: (string | [string, SyntaxNode])[] = []
while (pos < value.length) { while (pos < value.length) {
if (char === '$') { if (char === '$') {
@ -37,7 +37,7 @@ export const tokenizeCurlyString = (value: string): (string | [string, Tree])[]
} }
const input = value.slice(start + 2, pos) // skip '$(' const input = value.slice(start + 2, pos) // skip '$('
tokens.push([input, parser.parse(input)]) tokens.push([input, parser.parse(input).topNode])
start = ++pos // skip ')' start = ++pos // skip ')'
} else { } else {
char = value[++pos] char = value[++pos]
@ -48,7 +48,7 @@ export const tokenizeCurlyString = (value: string): (string | [string, Tree])[]
char = value[++pos] char = value[++pos]
const input = value.slice(start + 1, pos) // skip '$' const input = value.slice(start + 1, pos) // skip '$'
tokens.push([input, parser.parse(input)]) tokens.push([input, parser.parse(input).topNode])
start = pos-- // backtrack and start over start = pos-- // backtrack and start over
} }
} }