enable [ a = true ]
This commit is contained in:
parent
728c5df9eb
commit
688181654e
|
|
@ -10,6 +10,7 @@ export type NodeType =
|
|||
| 'FunctionCallWithBlock'
|
||||
| 'PositionalArg'
|
||||
| 'NamedArg'
|
||||
| 'NamedArgPrefix'
|
||||
|
||||
| 'FunctionDef'
|
||||
| 'Params'
|
||||
|
|
|
|||
|
|
@ -305,6 +305,13 @@ export class Parser {
|
|||
break
|
||||
}
|
||||
|
||||
// [ a = true ]
|
||||
const next = this.peek(peek)
|
||||
if (next?.type === $T.Operator && next.value === '=') {
|
||||
isDict = true
|
||||
break
|
||||
}
|
||||
|
||||
// probably an array
|
||||
if (curr.type !== $T.Comment && curr.type !== $T.Semicolon && curr.type !== $T.Newline)
|
||||
break
|
||||
|
|
@ -445,7 +452,19 @@ export class Parser {
|
|||
continue
|
||||
}
|
||||
|
||||
values.push(this.is($T.NamedArgPrefix) ? this.namedArg() : this.arg())
|
||||
// check for named arg with space after it (vs connected)
|
||||
if (this.nextIs($T.Operator, '=')) {
|
||||
const ident = this.identifier()
|
||||
const op = this.op('=')
|
||||
const val = this.arg(true)
|
||||
const prefix = new SyntaxNode('NamedArgPrefix', ident.from, op.to)
|
||||
const node = new SyntaxNode('NamedArg', ident.from, val.to)
|
||||
node.add(prefix)
|
||||
node.add(val)
|
||||
values.push(node)
|
||||
} else {
|
||||
values.push(this.is($T.NamedArgPrefix) ? this.namedArg() : this.arg())
|
||||
}
|
||||
}
|
||||
|
||||
const close = this.expect($T.CloseBracket)
|
||||
|
|
|
|||
|
|
@ -387,6 +387,26 @@ describe('dict literals', () => {
|
|||
Number 3
|
||||
`)
|
||||
})
|
||||
|
||||
test('can have spaces between equals', () => {
|
||||
expect(`[
|
||||
a = 1
|
||||
b = 2
|
||||
c = 3
|
||||
]`).toMatchTree(`
|
||||
Dict
|
||||
NamedArg
|
||||
NamedArgPrefix a =
|
||||
Number 1
|
||||
NamedArg
|
||||
NamedArgPrefix b =
|
||||
Number 2
|
||||
NamedArg
|
||||
NamedArgPrefix c =
|
||||
Number 3
|
||||
`)
|
||||
})
|
||||
|
||||
test('empty dict', () => {
|
||||
expect('[=]').toMatchTree(`
|
||||
Dict [=]
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user