now it is do

This commit is contained in:
Corey Johnson 2025-10-24 14:04:50 -07:00
parent 7077762738
commit d306d58b2f
10 changed files with 62 additions and 62 deletions

View File

@ -63,26 +63,26 @@ describe('compiler', () => {
})
test('function', () => {
expect(`fn a b: a + b end`).toEvaluateTo(Function)
expect(`do a b: a + b end`).toEvaluateTo(Function)
})
test('function call', () => {
expect(`add = fn a b: a + b end; add 2 9`).toEvaluateTo(11)
expect(`add = do a b: a + b end; add 2 9`).toEvaluateTo(11)
})
test('function call with named args', () => {
expect(`minus = fn a b: a - b end; minus b=2 a=9`).toEvaluateTo(7)
expect(`minus = do a b: a - b end; minus b=2 a=9`).toEvaluateTo(7)
})
test('function call with named and positional args', () => {
expect(`minus = fn a b: a - b end; minus b=2 9`).toEvaluateTo(7)
expect(`minus = fn a b: a - b end; minus 90 b=20`).toEvaluateTo(70)
expect(`minus = fn a b: a - b end; minus a=900 200`).toEvaluateTo(700)
expect(`minus = fn a b: a - b end; minus 2000 a=9000`).toEvaluateTo(7000)
expect(`minus = do a b: a - b end; minus b=2 9`).toEvaluateTo(7)
expect(`minus = do a b: a - b end; minus 90 b=20`).toEvaluateTo(70)
expect(`minus = do a b: a - b end; minus a=900 200`).toEvaluateTo(700)
expect(`minus = do a b: a - b end; minus 2000 a=9000`).toEvaluateTo(7000)
})
test('function call with no args', () => {
expect(`bloop = fn: 'bloop' end; bloop`).toEvaluateTo('bloop')
expect(`bloop = do: 'bloop' end; bloop`).toEvaluateTo('bloop')
})
test('simple conditionals', () => {
@ -150,7 +150,7 @@ describe('errors', () => {
describe('multiline tests', () => {
test('multiline function', () => {
expect(`
add = fn a b:
add = do a b:
result = a + b
result
end

View File

@ -3,7 +3,7 @@ import { describe, test, expect } from 'bun:test'
describe('pipe expressions', () => {
test('simple pipe passes result as first argument', () => {
const code = `
double = fn x: x * 2 end
double = do x: x * 2 end
double 2 | double`
expect(code).toEvaluateTo(8)
@ -11,9 +11,9 @@ describe('pipe expressions', () => {
test('pipe chain with three stages', () => {
const code = `
add-one = fn x: x + 1 end
double = fn x: x * 2 end
minus-point-one = fn x: x - 0.1 end
add-one = do x: x + 1 end
double = do x: x * 2 end
minus-point-one = do x: x - 0.1 end
add-one 3 | double | minus-point-one`
// 4 8 7.9
expect(code).toEvaluateTo(7.9)
@ -21,8 +21,8 @@ describe('pipe expressions', () => {
test('pipe with function that has additional arguments', () => {
const code = `
multiply = fn a b: a * b end
get-five = fn: 5 end
multiply = do a b: a * b end
get-five = do: 5 end
get-five | multiply 3`
expect(code).toEvaluateTo(15)
@ -31,7 +31,7 @@ describe('pipe expressions', () => {
test('pipe with bare identifier', () => {
const code = `
get-value = 42
process = fn x: x + 10 end
process = do x: x + 10 end
get-value | process`
expect(code).toEvaluateTo(52)
@ -39,7 +39,7 @@ describe('pipe expressions', () => {
test('pipe in assignment', () => {
const code = `
add-ten = fn x: x + 10 end
add-ten = do x: x + 10 end
result = add-ten 5 | add-ten
result`
@ -49,23 +49,23 @@ describe('pipe expressions', () => {
test('pipe with named underscore arg', () => {
expect(`
divide = fn a b: a / b end
get-ten = fn: 10 end
divide = do a b: a / b end
get-ten = do: 10 end
get-ten | divide 2 b=_`).toEvaluateTo(0.2)
expect(`
divide = fn a b: a / b end
get-ten = fn: 10 end
divide = do a b: a / b end
get-ten = do: 10 end
get-ten | divide b=_ 2`).toEvaluateTo(0.2)
expect(`
divide = fn a b: a / b end
get-ten = fn: 10 end
divide = do a b: a / b end
get-ten = do: 10 end
get-ten | divide 2 a=_`).toEvaluateTo(5)
expect(`
divide = fn a b: a / b end
get-ten = fn: 10 end
divide = do a b: a / b end
get-ten = do: 10 end
get-ten | divide a=_ 2`).toEvaluateTo(5)
})
@ -74,8 +74,8 @@ describe('pipe expressions', () => {
// handling logic works correctly when there are multiple pipe stages
// in a single expression.
expect(`
sub = fn a b: a - b end
div = fn a b: a / b end
sub = do a b: a - b end
div = do a b: a / b end
sub 3 1 | div (sub 110 9 | sub 1) _ | div 5`).toEvaluateTo(10)
})
})

View File

@ -245,7 +245,7 @@ const commandShapes: CommandShape[] = [
] as const
let commandSource = () => commandShapes
export const setCommandSource = (fn: () => CommandShape[]) => {
export const setCommandSource = (do: () => CommandShape[]) => {
commandSource = fn
}

View File

@ -93,11 +93,11 @@ FunctionDef {
}
singleLineFunctionDef {
@specialize[@name=keyword]<Identifier, "fn"> Params colon consumeToTerminator @specialize[@name=keyword]<Identifier, "end">
@specialize[@name=keyword]<Identifier, "do"> Params colon consumeToTerminator @specialize[@name=keyword]<Identifier, "end">
}
multilineFunctionDef {
@specialize[@name=keyword]<Identifier, "fn"> Params colon newlineOrSemicolon block @specialize[@name=keyword]<Identifier, "end">
@specialize[@name=keyword]<Identifier, "do"> Params colon newlineOrSemicolon block @specialize[@name=keyword]<Identifier, "end">
}
IfExpr {

View File

@ -4,7 +4,7 @@ import {operatorTokenizer} from "./operatorTokenizer"
import {tokenizer} from "./tokenizer"
import {trackScope} from "./scopeTracker"
import {highlighting} from "./highlight"
const spec_Identifier = {__proto__:null,fn:70, end:76, if:88, elsif:96, else:100}
const spec_Identifier = {__proto__:null,do:70, end:76, if:88, elsif:96, else:100}
export const parser = LRParser.deserialize({
version: 14,
states: ".jQVQbOOO#XQcO'#CrO$RQRO'#CsO$aQcO'#DmO$xQbO'#CqO%gOSO'#CuOOQa'#Dq'#DqO%uOpO'#C}O%zQcO'#DpO&cQbO'#D|OOQ`'#DO'#DOOOQ`'#Dn'#DnO&kQbO'#DmO&yQbO'#EQOOQ`'#DX'#DXO'hQRO'#DaOOQ`'#Dm'#DmO'mQQO'#DlOOQ`'#Dl'#DlOOQ`'#Db'#DbQVQbOOOOQa'#Dp'#DpOOQ`'#Cp'#CpO'uQbO'#DUOOQ`'#Do'#DoOOQ`'#Dc'#DcO(PQbO,59ZO&yQbO,59_O&yQbO,59_O)XQRO'#CsO)iQRO,59]O)zQRO,59]O)uQQO,59]O*uQQO,59]O*}QbO'#CwO+VQWO'#CxOOOO'#Du'#DuOOOO'#Dd'#DdO+kOSO,59aOOQa,59a,59aO+yO`O,59iOOQ`'#De'#DeO,OQbO'#DQO,WQQO,5:hO,]QbO'#DgO,bQbO,59YO,sQRO,5:lO,zQQO,5:lO-PQbO,59{OOQ`,5:W,5:WOOQ`-E7`-E7`OOQ`,59p,59pOOQ`-E7a-E7aOOQa1G.y1G.yO-^QcO1G.yO&yQbO,59`O&yQbO,59`OOQa1G.w1G.wOOOO,59c,59cOOOO,59d,59dOOOO-E7b-E7bOOQa1G.{1G.{OOQa1G/T1G/TOOQ`-E7c-E7cO-xQbO1G0SO!QQbO'#CrOOQ`,5:R,5:ROOQ`-E7e-E7eO.YQbO1G0WOOQ`1G/g1G/gOOQO1G.z1G.zO.jQRO1G.zO.tQbO7+%nO.yQbO7+%oOOQ`'#DZ'#DZOOQ`7+%r7+%rO/ZQbO7+%sOOQ`<<IY<<IYO/qQQO'#DfO/vQbO'#EPO0^QbO<<IZOOQ`'#D['#D[O0cQbO<<I_OOQ`,5:Q,5:QOOQ`-E7d-E7dOOQ`AN>uAN>uO&yQbO'#D]OOQ`'#Dh'#DhO0nQbOAN>yO0yQQO'#D_OOQ`AN>yAN>yO1OQbOAN>yO1TQRO,59wO1[QQO,59wOOQ`-E7f-E7fOOQ`G24eG24eO1aQbOG24eO1fQQO,59yO1kQQO1G/cOOQ`LD*PLD*PO.yQbO1G/eO/ZQbO7+$}OOQ`7+%P7+%POOQ`<<Hi<<Hi",

View File

@ -286,12 +286,12 @@ describe('Assign', () => {
})
test('parses assignment with functions', () => {
expect('add = fn a b: a + b end').toMatchTree(`
expect('add = do a b: a + b end').toMatchTree(`
Assign
AssignableIdentifier add
Eq =
FunctionDef
keyword fn
keyword do
Params
AssignableIdentifier a
AssignableIdentifier b

View File

@ -27,9 +27,9 @@ describe('DotGet', () => {
})
test('function parameters are in scope within function body', () => {
expect('fn config: config.path end').toMatchTree(`
expect('do config: config.path end').toMatchTree(`
FunctionDef
keyword fn
keyword do
Params
AssignableIdentifier config
colon :
@ -41,9 +41,9 @@ describe('DotGet', () => {
})
test('parameters out of scope outside function', () => {
expect('fn x: x.prop end; x.prop').toMatchTree(`
expect('do x: x.prop end; x.prop').toMatchTree(`
FunctionDef
keyword fn
keyword do
Params
AssignableIdentifier x
colon :
@ -56,12 +56,12 @@ describe('DotGet', () => {
})
test('multiple parameters work correctly', () => {
expect(`fn x y:
expect(`do x y:
x.foo
y.bar
end`).toMatchTree(`
FunctionDef
keyword fn
keyword do
Params
AssignableIdentifier x
AssignableIdentifier y
@ -77,12 +77,12 @@ end`).toMatchTree(`
})
test('nested functions with scope isolation', () => {
expect(`fn x:
expect(`do x:
x.outer
fn y: y.inner end
do y: y.inner end
end`).toMatchTree(`
FunctionDef
keyword fn
keyword do
Params
AssignableIdentifier x
colon :
@ -90,7 +90,7 @@ end`).toMatchTree(`
IdentifierBeforeDot x
Identifier outer
FunctionDef
keyword fn
keyword do
Params
AssignableIdentifier y
colon :

View File

@ -56,11 +56,11 @@ describe('calling functions', () => {
})
})
describe('Fn', () => {
describe('Do', () => {
test('parses function no parameters', () => {
expect('fn: 1 end').toMatchTree(`
expect('do: 1 end').toMatchTree(`
FunctionDef
keyword fn
keyword do
Params
colon :
Number 1
@ -68,9 +68,9 @@ describe('Fn', () => {
})
test('parses function with single parameter', () => {
expect('fn x: x + 1 end').toMatchTree(`
expect('do x: x + 1 end').toMatchTree(`
FunctionDef
keyword fn
keyword do
Params
AssignableIdentifier x
colon :
@ -82,9 +82,9 @@ describe('Fn', () => {
})
test('parses function with multiple parameters', () => {
expect('fn x y: x * y end').toMatchTree(`
expect('do x y: x * y end').toMatchTree(`
FunctionDef
keyword fn
keyword do
Params
AssignableIdentifier x
AssignableIdentifier y
@ -97,12 +97,12 @@ describe('Fn', () => {
})
test('parses multiline function with multiple statements', () => {
expect(`fn x y:
expect(`do x y:
x * y
x + 9
end`).toMatchTree(`
FunctionDef
keyword fn
keyword do
Params
AssignableIdentifier x
AssignableIdentifier y
@ -119,12 +119,12 @@ end`).toMatchTree(`
})
test('does not parse identifiers that start with fn', () => {
expect('fnnn = fn x: x end').toMatchTree(`
expect('fnnn = do x: x end').toMatchTree(`
Assign
AssignableIdentifier fnnn
Eq =
FunctionDef
keyword fn
keyword do
Params
AssignableIdentifier x
colon :
@ -134,12 +134,12 @@ end`).toMatchTree(`
})
test('does not parse identifiers that start with end', () => {
expect('enddd = fn x: x end').toMatchTree(`
expect('enddd = do x: x end').toMatchTree(`
Assign
AssignableIdentifier enddd
Eq =
FunctionDef
keyword fn
keyword do
Params
AssignableIdentifier x
colon :

View File

@ -13,7 +13,7 @@ describe('multiline', () => {
test('parses multiline functions', () => {
expect(`
add = fn a b:
add = do a b:
result = a + b
result
end
@ -24,7 +24,7 @@ describe('multiline', () => {
AssignableIdentifier add
Eq =
FunctionDef
keyword fn
keyword do
Params
AssignableIdentifier a
AssignableIdentifier b
@ -53,7 +53,7 @@ describe('multiline', () => {
3
fn x y:
do x y:
x
end
@ -61,7 +61,7 @@ end
Number 3
FunctionDef
keyword fn
keyword do
Params
AssignableIdentifier x
AssignableIdentifier y

View File

@ -66,7 +66,7 @@ describe('pipe expressions', () => {
})
test('pipe with inline function', () => {
expect('items | each fn x: x end').toMatchTree(`
expect('items | each do x: x end').toMatchTree(`
PipeExpr
FunctionCallOrIdentifier
Identifier items
@ -75,7 +75,7 @@ describe('pipe expressions', () => {
Identifier each
PositionalArg
FunctionDef
keyword fn
keyword do
Params
AssignableIdentifier x
colon :