[ = ]
This commit is contained in:
parent
982054eb54
commit
8112515278
|
|
@ -470,7 +470,18 @@ export class Compiler {
|
||||||
|
|
||||||
case terms.Array: {
|
case terms.Array: {
|
||||||
const children = getAllChildren(node)
|
const children = getAllChildren(node)
|
||||||
// todo: [ = ]
|
|
||||||
|
// We can easily parse [=] as an empty dict, but `[ = ]` is tougher.
|
||||||
|
// = can be a valid word, and also valid in words, so for now we cheat
|
||||||
|
// and check for arrays that look like `[ = ]` to interpret them as
|
||||||
|
// empty dicts
|
||||||
|
if (children.length === 1 && children[0].name === 'Word') {
|
||||||
|
const child = children[0]
|
||||||
|
if (input.slice(child.from, child.to) === '=') {
|
||||||
|
return [['MAKE_DICT', 0]]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const instructions: ProgramItem[] = children.map((x) => this.#compileNode(x, input)).flat()
|
const instructions: ProgramItem[] = children.map((x) => this.#compileNode(x, input)).flat()
|
||||||
instructions.push(['MAKE_ARRAY', children.length])
|
instructions.push(['MAKE_ARRAY', children.length])
|
||||||
return instructions
|
return instructions
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,7 @@ describe('dict literals', () => {
|
||||||
test('empty dict', () => {
|
test('empty dict', () => {
|
||||||
expect('[=]').toEvaluateTo({})
|
expect('[=]').toEvaluateTo({})
|
||||||
expect('[ = ]').toEvaluateTo({})
|
expect('[ = ]').toEvaluateTo({})
|
||||||
|
})
|
||||||
|
|
||||||
test('mixed types', () => {
|
test('mixed types', () => {
|
||||||
expect("[a=1 b='two' c=three d=true e=null]").toEvaluateTo({
|
expect("[a=1 b='two' c=three d=true e=null]").toEvaluateTo({
|
||||||
|
|
@ -136,6 +137,7 @@ describe('dict literals', () => {
|
||||||
d: true,
|
d: true,
|
||||||
e: null,
|
e: null,
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
test('semicolons as separators', () => {
|
test('semicolons as separators', () => {
|
||||||
expect('[a=1; b=2; c=3]').toEvaluateTo({ a: 1, b: 2, c: 3 })
|
expect('[a=1; b=2; c=3]').toEvaluateTo({ a: 1, b: 2, c: 3 })
|
||||||
|
|
@ -153,5 +155,3 @@ describe('dict literals', () => {
|
||||||
c=3]`).toEvaluateTo({ a: 1, b: 2, c: 3 })
|
c=3]`).toEvaluateTo({ a: 1, b: 2, c: 3 })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user