Merge branch 'list-and-dict-literals' into prelude
This commit is contained in:
commit
f08b16824a
13
CLAUDE.md
13
CLAUDE.md
|
|
@ -207,6 +207,19 @@ Implementation files:
|
||||||
|
|
||||||
**Why this matters**: This enables shell-like file paths (`readme.txt`) while supporting dictionary/array access (`config.path`) without quotes, determined entirely at parse time based on lexical scope.
|
**Why this matters**: This enables shell-like file paths (`readme.txt`) while supporting dictionary/array access (`config.path`) without quotes, determined entirely at parse time based on lexical scope.
|
||||||
|
|
||||||
|
**Array and dict literals**: Square brackets `[]` create both arrays and dicts, distinguished by content:
|
||||||
|
- **Arrays**: Space/newline/semicolon-separated args that work like calling a function → `[1 2 3]` (call functions using parens eg `[1 (double 4) 200]`)
|
||||||
|
- **Dicts**: NamedArg syntax (key=value pairs) → `[a=1 b=2]`
|
||||||
|
- **Empty array**: `[]` (standard empty brackets)
|
||||||
|
- **Empty dict**: `[=]` (exactly this, no spaces)
|
||||||
|
|
||||||
|
Implementation details:
|
||||||
|
- Grammar rules (shrimp.grammar:194-201): Dict uses `NamedArg` nodes, Array uses `expression` nodes
|
||||||
|
- Parser distinguishes at parse time based on whether first element contains `=`
|
||||||
|
- Both support multiline, comments, and nesting
|
||||||
|
- Separators: spaces, newlines (`\n`), or semicolons (`;`) work interchangeably
|
||||||
|
- Test files: `src/parser/tests/literals.test.ts` and `src/compiler/tests/literals.test.ts`
|
||||||
|
|
||||||
**EOF handling**: The grammar uses `(statement | newlineOrSemicolon)+ eof?` to handle empty lines and end-of-file without infinite loops.
|
**EOF handling**: The grammar uses `(statement | newlineOrSemicolon)+ eof?` to handle empty lines and end-of-file without infinite loops.
|
||||||
|
|
||||||
## Compiler Architecture
|
## Compiler Architecture
|
||||||
|
|
|
||||||
|
|
@ -42,13 +42,13 @@ a-file = file.txt
|
||||||
3
|
3
|
||||||
|
|
||||||
# symbols can be assigned to functions. The body of the function comes after a colon `:`
|
# symbols can be assigned to functions. The body of the function comes after a colon `:`
|
||||||
add = fn x y: x + y
|
add = do x y: x + y
|
||||||
add 1 2
|
add 1 2
|
||||||
---
|
---
|
||||||
3
|
3
|
||||||
|
|
||||||
# Functions can have multiple lines, they are terminated with `end`
|
# Functions can have multiple lines, they are terminated with `end`
|
||||||
sub = fn x y:
|
sub = do x y:
|
||||||
x - y
|
x - y
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -82,9 +82,25 @@ add 1 (sub 5 2)
|
||||||
4
|
4
|
||||||
|
|
||||||
|
|
||||||
|
# Arrays use square brackets with space-separated elements
|
||||||
|
numbers = [1 2 3]
|
||||||
|
shopping-list = [apples bananas carrots]
|
||||||
|
empty-array = []
|
||||||
|
|
||||||
|
# Dicts use square brackets with key=value pairs
|
||||||
|
config = [name=Shrimp version=1.0 debug=true]
|
||||||
|
empty-dict = [=]
|
||||||
|
|
||||||
|
# Nested structures work naturally
|
||||||
|
nested = [
|
||||||
|
users=[
|
||||||
|
[name=Alice age=30]
|
||||||
|
[name=Bob age=25]
|
||||||
|
]
|
||||||
|
settings=[debug=true timeout=5000]
|
||||||
|
]
|
||||||
|
|
||||||
# HOLD UP
|
# HOLD UP
|
||||||
|
|
||||||
- how do we handle arrays?
|
|
||||||
- how do we handle hashes?
|
|
||||||
- conditionals
|
- conditionals
|
||||||
- loops
|
- loops
|
||||||
1
packages/ReefVM
Submodule
1
packages/ReefVM
Submodule
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 97b6722a113417398a1c47d583bfe07a906f87a0
|
||||||
|
|
@ -468,6 +468,44 @@ export class Compiler {
|
||||||
return instructions
|
return instructions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case terms.Array: {
|
||||||
|
const children = getAllChildren(node)
|
||||||
|
|
||||||
|
// We can easily parse [=] as an empty dict, but `[ = ]` is tougher.
|
||||||
|
// = can be a valid word, and is also valid inside 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()
|
||||||
|
instructions.push(['MAKE_ARRAY', children.length])
|
||||||
|
return instructions
|
||||||
|
}
|
||||||
|
|
||||||
|
case terms.Dict: {
|
||||||
|
const children = getAllChildren(node)
|
||||||
|
const instructions: ProgramItem[] = []
|
||||||
|
|
||||||
|
children.forEach((node) => {
|
||||||
|
const keyNode = node.firstChild
|
||||||
|
const valueNode = node.firstChild!.nextSibling
|
||||||
|
|
||||||
|
// name= -> name
|
||||||
|
const key = input.slice(keyNode!.from, keyNode!.to).slice(0, -1)
|
||||||
|
instructions.push(['PUSH', key])
|
||||||
|
|
||||||
|
instructions.push(...this.#compileNode(valueNode!, input))
|
||||||
|
})
|
||||||
|
|
||||||
|
instructions.push(['MAKE_DICT', children.length])
|
||||||
|
return instructions
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new CompilerError(
|
throw new CompilerError(
|
||||||
`Compiler doesn't know how to handle a "${node.type.name}" node.`,
|
`Compiler doesn't know how to handle a "${node.type.name}" node.`,
|
||||||
|
|
|
||||||
157
src/compiler/tests/literals.test.ts
Normal file
157
src/compiler/tests/literals.test.ts
Normal file
|
|
@ -0,0 +1,157 @@
|
||||||
|
import { describe } from 'bun:test'
|
||||||
|
import { expect, test } from 'bun:test'
|
||||||
|
|
||||||
|
describe('array literals', () => {
|
||||||
|
test('work with numbers', () => {
|
||||||
|
expect('[1 2 3]').toEvaluateTo([1, 2, 3])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('work with strings', () => {
|
||||||
|
expect("['one' 'two' 'three']").toEvaluateTo(['one', 'two', 'three'])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('work with identifiers', () => {
|
||||||
|
expect('[one two three]').toEvaluateTo(['one', 'two', 'three'])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('can be nested', () => {
|
||||||
|
expect('[one [two [three]]]').toEvaluateTo(['one', ['two', ['three']]])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('can span multiple lines', () => {
|
||||||
|
expect(`[
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
]`).toEvaluateTo([1, 2, 3])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('can span multiple w/o calling functions', () => {
|
||||||
|
expect(`[
|
||||||
|
one
|
||||||
|
two
|
||||||
|
three
|
||||||
|
]`).toEvaluateTo(['one', 'two', 'three'])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('empty arrays', () => {
|
||||||
|
expect('[]').toEvaluateTo([])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('mixed types', () => {
|
||||||
|
expect("[1 'two' three true null]").toEvaluateTo([1, 'two', 'three', true, null])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('semicolons as separators', () => {
|
||||||
|
expect('[1; 2; 3]').toEvaluateTo([1, 2, 3])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('expressions in arrays', () => {
|
||||||
|
expect('[(1 + 2) (3 * 4)]').toEvaluateTo([3, 12])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('mixed separators - spaces and newlines', () => {
|
||||||
|
expect(`[1 2
|
||||||
|
3 4]`).toEvaluateTo([1, 2, 3, 4])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('mixed separators - spaces and semicolons', () => {
|
||||||
|
expect('[1 2; 3 4]').toEvaluateTo([1, 2, 3, 4])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('empty lines within arrays', () => {
|
||||||
|
expect(`[1
|
||||||
|
|
||||||
|
2]`).toEvaluateTo([1, 2])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('comments within arrays', () => {
|
||||||
|
expect(`[1 # first
|
||||||
|
2 # second
|
||||||
|
]`).toEvaluateTo([1, 2])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('complex nested multiline', () => {
|
||||||
|
expect(`[
|
||||||
|
[1 2]
|
||||||
|
[3 4]
|
||||||
|
[5 6]
|
||||||
|
]`).toEvaluateTo([
|
||||||
|
[1, 2],
|
||||||
|
[3, 4],
|
||||||
|
[5, 6],
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('boolean and null literals', () => {
|
||||||
|
expect('[true false null]').toEvaluateTo([true, false, null])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('regex literals', () => {
|
||||||
|
expect('[//[0-9]+//]').toEvaluateTo([/[0-9]+/])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('trailing newlines', () => {
|
||||||
|
expect(`[
|
||||||
|
1
|
||||||
|
2
|
||||||
|
]`).toEvaluateTo([1, 2])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('dict literals', () => {
|
||||||
|
test('work with numbers', () => {
|
||||||
|
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' })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('work with identifiers', () => {
|
||||||
|
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' }] })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('can span multiple lines', () => {
|
||||||
|
expect(`[
|
||||||
|
a=1
|
||||||
|
b=2
|
||||||
|
c=3
|
||||||
|
]`).toEvaluateTo({ a: 1, b: 2, c: 3 })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('empty dict', () => {
|
||||||
|
expect('[=]').toEvaluateTo({})
|
||||||
|
expect('[ = ]').toEvaluateTo({})
|
||||||
|
})
|
||||||
|
|
||||||
|
test('mixed types', () => {
|
||||||
|
expect("[a=1 b='two' c=three d=true e=null]").toEvaluateTo({
|
||||||
|
a: 1,
|
||||||
|
b: 'two',
|
||||||
|
c: 'three',
|
||||||
|
d: true,
|
||||||
|
e: null,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
test('semicolons as separators', () => {
|
||||||
|
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 })
|
||||||
|
})
|
||||||
|
|
||||||
|
test('empty lines within dicts', () => {
|
||||||
|
expect(`[a=1
|
||||||
|
|
||||||
|
b=2
|
||||||
|
|
||||||
|
c=3]`).toEvaluateTo({ a: 1, b: 2, c: 3 })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
@ -191,6 +191,15 @@ EscapeSeq {
|
||||||
"\\" ("$" | "n" | "t" | "r" | "\\" | "'")
|
"\\" ("$" | "n" | "t" | "r" | "\\" | "'")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Dict {
|
||||||
|
"[=]" |
|
||||||
|
"[" newlineOrSemicolon* NamedArg (newlineOrSemicolon | NamedArg)* "]"
|
||||||
|
}
|
||||||
|
|
||||||
|
Array {
|
||||||
|
"[" newlineOrSemicolon* (expression (newlineOrSemicolon | expression)*)? "]"
|
||||||
|
}
|
||||||
|
|
||||||
// We need expressionWithoutIdentifier to avoid conflicts in consumeToTerminator.
|
// We need expressionWithoutIdentifier to avoid conflicts in consumeToTerminator.
|
||||||
// Without this, when parsing "my-var" at statement level, the parser can't decide:
|
// Without this, when parsing "my-var" at statement level, the parser can't decide:
|
||||||
// - ambiguousFunctionCall → FunctionCallOrIdentifier → Identifier
|
// - ambiguousFunctionCall → FunctionCallOrIdentifier → Identifier
|
||||||
|
|
@ -200,7 +209,7 @@ EscapeSeq {
|
||||||
// to go through ambiguousFunctionCall (which is what we want semantically).
|
// to go through ambiguousFunctionCall (which is what we want semantically).
|
||||||
// Yes, it is annoying and I gave up trying to use GLR to fix it.
|
// Yes, it is annoying and I gave up trying to use GLR to fix it.
|
||||||
expressionWithoutIdentifier {
|
expressionWithoutIdentifier {
|
||||||
ParenExpr | Word | String | Number | Boolean | Regex | @specialize[@name=Null]<Identifier, "null">
|
ParenExpr | Word | String | Number | Boolean | Regex | Dict | Array | @specialize[@name=Null]<Identifier, "null">
|
||||||
}
|
}
|
||||||
|
|
||||||
block {
|
block {
|
||||||
|
|
|
||||||
|
|
@ -31,19 +31,21 @@ export const
|
||||||
EscapeSeq = 29,
|
EscapeSeq = 29,
|
||||||
Boolean = 30,
|
Boolean = 30,
|
||||||
Regex = 31,
|
Regex = 31,
|
||||||
Null = 32,
|
Dict = 32,
|
||||||
ConditionalOp = 33,
|
NamedArg = 33,
|
||||||
FunctionDef = 34,
|
NamedArgPrefix = 34,
|
||||||
Params = 35,
|
FunctionDef = 35,
|
||||||
colon = 36,
|
Params = 36,
|
||||||
keyword = 50,
|
colon = 37,
|
||||||
PositionalArg = 38,
|
keyword = 52,
|
||||||
Underscore = 39,
|
Underscore = 39,
|
||||||
NamedArg = 40,
|
Array = 40,
|
||||||
NamedArgPrefix = 41,
|
Null = 41,
|
||||||
IfExpr = 43,
|
ConditionalOp = 42,
|
||||||
SingleLineThenBlock = 45,
|
PositionalArg = 43,
|
||||||
ThenBlock = 46,
|
IfExpr = 45,
|
||||||
ElseIfExpr = 47,
|
SingleLineThenBlock = 47,
|
||||||
ElseExpr = 49,
|
ThenBlock = 48,
|
||||||
Assign = 51
|
ElseIfExpr = 49,
|
||||||
|
ElseExpr = 51,
|
||||||
|
Assign = 53
|
||||||
|
|
|
||||||
|
|
@ -4,24 +4,24 @@ import {operatorTokenizer} from "./operatorTokenizer"
|
||||||
import {tokenizer, specializeKeyword} from "./tokenizer"
|
import {tokenizer, specializeKeyword} from "./tokenizer"
|
||||||
import {trackScope} from "./scopeTracker"
|
import {trackScope} from "./scopeTracker"
|
||||||
import {highlighting} from "./highlight"
|
import {highlighting} from "./highlight"
|
||||||
const spec_Identifier = {__proto__:null,null:64, end:74, if:88, elseif:96, else:100}
|
const spec_Identifier = {__proto__:null,end:76, null:82, if:92, elseif:100, else:104}
|
||||||
export const parser = LRParser.deserialize({
|
export const parser = LRParser.deserialize({
|
||||||
version: 14,
|
version: 14,
|
||||||
states: "/SQYQbOOO!TOpO'#CqO#aQcO'#CtO$ZOSO'#CvO%aQcO'#DsOOQa'#Ds'#DsO&gQcO'#DrO'OQRO'#CuO'^QcO'#DnO'uQbO'#D{OOQ`'#DO'#DOO'}QbO'#CsOOQ`'#Do'#DoO(oQbO'#DnO(}QbO'#EROOQ`'#DX'#DXO)lQRO'#DaOOQ`'#Dn'#DnO)qQQO'#DmOOQ`'#Dm'#DmOOQ`'#Db'#DbQYQbOOO)yObO,59]OOQa'#Dr'#DrOOQ`'#DS'#DSO*RQbO'#DUOOQ`'#EQ'#EQOOQ`'#Df'#DfO*]QbO,59[O*pQbO'#CxO*xQWO'#CyOOOO'#Du'#DuOOOO'#Dc'#DcO+^OSO,59bOOQa,59b,59bO(}QbO,59aO(}QbO,59aOOQ`'#Dd'#DdO+lQbO'#DPO+tQQO,5:gO+yQRO,59_O-`QRO'#CuO-pQRO,59_O-|QQO,59_O.RQQO,59_O.ZQbO'#DgO.fQbO,59ZO.wQRO,5:mO/OQQO,5:mO/TQbO,59{OOQ`,5:X,5:XOOQ`-E7`-E7`OOQa1G.w1G.wOOQ`,59p,59pOOQ`-E7d-E7dOOOO,59d,59dOOOO,59e,59eOOOO-E7a-E7aOOQa1G.|1G.|OOQa1G.{1G.{O/_QcO1G.{OOQ`-E7b-E7bO/yQbO1G0ROOQa1G.y1G.yO(}QbO,59iO(}QbO,59iO!YQbO'#CtO$iQbO'#CpOOQ`,5:R,5:ROOQ`-E7e-E7eO0WQbO1G0XOOQ`1G/g1G/gO0eQb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y)c)m)w*Q*XPPPP*_*c*wPP+Z,dP-XPPPPPPPP-]-]-pPP-x.P.PdcOg!Y!e!x!{#W#[#t#uR!S]i^O]g!U!Y!e!x!{#W#[#t#ufQO]g!Y!e!x!{#W#[#t#utjQVW`iny|}!O!i!n!r!s!t!u#O#fR!t!UfWO]g!Y!e!x!{#W#[#t#utXQVW`iny|}!O!i!n!r!s!t!u#O#fQ!`oR!u!Ud[Og!Y!e!x!{#W#[#t#uQ!R]Q!o}R!p!O!]XOQVW]`giny|}!O!Y!e!i!n!r!s!t!u!x!{#O#W#[#f#t#uTqRsYlQWn!t!uQzVQ!gyX!jz!g!k!|dcOg!Y!e!x!{#W#[#t#uYkQWn!t!uQ!S]R!^iRwSQ!S]Q!X`Q#S!sR#m#fZlQWn!t!uecOg!Y!e!x!{#W#[#t#uR#V!xQ#b#WQ#v#tR#w#uT#g#b#hQ#k#bR#p#hQgOR![gQsRR!bsQyVR!fyQvSR!dvW#[!{#W#t#uR#d#[Q!kzQ!|!gT#Q!k!|Q!n|Q#O!iT#R!n#OWnQW!t!uR!_nS!V_!TR!w!VQ#h#bR#n#hTfOgSdOgQ!y!YQ!z!eQ#U!xZ#Z!{#W#[#t#ud_Og!Y!e!x!{#W#[#t#uQ!T]R!v!UdZOg!Y!e!x!{#W#[#t#uYkQWn!t!uQ|VQ!Q]Q!W`Q!^iQ!iyW!m|!i!n#OQ!o}Q!p!OQ#S!rQ#T!sR#l#fdYOg!Y!e!x!{#W#[#t#utjQVW`iny|}!O!i!n!r!s!t!u#O#fR!P]TrRssTOQW]gin!Y!e!t!u!x!{#W#[#t#uQ#]!{V#a#W#t#uZmQWn!t!ueaOg!Y!e!x!{#W#[#t#u",
|
||||||
nodeNames: "⚠ Star Slash Plus Minus And Or Eq Neq Lt Lte Gt Gte Identifier AssignableIdentifier Word IdentifierBeforeDot Do Program PipeExpr FunctionCall DotGet Number ParenExpr FunctionCallOrIdentifier BinOp String StringFragment Interpolation EscapeSeq Boolean Regex Null ConditionalOp FunctionDef Params colon keyword PositionalArg Underscore NamedArg NamedArgPrefix operator IfExpr keyword SingleLineThenBlock ThenBlock ElseIfExpr keyword ElseExpr keyword Assign",
|
nodeNames: "⚠ Star Slash Plus Minus And Or Eq Neq Lt Lte Gt Gte Identifier AssignableIdentifier Word IdentifierBeforeDot Do Program PipeExpr FunctionCall DotGet Number ParenExpr FunctionCallOrIdentifier BinOp String StringFragment Interpolation EscapeSeq Boolean Regex Dict NamedArg NamedArgPrefix FunctionDef Params colon keyword Underscore Array Null ConditionalOp PositionalArg operator IfExpr keyword SingleLineThenBlock ThenBlock ElseIfExpr keyword ElseExpr keyword Assign",
|
||||||
maxTerm: 85,
|
maxTerm: 93,
|
||||||
context: trackScope,
|
context: trackScope,
|
||||||
nodeProps: [
|
nodeProps: [
|
||||||
["closedBy", 36,"end"]
|
["closedBy", 37,"end"]
|
||||||
],
|
],
|
||||||
propSources: [highlighting],
|
propSources: [highlighting],
|
||||||
skippedNodes: [0],
|
skippedNodes: [0],
|
||||||
repeatNodeCount: 7,
|
repeatNodeCount: 10,
|
||||||
tokenData: ">i~RzOX#uXY$dYZ$}Zp#upq$dqs#ust%htu'Puw#uwx'Uxy'Zyz'tz{#u{|(_|}#u}!O(_!O!P#u!P!Q+R!Q![(|![!]3n!]!^$}!^#O#u#O#P4X#P#R#u#R#S4^#S#T#u#T#Y4w#Y#Z6V#Z#b4w#b#c:e#c#f4w#f#g;[#g#h4w#h#i<R#i#o4w#o#p#u#p#q=y#q;'S#u;'S;=`$^<%l~#u~O#u~~>dS#zUkSOt#uuw#ux#O#u#P;'S#u;'S;=`$^<%lO#uS$aP;=`<%l#u^$kUkS!_YOt#uuw#ux#O#u#P;'S#u;'S;=`$^<%lO#uU%UUkS!qQOt#uuw#ux#O#u#P;'S#u;'S;=`$^<%lO#u^%oZkS!`YOY%hYZ#uZt%htu&buw%hwx&bx#O%h#O#P&b#P;'S%h;'S;=`&y<%lO%hY&gS!`YOY&bZ;'S&b;'S;=`&s<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7^#`#a:_#a#o7^#o;'S#{;'S;=`$d<%lO#{U:d[kSOt#{uw#{x!_#{!_!`8R!`#O#{#P#T#{#T#g7^#g#h;Y#h#o7^#o;'S#{;'S;=`$d<%lO#{U;_[kSOt#{uw#{x!_#{!_!`8R!`#O#{#P#T#{#T#X7^#X#Y<T#Y#o7^#o;'S#{;'S;=`$d<%lO#{U<[YnQkSOt#{uw#{x!_#{!_!`8R!`#O#{#P#T#{#T#o7^#o;'S#{;'S;=`$d<%lO#{^=RY!qWkSOt#{uw#{x!_#{!_!`8R!`#O#{#P#T#{#T#o7^#o;'S#{;'S;=`$d<%lO#{^=xY!sWkSOt#{uw#{x!_#{!_!`8R!`#O#{#P#T#{#T#o7^#o;'S#{;'S;=`$d<%lO#{^>o[!rWkSOt#{uw#{x!_#{!_!`8R!`#O#{#P#T#{#T#f7^#f#g?e#g#o7^#o;'S#{;'S;=`$d<%lO#{U?j[kSOt#{uw#{x!_#{!_!`8R!`#O#{#P#T#{#T#i7^#i#j;Y#j#o7^#o;'S#{;'S;=`$d<%lO#{U@gU|QkSOt#{uw#{x#O#{#P;'S#{;'S;=`$d<%lO#{~AOO#P~",
|
||||||
tokenizers: [operatorTokenizer, 1, 2, 3, tokenizer, new LocalTokenGroup("[~RP!O!PU~ZO!d~~", 11)],
|
tokenizers: [operatorTokenizer, 1, 2, 3, tokenizer, new LocalTokenGroup("[~RP!O!PU~ZO!i~~", 11)],
|
||||||
topRules: {"Program":[0,18]},
|
topRules: {"Program":[0,18]},
|
||||||
specialized: [{term: 13, get: (value: any, stack: any) => (specializeKeyword(value, stack) << 1), external: specializeKeyword},{term: 13, get: (value: keyof typeof spec_Identifier) => spec_Identifier[value] || -1}],
|
specialized: [{term: 13, get: (value: any, stack: any) => (specializeKeyword(value, stack) << 1), external: specializeKeyword},{term: 13, get: (value: keyof typeof spec_Identifier) => spec_Identifier[value] || -1}],
|
||||||
tokenPrec: 860
|
tokenPrec: 1008
|
||||||
})
|
})
|
||||||
|
|
|
||||||
492
src/parser/tests/literals.test.ts
Normal file
492
src/parser/tests/literals.test.ts
Normal file
|
|
@ -0,0 +1,492 @@
|
||||||
|
import { expect, describe, test } from 'bun:test'
|
||||||
|
|
||||||
|
import '../shrimp.grammar' // Importing this so changes cause it to retest!
|
||||||
|
|
||||||
|
describe('array literals', () => {
|
||||||
|
test('work with numbers', () => {
|
||||||
|
expect('[1 2 3]').toMatchTree(`
|
||||||
|
Array
|
||||||
|
Number 1
|
||||||
|
Number 2
|
||||||
|
Number 3
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('work with strings', () => {
|
||||||
|
expect("['one' 'two' 'three']").toMatchTree(`
|
||||||
|
Array
|
||||||
|
String
|
||||||
|
StringFragment one
|
||||||
|
String
|
||||||
|
StringFragment two
|
||||||
|
String
|
||||||
|
StringFragment three
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('work with identifiers', () => {
|
||||||
|
expect('[one two three]').toMatchTree(`
|
||||||
|
Array
|
||||||
|
Identifier one
|
||||||
|
Identifier two
|
||||||
|
Identifier three
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('can be nested', () => {
|
||||||
|
expect('[one [two [three]]]').toMatchTree(`
|
||||||
|
Array
|
||||||
|
Identifier one
|
||||||
|
Array
|
||||||
|
Identifier two
|
||||||
|
Array
|
||||||
|
Identifier three
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('can span multiple lines', () => {
|
||||||
|
expect(`[
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
]`).toMatchTree(`
|
||||||
|
Array
|
||||||
|
Number 1
|
||||||
|
Number 2
|
||||||
|
Number 3
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('can span multiple w/o calling functions', () => {
|
||||||
|
expect(`[
|
||||||
|
one
|
||||||
|
two
|
||||||
|
three
|
||||||
|
]`).toMatchTree(`
|
||||||
|
Array
|
||||||
|
Identifier one
|
||||||
|
Identifier two
|
||||||
|
Identifier three
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('empty arrays', () => {
|
||||||
|
expect('[]').toMatchTree(`
|
||||||
|
Array []
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('mixed types', () => {
|
||||||
|
expect("[1 'two' three true null]").toMatchTree(`
|
||||||
|
Array
|
||||||
|
Number 1
|
||||||
|
String
|
||||||
|
StringFragment two
|
||||||
|
Identifier three
|
||||||
|
Boolean true
|
||||||
|
Null null
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('semicolons as separators', () => {
|
||||||
|
expect('[1; 2; 3]').toMatchTree(`
|
||||||
|
Array
|
||||||
|
Number 1
|
||||||
|
Number 2
|
||||||
|
Number 3
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('expressions in arrays', () => {
|
||||||
|
expect('[(1 + 2) (3 * 4)]').toMatchTree(`
|
||||||
|
Array
|
||||||
|
ParenExpr
|
||||||
|
BinOp
|
||||||
|
Number 1
|
||||||
|
Plus +
|
||||||
|
Number 2
|
||||||
|
ParenExpr
|
||||||
|
BinOp
|
||||||
|
Number 3
|
||||||
|
Star *
|
||||||
|
Number 4
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('mixed separators - spaces and newlines', () => {
|
||||||
|
expect(`[1 2
|
||||||
|
3 4]`).toMatchTree(`
|
||||||
|
Array
|
||||||
|
Number 1
|
||||||
|
Number 2
|
||||||
|
Number 3
|
||||||
|
Number 4
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('mixed separators - spaces and semicolons', () => {
|
||||||
|
expect('[1 2; 3 4]').toMatchTree(`
|
||||||
|
Array
|
||||||
|
Number 1
|
||||||
|
Number 2
|
||||||
|
Number 3
|
||||||
|
Number 4
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('empty lines within arrays', () => {
|
||||||
|
expect(`[1
|
||||||
|
|
||||||
|
2]`).toMatchTree(`
|
||||||
|
Array
|
||||||
|
Number 1
|
||||||
|
Number 2
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('comments within arrays', () => {
|
||||||
|
expect(`[ # something...
|
||||||
|
1 # first
|
||||||
|
2 # second
|
||||||
|
]`).toMatchTree(`
|
||||||
|
Array
|
||||||
|
Number 1
|
||||||
|
Number 2
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('complex nested multiline', () => {
|
||||||
|
expect(`[
|
||||||
|
[1 2]
|
||||||
|
[3 4]
|
||||||
|
[5 6]
|
||||||
|
]`).toMatchTree(`
|
||||||
|
Array
|
||||||
|
Array
|
||||||
|
Number 1
|
||||||
|
Number 2
|
||||||
|
Array
|
||||||
|
Number 3
|
||||||
|
Number 4
|
||||||
|
Array
|
||||||
|
Number 5
|
||||||
|
Number 6
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('boolean and null literals', () => {
|
||||||
|
expect('[true false null]').toMatchTree(`
|
||||||
|
Array
|
||||||
|
Boolean true
|
||||||
|
Boolean false
|
||||||
|
Null null
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('regex literals', () => {
|
||||||
|
expect('[//[0-9]+//]').toMatchTree(`
|
||||||
|
Array
|
||||||
|
Regex //[0-9]+//
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('trailing newlines', () => {
|
||||||
|
expect(`[
|
||||||
|
1
|
||||||
|
2
|
||||||
|
]`).toMatchTree(`
|
||||||
|
Array
|
||||||
|
Number 1
|
||||||
|
Number 2
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('dict literals', () => {
|
||||||
|
test('work with numbers', () => {
|
||||||
|
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('work with strings', () => {
|
||||||
|
expect("[a='one' b='two' c='three']").toMatchTree(`
|
||||||
|
Dict
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix a=
|
||||||
|
String
|
||||||
|
StringFragment one
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix b=
|
||||||
|
String
|
||||||
|
StringFragment two
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix c=
|
||||||
|
String
|
||||||
|
StringFragment three
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('work with identifiers', () => {
|
||||||
|
expect('[a=one b=two c=three]').toMatchTree(`
|
||||||
|
Dict
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix a=
|
||||||
|
Identifier one
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix b=
|
||||||
|
Identifier two
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix c=
|
||||||
|
Identifier three
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('can be nested', () => {
|
||||||
|
expect('[a=one b=[two [c=three]]]').toMatchTree(`
|
||||||
|
Dict
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix a=
|
||||||
|
Identifier one
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix b=
|
||||||
|
Array
|
||||||
|
Identifier two
|
||||||
|
Dict
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix c=
|
||||||
|
Identifier three
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('can span multiple lines', () => {
|
||||||
|
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 [=]
|
||||||
|
`)
|
||||||
|
|
||||||
|
expect('[ = ]').toMatchTree(`
|
||||||
|
Array
|
||||||
|
Word =
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('mixed types', () => {
|
||||||
|
expect("[a=1 b='two' c=three d=true e=null]").toMatchTree(`
|
||||||
|
Dict
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix a=
|
||||||
|
Number 1
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix b=
|
||||||
|
String
|
||||||
|
StringFragment two
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix c=
|
||||||
|
Identifier three
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix d=
|
||||||
|
Boolean true
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix e=
|
||||||
|
Null null
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('semicolons as separators', () => {
|
||||||
|
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('expressions in dicts', () => {
|
||||||
|
expect('[a=(1 + 2) b=(3 * 4)]').toMatchTree(`
|
||||||
|
Dict
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix a=
|
||||||
|
ParenExpr
|
||||||
|
BinOp
|
||||||
|
Number 1
|
||||||
|
Plus +
|
||||||
|
Number 2
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix b=
|
||||||
|
ParenExpr
|
||||||
|
BinOp
|
||||||
|
Number 3
|
||||||
|
Star *
|
||||||
|
Number 4
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('mixed separators - spaces and newlines', () => {
|
||||||
|
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 lines within dicts', () => {
|
||||||
|
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('comments within dicts', () => {
|
||||||
|
expect(`[ # something...
|
||||||
|
a=1 # first
|
||||||
|
b=2 # second
|
||||||
|
|
||||||
|
c=3
|
||||||
|
]`).toMatchTree(`
|
||||||
|
Dict
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix a=
|
||||||
|
Number 1
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix b=
|
||||||
|
Number 2
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix c=
|
||||||
|
Number 3
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('complex nested multiline', () => {
|
||||||
|
expect(`[
|
||||||
|
a=[a=1 b=2]
|
||||||
|
b=[b=3 c=4]
|
||||||
|
c=[c=5 d=6]
|
||||||
|
]`).toMatchTree(`
|
||||||
|
Dict
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix a=
|
||||||
|
Dict
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix a=
|
||||||
|
Number 1
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix b=
|
||||||
|
Number 2
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix b=
|
||||||
|
Dict
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix b=
|
||||||
|
Number 3
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix c=
|
||||||
|
Number 4
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix c=
|
||||||
|
Dict
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix c=
|
||||||
|
Number 5
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix d=
|
||||||
|
Number 6
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('boolean and null literals', () => {
|
||||||
|
expect('[a=true b=false c=null]').toMatchTree(`
|
||||||
|
Dict
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix a=
|
||||||
|
Boolean true
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix b=
|
||||||
|
Boolean false
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix c=
|
||||||
|
Null null
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('regex literals', () => {
|
||||||
|
expect('[pattern=//[0-9]+//]').toMatchTree(`
|
||||||
|
Dict
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix pattern=
|
||||||
|
Regex //[0-9]+//
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('trailing newlines', () => {
|
||||||
|
expect(`[
|
||||||
|
a=1
|
||||||
|
b=2
|
||||||
|
c=3
|
||||||
|
|
||||||
|
]`).toMatchTree(`
|
||||||
|
Dict
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix a=
|
||||||
|
Number 1
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix b=
|
||||||
|
Number 2
|
||||||
|
NamedArg
|
||||||
|
NamedArgPrefix c=
|
||||||
|
Number 3
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
@ -195,7 +195,13 @@ const isWhiteSpace = (ch: number): boolean => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const isWordChar = (ch: number): boolean => {
|
const isWordChar = (ch: number): boolean => {
|
||||||
return !isWhiteSpace(ch) && ch !== 10 /* \n */ && ch !== 41 /* ) */ && ch !== -1 /* EOF */
|
return (
|
||||||
|
!isWhiteSpace(ch) &&
|
||||||
|
ch !== 10 /* \n */ &&
|
||||||
|
ch !== 41 /* ) */ &&
|
||||||
|
ch !== 93 /* ] */ &&
|
||||||
|
ch !== -1 /* EOF */
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const isLowercaseLetter = (ch: number): boolean => {
|
const isLowercaseLetter = (ch: number): boolean => {
|
||||||
|
|
|
||||||
|
|
@ -105,11 +105,14 @@ expect.extend({
|
||||||
if (expected instanceof RegExp) expected = String(expected)
|
if (expected instanceof RegExp) expected = String(expected)
|
||||||
if (value instanceof RegExp) value = String(value)
|
if (value instanceof RegExp) value = String(value)
|
||||||
|
|
||||||
if (value === expected) {
|
if (isEqual(value, expected)) {
|
||||||
return { pass: true }
|
return { pass: true }
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
message: () => `Expected evaluation to be ${expected}, but got ${value}`,
|
message: () =>
|
||||||
|
`Expected evaluation to be ${JSON.stringify(expected)}, but got ${JSON.stringify(
|
||||||
|
value
|
||||||
|
)}`,
|
||||||
pass: false,
|
pass: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -161,3 +164,29 @@ const trimWhitespace = (str: string): string => {
|
||||||
})
|
})
|
||||||
.join('\n')
|
.join('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isEqual(a: any, b: any): boolean {
|
||||||
|
if (a === null && b === null) return true
|
||||||
|
|
||||||
|
switch (typeof a) {
|
||||||
|
case 'string':
|
||||||
|
case 'number':
|
||||||
|
case 'boolean':
|
||||||
|
case 'undefined':
|
||||||
|
return a === b
|
||||||
|
default:
|
||||||
|
return JSON.stringify(sortKeys(a)) === JSON.stringify(sortKeys(b))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function sortKeys(o: any): any {
|
||||||
|
if (Array.isArray(o)) return o.map(sortKeys)
|
||||||
|
if (o && typeof o === 'object' && o.constructor === Object)
|
||||||
|
return Object.keys(o)
|
||||||
|
.sort()
|
||||||
|
.reduce((r, k) => {
|
||||||
|
r[k] = sortKeys(o[k])
|
||||||
|
return r
|
||||||
|
}, {} as any)
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { Tree, TreeCursor } from '@lezer/common'
|
import { Tree, TreeCursor } from '@lezer/common'
|
||||||
import { assertNever } from '#utils/utils'
|
import { assertNever } from '#utils/utils'
|
||||||
import { type Value } from 'reefvm'
|
import { type Value, fromValue } from 'reefvm'
|
||||||
|
|
||||||
export const treeToString = (tree: Tree, input: string): string => {
|
export const treeToString = (tree: Tree, input: string): string => {
|
||||||
const lines: string[] = []
|
const lines: string[] = []
|
||||||
|
|
@ -35,27 +35,6 @@ export const treeToString = (tree: Tree, input: string): string => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const VMResultToValue = (result: Value): unknown => {
|
export const VMResultToValue = (result: Value): unknown => {
|
||||||
if (
|
if (result.type === 'function') return Function
|
||||||
result.type === 'number' ||
|
else return fromValue(result)
|
||||||
result.type === 'boolean' ||
|
|
||||||
result.type === 'string' ||
|
|
||||||
result.type === 'regex'
|
|
||||||
) {
|
|
||||||
return result.value
|
|
||||||
} else if (result.type === 'null') {
|
|
||||||
return null
|
|
||||||
} else if (result.type === 'array') {
|
|
||||||
return result.value.map(VMResultToValue)
|
|
||||||
} else if (result.type === 'dict') {
|
|
||||||
const obj: Record<string, unknown> = {}
|
|
||||||
for (const [key, val] of Object.entries(result.value)) {
|
|
||||||
obj[key] = VMResultToValue(val)
|
|
||||||
}
|
|
||||||
|
|
||||||
return obj
|
|
||||||
} else if (result.type === 'function') {
|
|
||||||
return Function
|
|
||||||
} else {
|
|
||||||
assertNever(result)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user