Compare commits
No commits in common. "a9df56346e3454342a965512d726deba42a10cd9" and "ee40dcc65c881f1d6f2bf764e596bc04480eb803" have entirely different histories.
a9df56346e
...
ee40dcc65c
|
|
@ -10,7 +10,6 @@ export type NodeType =
|
||||||
| 'FunctionCallWithBlock'
|
| 'FunctionCallWithBlock'
|
||||||
| 'PositionalArg'
|
| 'PositionalArg'
|
||||||
| 'NamedArg'
|
| 'NamedArg'
|
||||||
| 'NamedArgPrefix'
|
|
||||||
|
|
||||||
| 'FunctionDef'
|
| 'FunctionDef'
|
||||||
| 'Params'
|
| 'Params'
|
||||||
|
|
|
||||||
|
|
@ -305,13 +305,6 @@ export class Parser {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// [ a = true ]
|
|
||||||
const next = this.peek(peek)
|
|
||||||
if (next?.type === $T.Operator && next.value === '=') {
|
|
||||||
isDict = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
// probably an array
|
// probably an array
|
||||||
if (curr.type !== $T.Comment && curr.type !== $T.Semicolon && curr.type !== $T.Newline)
|
if (curr.type !== $T.Comment && curr.type !== $T.Semicolon && curr.type !== $T.Newline)
|
||||||
break
|
break
|
||||||
|
|
@ -452,20 +445,8 @@ export class Parser {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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())
|
values.push(this.is($T.NamedArgPrefix) ? this.namedArg() : this.arg())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const close = this.expect($T.CloseBracket)
|
const close = this.expect($T.CloseBracket)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -387,26 +387,6 @@ describe('dict literals', () => {
|
||||||
Number 3
|
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', () => {
|
test('empty dict', () => {
|
||||||
expect('[=]').toMatchTree(`
|
expect('[=]').toMatchTree(`
|
||||||
Dict [=]
|
Dict [=]
|
||||||
|
|
|
||||||
|
|
@ -191,8 +191,8 @@ export function formatValue(value: Value, inner = false): string {
|
||||||
return `${colors.blue}[${colors.reset}${items}${colors.blue}]${colors.reset}`
|
return `${colors.blue}[${colors.reset}${items}${colors.blue}]${colors.reset}`
|
||||||
}
|
}
|
||||||
case 'dict': {
|
case 'dict': {
|
||||||
const entries = Array.from(value.value.entries()).reverse()
|
const entries = Array.from(value.value.entries())
|
||||||
.map(([k, v]) => `${k.trim()}${colors.blue}=${colors.reset}${formatValue(v, true)}`)
|
.map(([k, v]) => `${k}${colors.blue}=${colors.reset}${formatValue(v, true)}`)
|
||||||
.join(' ')
|
.join(' ')
|
||||||
if (entries.length === 0)
|
if (entries.length === 0)
|
||||||
return `${colors.blue}[=]${colors.reset}`
|
return `${colors.blue}[=]${colors.reset}`
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user