topNode.topNode
This commit is contained in:
parent
b7a65e07dc
commit
c127566abe
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user