Parser 2.0 (Major Delezer) #52
|
|
@ -807,7 +807,7 @@ export class Compiler {
|
|||
const valueNode = node.firstChild!.nextSibling
|
||||
|
||||
// name= -> name
|
||||
const key = input.slice(keyNode!.from, keyNode!.to).slice(0, -1)
|
||||
const key = input.slice(keyNode!.from, keyNode!.to).replace(/\s*=$/, '')
|
||||
instructions.push(['PUSH', key])
|
||||
|
||||
instructions.push(...this.#compileNode(valueNode!, input))
|
||||
|
|
|
|||
|
|
@ -151,18 +151,22 @@ describe('array literals', () => {
|
|||
describe('dict literals', () => {
|
||||
test('work with numbers', () => {
|
||||
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 })
|
||||
})
|
||||
|
||||
test('work with strings', () => {
|
||||
expect("[a='one' b='two' c='three']").toEvaluateTo({ a: 'one', b: 'two', c: 'three' })
|
||||
expect("[a = 'one' b = 'two' c = 'three']").toEvaluateTo({ a: 'one', b: 'two', c: 'three' })
|
||||
})
|
||||
|
||||
test('work with identifiers', () => {
|
||||
expect('[a=one b=two c=three]').toEvaluateTo({ a: 'one', b: 'two', c: 'three' })
|
||||
expect('[a = one b = two c = three]').toEvaluateTo({ a: 'one', b: 'two', c: 'three' })
|
||||
})
|
||||
|
||||
test('can be nested', () => {
|
||||
expect('[a=one b=[two [c=three]]]').toEvaluateTo({ a: 'one', b: ['two', { c: 'three' }] })
|
||||
expect('[a = one b = [two [c = three]]]').toEvaluateTo({ a: 'one', b: ['two', { c: 'three' }] })
|
||||
})
|
||||
|
||||
test('can span multiple lines', () => {
|
||||
|
|
@ -171,6 +175,12 @@ describe('dict literals', () => {
|
|||
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 })
|
||||
})
|
||||
|
||||
test('empty dict', () => {
|
||||
|
|
@ -190,10 +200,12 @@ describe('dict literals', () => {
|
|||
|
||||
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 })
|
||||
})
|
||||
|
||||
test('expressions in dicts', () => {
|
||||
expect('[a=(1 + 2) b=(3 * 4)]').toEvaluateTo({ a: 3, b: 12 })
|
||||
expect('[a = (1 + 2) b = (3 * 4)]').toEvaluateTo({ a: 3, b: 12 })
|
||||
})
|
||||
|
||||
test('empty lines within dicts', () => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user