Compare commits
24 Commits
de30d85304
...
0eca3685f5
| Author | SHA1 | Date | |
|---|---|---|---|
| 0eca3685f5 | |||
|
|
dd2edb6dda | ||
| b738e6cfd1 | |||
| bf1196bf96 | |||
| f25ec024c2 | |||
| 6d19896d1a | |||
| f08b16824a | |||
| e1ba9c630d | |||
| b03610761b | |||
| b46154f753 | |||
| 3a04970dca | |||
| 2ff4615aab | |||
| 7387c56a20 | |||
| d3e83e17b2 | |||
| 9345c743ff | |||
| ee4de6c59e | |||
| 35e6b63499 | |||
| 62036b1e4b | |||
| 1aa1570135 | |||
| 8112515278 | |||
| 982054eb54 | |||
| 34c1177636 | |||
| 339c09eb8c | |||
| 7da4c14962 |
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.
|
||||
|
||||
**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.
|
||||
|
||||
## Compiler Architecture
|
||||
|
|
|
|||
93
bin/repl
93
bin/repl
|
|
@ -1,24 +1,12 @@
|
|||
#!/usr/bin/env bun
|
||||
|
||||
import { Compiler } from '../src/compiler/compiler'
|
||||
import { VM, type Value, Scope, bytecodeToString } from 'reefvm'
|
||||
import { colors, formatValue, globalFunctions } from '../src/prelude'
|
||||
import { VM, Scope, bytecodeToString } from 'reefvm'
|
||||
import * as readline from 'readline'
|
||||
import { readFileSync, writeFileSync } from 'fs'
|
||||
import { basename } from 'path'
|
||||
|
||||
const colors = {
|
||||
reset: '\x1b[0m',
|
||||
bright: '\x1b[1m',
|
||||
dim: '\x1b[2m',
|
||||
cyan: '\x1b[36m',
|
||||
yellow: '\x1b[33m',
|
||||
green: '\x1b[32m',
|
||||
red: '\x1b[31m',
|
||||
blue: '\x1b[34m',
|
||||
magenta: '\x1b[35m',
|
||||
pink: '\x1b[38;2;255;105;180m'
|
||||
}
|
||||
|
||||
async function repl() {
|
||||
const commands = ['/clear', '/reset', '/vars', '/funcs', '/history', '/bytecode', '/exit', '/save', '/quit']
|
||||
|
||||
|
|
@ -60,7 +48,7 @@ async function repl() {
|
|||
return
|
||||
}
|
||||
|
||||
vm ||= new VM({ instructions: [], constants: [] }, nativeFunctions)
|
||||
vm ||= new VM({ instructions: [], constants: [] }, globalFunctions)
|
||||
|
||||
if (['/exit', 'exit', '/quit', 'quit'].includes(trimmed)) {
|
||||
console.log(`\n${colors.yellow}Goodbye!${colors.reset}`)
|
||||
|
|
@ -186,40 +174,6 @@ async function repl() {
|
|||
})
|
||||
}
|
||||
|
||||
|
||||
function formatValue(value: Value, inner = false): string {
|
||||
switch (value.type) {
|
||||
case 'string':
|
||||
return `${colors.green}'${value.value}'${colors.reset}`
|
||||
case 'number':
|
||||
return `${colors.cyan}${value.value}${colors.reset}`
|
||||
case 'boolean':
|
||||
return `${colors.yellow}${value.value}${colors.reset}`
|
||||
case 'null':
|
||||
return `${colors.dim}null${colors.reset}`
|
||||
case 'array': {
|
||||
const items = value.value.map(x => formatValue(x, true)).join(' ')
|
||||
return `${inner ? '(' : ''}${colors.blue}list${colors.reset} ${items}${inner ? ')' : ''}`
|
||||
}
|
||||
case 'dict': {
|
||||
const entries = Array.from(value.value.entries())
|
||||
.map(([k, v]) => `${k}=${formatValue(v, true)}`)
|
||||
.join(' ')
|
||||
return `${inner ? '(' : ''}${colors.magenta}dict${colors.reset} ${entries}${inner ? ')' : ''}`
|
||||
}
|
||||
case 'function': {
|
||||
const params = value.params.join(', ')
|
||||
return `${colors.dim}<fn(${params})>${colors.reset}`
|
||||
}
|
||||
case 'native':
|
||||
return `${colors.dim}<native-fn>${colors.reset}`
|
||||
case 'regex':
|
||||
return `${colors.magenta}${value.value}${colors.reset}`
|
||||
default:
|
||||
return String(value)
|
||||
}
|
||||
}
|
||||
|
||||
function formatVariables(scope: Scope, onlyFunctions = false): string {
|
||||
const vars: string[] = []
|
||||
|
||||
|
|
@ -257,7 +211,7 @@ async function loadFile(filePath: string): Promise<{ vm: VM; codeHistory: string
|
|||
|
||||
console.log(`${colors.dim}Loading ${basename(filePath)}...${colors.reset}`)
|
||||
|
||||
const vm = new VM({ instructions: [], constants: [] }, nativeFunctions)
|
||||
const vm = new VM({ instructions: [], constants: [] }, globalFunctions)
|
||||
await vm.run()
|
||||
|
||||
const codeHistory: string[] = []
|
||||
|
|
@ -313,43 +267,4 @@ function showWelcome() {
|
|||
console.log()
|
||||
}
|
||||
|
||||
const nativeFunctions = {
|
||||
echo: (...args: any[]) => {
|
||||
console.log(...args)
|
||||
},
|
||||
len: (value: any) => {
|
||||
if (typeof value === 'string') return value.length
|
||||
if (Array.isArray(value)) return value.length
|
||||
if (value && typeof value === 'object') return Object.keys(value).length
|
||||
return 0
|
||||
},
|
||||
type: (value: any) => {
|
||||
if (value === null) return 'null'
|
||||
if (Array.isArray(value)) return 'array'
|
||||
return typeof value
|
||||
},
|
||||
range: (start: number, end: number | null) => {
|
||||
if (end === null) {
|
||||
end = start
|
||||
start = 0
|
||||
}
|
||||
const result: number[] = []
|
||||
for (let i = start; i <= end; i++) {
|
||||
result.push(i)
|
||||
}
|
||||
return result
|
||||
},
|
||||
join: (arr: any[], sep: string = ',') => {
|
||||
return arr.join(sep)
|
||||
},
|
||||
split: (str: string, sep: string = ',') => {
|
||||
return str.split(sep)
|
||||
},
|
||||
upper: (str: string) => str.toUpperCase(),
|
||||
lower: (str: string) => str.toLowerCase(),
|
||||
trim: (str: string) => str.trim(),
|
||||
list: (...args: any[]) => args,
|
||||
dict: (atNamed = {}) => atNamed
|
||||
}
|
||||
|
||||
await repl()
|
||||
|
|
|
|||
45
bin/shrimp
45
bin/shrimp
|
|
@ -1,57 +1,18 @@
|
|||
#!/usr/bin/env bun
|
||||
|
||||
import { Compiler } from '../src/compiler/compiler'
|
||||
import { VM, toValue, fromValue, bytecodeToString } from 'reefvm'
|
||||
import { colors, globalFunctions } from '../src/prelude'
|
||||
import { VM, fromValue, bytecodeToString } from 'reefvm'
|
||||
import { readFileSync, writeFileSync, mkdirSync } from 'fs'
|
||||
import { randomUUID } from "crypto"
|
||||
import { spawn } from 'child_process'
|
||||
import { join } from 'path'
|
||||
|
||||
const colors = {
|
||||
reset: '\x1b[0m',
|
||||
bright: '\x1b[1m',
|
||||
dim: '\x1b[2m',
|
||||
red: '\x1b[31m',
|
||||
yellow: '\x1b[33m',
|
||||
cyan: '\x1b[36m',
|
||||
magenta: '\x1b[35m',
|
||||
pink: '\x1b[38;2;255;105;180m'
|
||||
}
|
||||
|
||||
const nativeFunctions = {
|
||||
echo: (...args: any[]) => console.log(...args),
|
||||
len: (value: any) => {
|
||||
if (typeof value === 'string') return value.length
|
||||
if (Array.isArray(value)) return value.length
|
||||
if (value && typeof value === 'object') return Object.keys(value).length
|
||||
return 0
|
||||
},
|
||||
type: (value: any) => toValue(value).type,
|
||||
range: (start: number, end: number | null) => {
|
||||
if (end === null) {
|
||||
end = start
|
||||
start = 0
|
||||
}
|
||||
const result: number[] = []
|
||||
for (let i = start; i <= end; i++) {
|
||||
result.push(i)
|
||||
}
|
||||
return result
|
||||
},
|
||||
join: (arr: any[], sep: string = ',') => arr.join(sep),
|
||||
split: (str: string, sep: string = ',') => str.split(sep),
|
||||
upper: (str: string) => str.toUpperCase(),
|
||||
lower: (str: string) => str.toLowerCase(),
|
||||
trim: (str: string) => str.trim(),
|
||||
list: (...args: any[]) => args,
|
||||
dict: (atNamed = {}) => atNamed
|
||||
}
|
||||
|
||||
async function runFile(filePath: string) {
|
||||
try {
|
||||
const code = readFileSync(filePath, 'utf-8')
|
||||
const compiler = new Compiler(code)
|
||||
const vm = new VM(compiler.bytecode, nativeFunctions)
|
||||
const vm = new VM(compiler.bytecode, globalFunctions)
|
||||
await vm.run()
|
||||
return vm.stack.length ? fromValue(vm.stack[vm.stack.length - 1]) : null
|
||||
} catch (error: any) {
|
||||
|
|
|
|||
|
|
@ -42,13 +42,13 @@ a-file = file.txt
|
|||
3
|
||||
|
||||
# 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
|
||||
---
|
||||
3
|
||||
|
||||
# Functions can have multiple lines, they are terminated with `end`
|
||||
sub = fn x y:
|
||||
sub = do x y:
|
||||
x - y
|
||||
end
|
||||
|
||||
|
|
@ -82,9 +82,25 @@ add 1 (sub 5 2)
|
|||
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
|
||||
|
||||
- how do we handle arrays?
|
||||
- how do we handle hashes?
|
||||
- conditionals
|
||||
- loops
|
||||
|
|
@ -3,13 +3,11 @@
|
|||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
"scripts": {
|
||||
"dev": "bun generate-parser && bun --hot src/server/server.tsx",
|
||||
"generate-parser": "lezer-generator src/parser/shrimp.grammar --typeScript -o src/parser/shrimp.ts",
|
||||
"repl": "bun generate-parser && bun bin/repl"
|
||||
"repl": "bun generate-parser && bun bin/repl",
|
||||
"update-reef": "cd packages/ReefVM && git pull origin main"
|
||||
},
|
||||
"dependencies": {
|
||||
"@codemirror/view": "^6.38.3",
|
||||
|
|
|
|||
|
|
@ -265,6 +265,9 @@ export class Compiler {
|
|||
}
|
||||
|
||||
case terms.FunctionCallOrIdentifier: {
|
||||
if (node.firstChild?.name === 'DotGet')
|
||||
return this.#compileNode(node.firstChild, input)
|
||||
|
||||
return [['TRY_CALL', value]]
|
||||
}
|
||||
|
||||
|
|
@ -468,6 +471,44 @@ export class Compiler {
|
|||
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:
|
||||
throw new CompilerError(
|
||||
`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" | "\\" | "'")
|
||||
}
|
||||
|
||||
Dict {
|
||||
"[=]" |
|
||||
"[" newlineOrSemicolon* NamedArg (newlineOrSemicolon | NamedArg)* "]"
|
||||
}
|
||||
|
||||
Array {
|
||||
"[" newlineOrSemicolon* (expression (newlineOrSemicolon | expression)*)? "]"
|
||||
}
|
||||
|
||||
// We need expressionWithoutIdentifier to avoid conflicts in consumeToTerminator.
|
||||
// Without this, when parsing "my-var" at statement level, the parser can't decide:
|
||||
// - ambiguousFunctionCall → FunctionCallOrIdentifier → Identifier
|
||||
|
|
@ -200,7 +209,7 @@ EscapeSeq {
|
|||
// 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.
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -31,19 +31,21 @@ export const
|
|||
EscapeSeq = 29,
|
||||
Boolean = 30,
|
||||
Regex = 31,
|
||||
Null = 32,
|
||||
ConditionalOp = 33,
|
||||
FunctionDef = 34,
|
||||
Params = 35,
|
||||
colon = 36,
|
||||
keyword = 50,
|
||||
PositionalArg = 38,
|
||||
Dict = 32,
|
||||
NamedArg = 33,
|
||||
NamedArgPrefix = 34,
|
||||
FunctionDef = 35,
|
||||
Params = 36,
|
||||
colon = 37,
|
||||
keyword = 52,
|
||||
Underscore = 39,
|
||||
NamedArg = 40,
|
||||
NamedArgPrefix = 41,
|
||||
IfExpr = 43,
|
||||
SingleLineThenBlock = 45,
|
||||
ThenBlock = 46,
|
||||
ElseIfExpr = 47,
|
||||
ElseExpr = 49,
|
||||
Assign = 51
|
||||
Array = 40,
|
||||
Null = 41,
|
||||
ConditionalOp = 42,
|
||||
PositionalArg = 43,
|
||||
IfExpr = 45,
|
||||
SingleLineThenBlock = 47,
|
||||
ThenBlock = 48,
|
||||
ElseIfExpr = 49,
|
||||
ElseExpr = 51,
|
||||
Assign = 53
|
||||
|
|
|
|||
|
|
@ -4,24 +4,24 @@ import {operatorTokenizer} from "./operatorTokenizer"
|
|||
import {tokenizer, specializeKeyword} from "./tokenizer"
|
||||
import {trackScope} from "./scopeTracker"
|
||||
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({
|
||||
version: 14,
|
||||
states: "/SQYQbOOO!TOpO'#CqO#aQcO'#CtO$ZOSO'#CvO%aQcO'#DsOOQa'#Ds'#DsO&gQcO'#D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pr 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",
|
||||
maxTerm: 85,
|
||||
states: "2YQYQbOOO!ZOpO'#CqO#mQcO'#CtO$gOSO'#CvO$uQbO'#ETOOQ`'#DP'#DPOOQa'#C|'#C|O%xQbO'#DUO&}QcO'#DxOOQa'#Dx'#DxO(TQcO'#DwO(lQRO'#CuO(zQcO'#DsO)cQbO'#CsOOQ`'#Dt'#DtO*ZQbO'#DsO*iQbO'#EZOOQ`'#DZ'#DZO+^QRO'#DcOOQ`'#Ds'#DsO+cQQO'#DrOOQ`'#Dr'#DrOOQ`'#Dd'#DdQYQbOOO+kObO,59]O+sQbO'#C}OOQa'#Dw'#DwOOQ`'#DX'#DXOOQ`'#EY'#EYOOQ`'#Dk'#DkO+}QbO,59[O,bQbO'#CxO,jQWO'#CyOOOO'#Dz'#DzOOOO'#De'#DeO-OOSO,59bOOQa,59b,59bOOQ`'#Dg'#DgO-^QbO'#DQO-fQQO,5:oOOQ`'#Df'#DfO-kQbO,59pO-rQQO,59hOOQa,59p,59pO-}QbO,59pO*iQbO,59aO*iQbO,59aO.XQRO,59_O/nQRO'#CuO0OQRO,59_O0[QQO,59_O0aQQO,59_O0iQbO'#DlO0tQbO,59ZO1VQRO,5:uO1^QQO,5:uO1cQbO,59}OOQ`,5:^,5:^OOQ`-E7b-E7bOOQa1G.w1G.wOOQ`,59i,59iOOQ`-E7i-E7iOOOO,59d,59dOOOO,59e,59eOOOO-E7c-E7cOOQa1G.|1G.|OOQ`-E7e-E7eO1mQbO1G0ZOOQ`-E7d-E7dO1zQQO1G/SOOQa1G/[1G/[O2VQbO1G/[OOQO'#Di'#DiO1zQQO1G/SOOQa1G/S1G/SOOQ`'#Dj'#DjO2VQbO1G/[OOQa1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-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 Dict NamedArg NamedArgPrefix FunctionDef Params colon keyword Underscore Array Null ConditionalOp PositionalArg operator IfExpr keyword SingleLineThenBlock ThenBlock ElseIfExpr keyword ElseExpr keyword Assign",
|
||||
maxTerm: 93,
|
||||
context: trackScope,
|
||||
nodeProps: [
|
||||
["closedBy", 36,"end"]
|
||||
["closedBy", 37,"end"]
|
||||
],
|
||||
propSources: [highlighting],
|
||||
skippedNodes: [0],
|
||||
repeatNodeCount: 7,
|
||||
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<%lO&bY&vP;=`<%l&b^&|P;=`<%l%h~'UO!j~~'ZO!h~U'bUkS!eQOt#uuw#ux#O#u#P;'S#u;'S;=`$^<%lO#uU'{UkS!sQOt#uuw#ux#O#u#P;'S#u;'S;=`$^<%lO#uU(dWkSOt#uuw#ux!Q#u!Q![(|![#O#u#P;'S#u;'S;=`$^<%lO#uU)TYkSfQOt#uuw#ux!O#u!O!P)s!P!Q#u!Q![(|![#O#u#P;'S#u;'S;=`$^<%lO#uU)xWkSOt#uuw#ux!Q#u!Q![*b![#O#u#P;'S#u;'S;=`$^<%lO#uU*iWkSfQOt#uuw#ux!Q#u!Q![*b![#O#u#P;'S#u;'S;=`$^<%lO#uU+WWkSOt#uuw#ux!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_!`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!i~~", 11)],
|
||||
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}],
|
||||
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 => {
|
||||
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 => {
|
||||
|
|
|
|||
142
src/prelude/index.ts
Normal file
142
src/prelude/index.ts
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
// The prelude creates all the builtin Shrimp functions.
|
||||
|
||||
import { resolve, parse } from 'path'
|
||||
import { readFileSync } from 'fs'
|
||||
import { Compiler } from '#compiler/compiler'
|
||||
import {
|
||||
VM, Scope, toValue, type Value,
|
||||
extractParamInfo, isWrapped, getOriginalFunction,
|
||||
} from 'reefvm'
|
||||
|
||||
export const colors = {
|
||||
reset: '\x1b[0m',
|
||||
bright: '\x1b[1m',
|
||||
dim: '\x1b[2m',
|
||||
cyan: '\x1b[36m',
|
||||
yellow: '\x1b[33m',
|
||||
green: '\x1b[32m',
|
||||
red: '\x1b[31m',
|
||||
blue: '\x1b[34m',
|
||||
magenta: '\x1b[35m',
|
||||
pink: '\x1b[38;2;255;105;180m'
|
||||
}
|
||||
|
||||
export const globalFunctions = {
|
||||
// hello
|
||||
echo: (...args: any[]) => {
|
||||
console.log(...args.map(a => {
|
||||
const v = toValue(a)
|
||||
return ['array', 'dict'].includes(v.type) ? formatValue(v, true) : v.value
|
||||
}))
|
||||
return toValue(null)
|
||||
},
|
||||
|
||||
// info
|
||||
type: (v: any) => toValue(v).type,
|
||||
inspect: (v: any) => formatValue(toValue(v)),
|
||||
length: (v: any) => {
|
||||
const value = toValue(v)
|
||||
switch (value.type) {
|
||||
case 'string': case 'array': return value.value.length
|
||||
case 'dict': return value.value.size
|
||||
default: return 0
|
||||
}
|
||||
},
|
||||
|
||||
// strings
|
||||
join: (arr: string[], sep: string = ',') => arr.join(sep),
|
||||
split: (str: string, sep: string = ',') => str.split(sep),
|
||||
'to-upper': (str: string) => str.toUpperCase(),
|
||||
'to-lower': (str: string) => str.toLowerCase(),
|
||||
trim: (str: string) => str.trim(),
|
||||
|
||||
// collections
|
||||
at: (collection: any, index: number | string) => collection[index],
|
||||
list: (...args: any[]) => args,
|
||||
dict: (atNamed = {}) => atNamed,
|
||||
slice: (list: any[], start: number, end?: number) => list.slice(start, end),
|
||||
range: (start: number, end: number | null) => {
|
||||
if (end === null) {
|
||||
end = start
|
||||
start = 0
|
||||
}
|
||||
const result: number[] = []
|
||||
for (let i = start; i <= end; i++) {
|
||||
result.push(i)
|
||||
}
|
||||
return result
|
||||
},
|
||||
|
||||
// enumerables
|
||||
map: async (list: any[], cb: Function) => {
|
||||
let acc: any[] = []
|
||||
for (const value of list) acc.push(await cb(value))
|
||||
return acc
|
||||
},
|
||||
each: async (list: any[], cb: Function) => {
|
||||
for (const value of list) await cb(value)
|
||||
return list
|
||||
},
|
||||
|
||||
// modules
|
||||
load: async function (this: VM, path: string): Promise<Record<string, Value>> {
|
||||
const scope = this.scope
|
||||
const pc = this.pc
|
||||
|
||||
const fullPath = resolve(path) + '.sh'
|
||||
const code = readFileSync(fullPath, 'utf-8')
|
||||
|
||||
this.pc = this.instructions.length
|
||||
this.scope = new Scope(scope)
|
||||
const compiled = new Compiler(code)
|
||||
this.appendBytecode(compiled.bytecode)
|
||||
|
||||
await this.continue()
|
||||
|
||||
const module: Record<string, Value> = {}
|
||||
for (const [name, value] of this.scope.locals.entries())
|
||||
module[name] = value
|
||||
|
||||
this.scope = scope
|
||||
this.pc = pc
|
||||
this.stopped = false
|
||||
|
||||
return module
|
||||
},
|
||||
}
|
||||
|
||||
export function formatValue(value: Value, inner = false): string {
|
||||
switch (value.type) {
|
||||
case 'string':
|
||||
return `${colors.green}'${value.value.replaceAll("'", "\\'")}${colors.green}'${colors.reset}`
|
||||
case 'number':
|
||||
return `${colors.cyan}${value.value}${colors.reset}`
|
||||
case 'boolean':
|
||||
return `${colors.yellow}${value.value}${colors.reset}`
|
||||
case 'null':
|
||||
return `${colors.dim}null${colors.reset}`
|
||||
case 'array': {
|
||||
const items = value.value.map(x => formatValue(x, true)).join(' ')
|
||||
return `${inner ? '(' : ''}${colors.blue}list${colors.reset} ${items}${inner ? ')' : ''}`
|
||||
}
|
||||
case 'dict': {
|
||||
const entries = Array.from(value.value.entries())
|
||||
.map(([k, v]) => `${k}=${formatValue(v, true)}`)
|
||||
.join(' ')
|
||||
return `${inner ? '(' : ''}${colors.magenta}dict${colors.reset} ${entries}${inner ? ')' : ''}`
|
||||
}
|
||||
case 'function': {
|
||||
const params = value.params.length ? '(' + value.params.join(' ') + ')' : ''
|
||||
return `${colors.dim}<function${params}>${colors.reset}`
|
||||
}
|
||||
case 'native':
|
||||
const fn = isWrapped(value.fn) ? getOriginalFunction(value.fn) : value.fn
|
||||
const info = extractParamInfo(fn)
|
||||
const params = info.params.length ? '(' + info.params.join(' ') + ')' : ''
|
||||
return `${colors.dim}<native${params}>${colors.reset}`
|
||||
case 'regex':
|
||||
return `${colors.magenta}${value.value}${colors.reset}`
|
||||
default:
|
||||
return String(value)
|
||||
}
|
||||
}
|
||||
42
src/prelude/tests/load.ts
Normal file
42
src/prelude/tests/load.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import { expect, describe, test } from 'bun:test'
|
||||
import { globalFunctions } from '#prelude'
|
||||
|
||||
describe('use', () => {
|
||||
test(`imports all a file's functions`, async () => {
|
||||
expect(`
|
||||
math = load ./src/prelude/tests/math
|
||||
math.double 4
|
||||
`).toEvaluateTo(8, globalFunctions)
|
||||
|
||||
expect(`
|
||||
math = load ./src/prelude/tests/math
|
||||
math.double (math.double 4)
|
||||
`).toEvaluateTo(16, globalFunctions)
|
||||
|
||||
expect(`
|
||||
math = load ./src/prelude/tests/math
|
||||
dbl = math.double
|
||||
dbl (dbl 2)
|
||||
`).toEvaluateTo(8, globalFunctions)
|
||||
|
||||
expect(`
|
||||
math = load ./src/prelude/tests/math
|
||||
math.pi
|
||||
`).toEvaluateTo(3.14, globalFunctions)
|
||||
|
||||
expect(`
|
||||
math = load ./src/prelude/tests/math
|
||||
math | at 🥧
|
||||
`).toEvaluateTo(3.14159265359, globalFunctions)
|
||||
|
||||
expect(`
|
||||
math = load ./src/prelude/tests/math
|
||||
math.🥧
|
||||
`).toEvaluateTo(3.14159265359, globalFunctions)
|
||||
|
||||
expect(`
|
||||
math = load ./src/prelude/tests/math
|
||||
math.add1 5
|
||||
`).toEvaluateTo(6, globalFunctions)
|
||||
})
|
||||
})
|
||||
4
src/prelude/tests/math.sh
Normal file
4
src/prelude/tests/math.sh
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
🥧 = 3.14159265359
|
||||
pi = 3.14
|
||||
add1 = do x: x + 1 end
|
||||
double = do x: x * 2 end
|
||||
147
src/prelude/tests/prelude.test.ts
Normal file
147
src/prelude/tests/prelude.test.ts
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
import { expect, describe, test } from 'bun:test'
|
||||
import { globalFunctions } from '#prelude'
|
||||
|
||||
describe('string operations', () => {
|
||||
test('to-upper converts to uppercase', async () => {
|
||||
await expect(`to-upper 'hello'`).toEvaluateTo('HELLO', globalFunctions)
|
||||
await expect(`to-upper 'Hello World!'`).toEvaluateTo('HELLO WORLD!', globalFunctions)
|
||||
})
|
||||
|
||||
test('to-lower converts to lowercase', async () => {
|
||||
await expect(`to-lower 'HELLO'`).toEvaluateTo('hello', globalFunctions)
|
||||
await expect(`to-lower 'Hello World!'`).toEvaluateTo('hello world!', globalFunctions)
|
||||
})
|
||||
|
||||
test('trim removes whitespace', async () => {
|
||||
await expect(`trim ' hello '`).toEvaluateTo('hello', globalFunctions)
|
||||
await expect(`trim '\\n\\thello\\t\\n'`).toEvaluateTo('hello', globalFunctions)
|
||||
})
|
||||
|
||||
test('split divides string by separator', async () => {
|
||||
await expect(`split 'a,b,c' ','`).toEvaluateTo(['a', 'b', 'c'], globalFunctions)
|
||||
await expect(`split 'hello' ''`).toEvaluateTo(['h', 'e', 'l', 'l', 'o'], globalFunctions)
|
||||
})
|
||||
|
||||
test('split with comma separator', async () => {
|
||||
await expect(`split 'a,b,c' ','`).toEvaluateTo(['a', 'b', 'c'], globalFunctions)
|
||||
})
|
||||
|
||||
test('join combines array elements', async () => {
|
||||
await expect(`join ['a' 'b' 'c'] '-'`).toEvaluateTo('a-b-c', globalFunctions)
|
||||
await expect(`join ['hello' 'world'] ' '`).toEvaluateTo('hello world', globalFunctions)
|
||||
})
|
||||
|
||||
test('join with comma separator', async () => {
|
||||
await expect(`join ['a' 'b' 'c'] ','`).toEvaluateTo('a,b,c', globalFunctions)
|
||||
})
|
||||
})
|
||||
|
||||
describe('introspection', () => {
|
||||
test('type returns proper types', async () => {
|
||||
await expect(`type 'hello'`).toEvaluateTo('string', globalFunctions)
|
||||
await expect(`type 42`).toEvaluateTo('number', globalFunctions)
|
||||
await expect(`type true`).toEvaluateTo('boolean', globalFunctions)
|
||||
await expect(`type false`).toEvaluateTo('boolean', globalFunctions)
|
||||
await expect(`type null`).toEvaluateTo('null', globalFunctions)
|
||||
await expect(`type [1 2 3]`).toEvaluateTo('array', globalFunctions)
|
||||
await expect(`type [a=1 b=2]`).toEvaluateTo('dict', globalFunctions)
|
||||
})
|
||||
|
||||
test('length', async () => {
|
||||
await expect(`length 'hello'`).toEvaluateTo(5, globalFunctions)
|
||||
await expect(`length [1 2 3]`).toEvaluateTo(3, globalFunctions)
|
||||
await expect(`length [a=1 b=2]`).toEvaluateTo(2, globalFunctions)
|
||||
await expect(`length 42`).toEvaluateTo(0, globalFunctions)
|
||||
await expect(`length true`).toEvaluateTo(0, globalFunctions)
|
||||
await expect(`length null`).toEvaluateTo(0, globalFunctions)
|
||||
})
|
||||
|
||||
test('inspect formats values', async () => {
|
||||
// Just test that inspect returns something for now
|
||||
// (we'd need more complex assertion to check the actual format)
|
||||
await expect(`type (inspect 'hello')`).toEvaluateTo('string', globalFunctions)
|
||||
})
|
||||
})
|
||||
|
||||
describe('collections', () => {
|
||||
test('list creates array from arguments', async () => {
|
||||
await expect(`list 1 2 3`).toEvaluateTo([1, 2, 3], globalFunctions)
|
||||
await expect(`list 'a' 'b'`).toEvaluateTo(['a', 'b'], globalFunctions)
|
||||
await expect(`list`).toEvaluateTo([], globalFunctions)
|
||||
})
|
||||
|
||||
test('dict creates object from named arguments', async () => {
|
||||
await expect(`dict a=1 b=2`).toEvaluateTo({ a: 1, b: 2 }, globalFunctions)
|
||||
await expect(`dict`).toEvaluateTo({}, globalFunctions)
|
||||
})
|
||||
|
||||
test('at retrieves element at index', async () => {
|
||||
await expect(`at [10 20 30] 0`).toEvaluateTo(10, globalFunctions)
|
||||
await expect(`at [10 20 30] 2`).toEvaluateTo(30, globalFunctions)
|
||||
})
|
||||
|
||||
test('at retrieves property from object', async () => {
|
||||
await expect(`at [name='test'] 'name'`).toEvaluateTo('test', globalFunctions)
|
||||
})
|
||||
|
||||
test('slice extracts array subset', async () => {
|
||||
await expect(`slice [1 2 3 4 5] 1 3`).toEvaluateTo([2, 3], globalFunctions)
|
||||
await expect(`slice [1 2 3 4 5] 2 5`).toEvaluateTo([3, 4, 5], globalFunctions)
|
||||
})
|
||||
|
||||
test('range creates number sequence', async () => {
|
||||
await expect(`range 0 5`).toEvaluateTo([0, 1, 2, 3, 4, 5], globalFunctions)
|
||||
await expect(`range 3 6`).toEvaluateTo([3, 4, 5, 6], globalFunctions)
|
||||
})
|
||||
|
||||
test('range with single argument starts from 0', async () => {
|
||||
await expect(`range 3 null`).toEvaluateTo([0, 1, 2, 3], globalFunctions)
|
||||
await expect(`range 0 null`).toEvaluateTo([0], globalFunctions)
|
||||
})
|
||||
})
|
||||
|
||||
describe('enumerables', () => {
|
||||
test('map transforms array elements', async () => {
|
||||
await expect(`
|
||||
double = do x: x * 2 end
|
||||
map [1 2 3] double
|
||||
`).toEvaluateTo([2, 4, 6], globalFunctions)
|
||||
})
|
||||
|
||||
test('map handles empty array', async () => {
|
||||
await expect(`
|
||||
double = do x: x * 2 end
|
||||
map [] double
|
||||
`).toEvaluateTo([], globalFunctions)
|
||||
})
|
||||
|
||||
test('each iterates over array', async () => {
|
||||
// Note: each doesn't return the results, it returns null
|
||||
// We can test it runs by checking the return value
|
||||
await expect(`
|
||||
double = do x: x * 2 end
|
||||
each [1 2 3] double
|
||||
`).toEvaluateTo([1, 2, 3], globalFunctions)
|
||||
})
|
||||
|
||||
test('each handles empty array', async () => {
|
||||
await expect(`
|
||||
fn = do x: x end
|
||||
each [] fn
|
||||
`).toEvaluateTo([], globalFunctions)
|
||||
})
|
||||
})
|
||||
|
||||
// describe('echo', () => {
|
||||
// test('echo returns null value', async () => {
|
||||
// await expect(`echo 'hello' 'world'`).toEvaluateTo(null, globalFunctions)
|
||||
// })
|
||||
|
||||
// test('echo with array', async () => {
|
||||
// await expect(`echo [1 2 3]`).toEvaluateTo(null, globalFunctions)
|
||||
// })
|
||||
|
||||
// test('echo with multiple arguments', async () => {
|
||||
// await expect(`echo 'test' 42 true`).toEvaluateTo(null, globalFunctions)
|
||||
// })
|
||||
// })
|
||||
|
|
@ -3,7 +3,7 @@ import { parser } from '#parser/shrimp'
|
|||
import { $ } from 'bun'
|
||||
import { assert, errorMessage } from '#utils/utils'
|
||||
import { Compiler } from '#compiler/compiler'
|
||||
import { run, VM } from 'reefvm'
|
||||
import { run, VM, type TypeScriptFunction } from 'reefvm'
|
||||
import { treeToString, VMResultToValue } from '#utils/tree'
|
||||
|
||||
const regenerateParser = async () => {
|
||||
|
|
@ -93,11 +93,7 @@ expect.extend({
|
|||
}
|
||||
},
|
||||
|
||||
async toEvaluateTo(
|
||||
received: unknown,
|
||||
expected: unknown,
|
||||
globals: Record<string, any> = {}
|
||||
) {
|
||||
async toEvaluateTo(received: unknown, expected: unknown, globals: Record<string, any> = {}) {
|
||||
assert(typeof received === 'string', 'toEvaluateTo can only be used with string values')
|
||||
|
||||
try {
|
||||
|
|
@ -109,11 +105,14 @@ expect.extend({
|
|||
if (expected instanceof RegExp) expected = String(expected)
|
||||
if (value instanceof RegExp) value = String(value)
|
||||
|
||||
if (value === expected) {
|
||||
if (isEqual(value, expected)) {
|
||||
return { pass: true }
|
||||
} else {
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
|
@ -165,3 +164,29 @@ const trimWhitespace = (str: string): string => {
|
|||
})
|
||||
.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 { assertNever } from '#utils/utils'
|
||||
import { type Value } from 'reefvm'
|
||||
import { type Value, fromValue } from 'reefvm'
|
||||
|
||||
export const treeToString = (tree: Tree, input: string): string => {
|
||||
const lines: string[] = []
|
||||
|
|
@ -35,27 +35,6 @@ export const treeToString = (tree: Tree, input: string): string => {
|
|||
}
|
||||
|
||||
export const VMResultToValue = (result: Value): unknown => {
|
||||
if (
|
||||
result.type === 'number' ||
|
||||
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)
|
||||
}
|
||||
if (result.type === 'function') return Function
|
||||
else return fromValue(result)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user