Compare commits
2 Commits
66671970e0
...
d306d58b2f
| Author | SHA1 | Date | |
|---|---|---|---|
| d306d58b2f | |||
| 7077762738 |
|
|
@ -63,26 +63,26 @@ describe('compiler', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
test('function', () => {
|
test('function', () => {
|
||||||
expect(`fn a b: a + b end`).toEvaluateTo(Function)
|
expect(`do a b: a + b end`).toEvaluateTo(Function)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('function call', () => {
|
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', () => {
|
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', () => {
|
test('function call with named and positional args', () => {
|
||||||
expect(`minus = fn a b: a - b end; minus b=2 9`).toEvaluateTo(7)
|
expect(`minus = do 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 = do 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 = do 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 2000 a=9000`).toEvaluateTo(7000)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('function call with no args', () => {
|
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', () => {
|
test('simple conditionals', () => {
|
||||||
|
|
@ -150,7 +150,7 @@ describe('errors', () => {
|
||||||
describe('multiline tests', () => {
|
describe('multiline tests', () => {
|
||||||
test('multiline function', () => {
|
test('multiline function', () => {
|
||||||
expect(`
|
expect(`
|
||||||
add = fn a b:
|
add = do a b:
|
||||||
result = a + b
|
result = a + b
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { describe, test, expect } from 'bun:test'
|
||||||
describe('pipe expressions', () => {
|
describe('pipe expressions', () => {
|
||||||
test('simple pipe passes result as first argument', () => {
|
test('simple pipe passes result as first argument', () => {
|
||||||
const code = `
|
const code = `
|
||||||
double = fn x: x * 2 end
|
double = do x: x * 2 end
|
||||||
double 2 | double`
|
double 2 | double`
|
||||||
|
|
||||||
expect(code).toEvaluateTo(8)
|
expect(code).toEvaluateTo(8)
|
||||||
|
|
@ -11,9 +11,9 @@ describe('pipe expressions', () => {
|
||||||
|
|
||||||
test('pipe chain with three stages', () => {
|
test('pipe chain with three stages', () => {
|
||||||
const code = `
|
const code = `
|
||||||
add-one = fn x: x + 1 end
|
add-one = do x: x + 1 end
|
||||||
double = fn x: x * 2 end
|
double = do x: x * 2 end
|
||||||
minus-point-one = fn x: x - 0.1 end
|
minus-point-one = do x: x - 0.1 end
|
||||||
add-one 3 | double | minus-point-one`
|
add-one 3 | double | minus-point-one`
|
||||||
// 4 8 7.9
|
// 4 8 7.9
|
||||||
expect(code).toEvaluateTo(7.9)
|
expect(code).toEvaluateTo(7.9)
|
||||||
|
|
@ -21,8 +21,8 @@ describe('pipe expressions', () => {
|
||||||
|
|
||||||
test('pipe with function that has additional arguments', () => {
|
test('pipe with function that has additional arguments', () => {
|
||||||
const code = `
|
const code = `
|
||||||
multiply = fn a b: a * b end
|
multiply = do a b: a * b end
|
||||||
get-five = fn: 5 end
|
get-five = do: 5 end
|
||||||
get-five | multiply 3`
|
get-five | multiply 3`
|
||||||
|
|
||||||
expect(code).toEvaluateTo(15)
|
expect(code).toEvaluateTo(15)
|
||||||
|
|
@ -31,7 +31,7 @@ describe('pipe expressions', () => {
|
||||||
test('pipe with bare identifier', () => {
|
test('pipe with bare identifier', () => {
|
||||||
const code = `
|
const code = `
|
||||||
get-value = 42
|
get-value = 42
|
||||||
process = fn x: x + 10 end
|
process = do x: x + 10 end
|
||||||
get-value | process`
|
get-value | process`
|
||||||
|
|
||||||
expect(code).toEvaluateTo(52)
|
expect(code).toEvaluateTo(52)
|
||||||
|
|
@ -39,7 +39,7 @@ describe('pipe expressions', () => {
|
||||||
|
|
||||||
test('pipe in assignment', () => {
|
test('pipe in assignment', () => {
|
||||||
const code = `
|
const code = `
|
||||||
add-ten = fn x: x + 10 end
|
add-ten = do x: x + 10 end
|
||||||
result = add-ten 5 | add-ten
|
result = add-ten 5 | add-ten
|
||||||
result`
|
result`
|
||||||
|
|
||||||
|
|
@ -49,23 +49,23 @@ describe('pipe expressions', () => {
|
||||||
|
|
||||||
test('pipe with named underscore arg', () => {
|
test('pipe with named underscore arg', () => {
|
||||||
expect(`
|
expect(`
|
||||||
divide = fn a b: a / b end
|
divide = do a b: a / b end
|
||||||
get-ten = fn: 10 end
|
get-ten = do: 10 end
|
||||||
get-ten | divide 2 b=_`).toEvaluateTo(0.2)
|
get-ten | divide 2 b=_`).toEvaluateTo(0.2)
|
||||||
|
|
||||||
expect(`
|
expect(`
|
||||||
divide = fn a b: a / b end
|
divide = do a b: a / b end
|
||||||
get-ten = fn: 10 end
|
get-ten = do: 10 end
|
||||||
get-ten | divide b=_ 2`).toEvaluateTo(0.2)
|
get-ten | divide b=_ 2`).toEvaluateTo(0.2)
|
||||||
|
|
||||||
expect(`
|
expect(`
|
||||||
divide = fn a b: a / b end
|
divide = do a b: a / b end
|
||||||
get-ten = fn: 10 end
|
get-ten = do: 10 end
|
||||||
get-ten | divide 2 a=_`).toEvaluateTo(5)
|
get-ten | divide 2 a=_`).toEvaluateTo(5)
|
||||||
|
|
||||||
expect(`
|
expect(`
|
||||||
divide = fn a b: a / b end
|
divide = do a b: a / b end
|
||||||
get-ten = fn: 10 end
|
get-ten = do: 10 end
|
||||||
get-ten | divide a=_ 2`).toEvaluateTo(5)
|
get-ten | divide a=_ 2`).toEvaluateTo(5)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -74,8 +74,8 @@ describe('pipe expressions', () => {
|
||||||
// handling logic works correctly when there are multiple pipe stages
|
// handling logic works correctly when there are multiple pipe stages
|
||||||
// in a single expression.
|
// in a single expression.
|
||||||
expect(`
|
expect(`
|
||||||
sub = fn a b: a - b end
|
sub = do a b: a - b end
|
||||||
div = fn 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)
|
sub 3 1 | div (sub 110 9 | sub 1) _ | div 5`).toEvaluateTo(10)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -245,7 +245,7 @@ const commandShapes: CommandShape[] = [
|
||||||
] as const
|
] as const
|
||||||
|
|
||||||
let commandSource = () => commandShapes
|
let commandSource = () => commandShapes
|
||||||
export const setCommandSource = (fn: () => CommandShape[]) => {
|
export const setCommandSource = (do: () => CommandShape[]) => {
|
||||||
commandSource = fn
|
commandSource = fn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,14 +21,9 @@
|
||||||
leftParen { "(" }
|
leftParen { "(" }
|
||||||
rightParen { ")" }
|
rightParen { ")" }
|
||||||
colon[closedBy="end", @name="colon"] { ":" }
|
colon[closedBy="end", @name="colon"] { ":" }
|
||||||
end[openedBy="colon", @name="end"] { "end" }
|
|
||||||
Underscore { "_" }
|
Underscore { "_" }
|
||||||
Null { "null" }
|
Null { "null" }
|
||||||
Regex { "//" (![/\\\n[] | "\\" ![\n] | "[" (![\n\\\]] | "\\" ![\n])* "]")+ ("//" $[gimsuy]*)? } // Stolen from the lezer JavaScript grammar
|
Regex { "//" (![/\\\n[] | "\\" ![\n] | "[" (![\n\\\]] | "\\" ![\n])* "]")+ ("//" $[gimsuy]*)? } // Stolen from the lezer JavaScript grammar
|
||||||
Fn[@name=keyword] { "fn" }
|
|
||||||
"if" [@name=keyword]
|
|
||||||
"elsif" [@name=keyword]
|
|
||||||
"else" [@name=keyword]
|
|
||||||
"|"[@name=operator]
|
"|"[@name=operator]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -98,11 +93,11 @@ FunctionDef {
|
||||||
}
|
}
|
||||||
|
|
||||||
singleLineFunctionDef {
|
singleLineFunctionDef {
|
||||||
Fn Params colon consumeToTerminator end
|
@specialize[@name=keyword]<Identifier, "do"> Params colon consumeToTerminator @specialize[@name=keyword]<Identifier, "end">
|
||||||
}
|
}
|
||||||
|
|
||||||
multilineFunctionDef {
|
multilineFunctionDef {
|
||||||
Fn Params colon newlineOrSemicolon block end
|
@specialize[@name=keyword]<Identifier, "do"> Params colon newlineOrSemicolon block @specialize[@name=keyword]<Identifier, "end">
|
||||||
}
|
}
|
||||||
|
|
||||||
IfExpr {
|
IfExpr {
|
||||||
|
|
@ -110,19 +105,19 @@ IfExpr {
|
||||||
}
|
}
|
||||||
|
|
||||||
singleLineIf {
|
singleLineIf {
|
||||||
"if" (ConditionalOp | expression) colon ThenBlock { consumeToTerminator }
|
@specialize[@name=keyword]<Identifier, "if"> (ConditionalOp | expression) colon ThenBlock { consumeToTerminator }
|
||||||
}
|
}
|
||||||
|
|
||||||
multilineIf {
|
multilineIf {
|
||||||
"if" (ConditionalOp | expression) colon newlineOrSemicolon ThenBlock ElsifExpr* ElseExpr? end
|
@specialize[@name=keyword]<Identifier, "if"> (ConditionalOp | expression) colon newlineOrSemicolon ThenBlock ElsifExpr* ElseExpr? @specialize[@name=keyword]<Identifier, "end">
|
||||||
}
|
}
|
||||||
|
|
||||||
ElsifExpr {
|
ElsifExpr {
|
||||||
"elsif" (ConditionalOp | expression) colon newlineOrSemicolon ThenBlock
|
@specialize[@name=keyword]<Identifier, "elsif"> (ConditionalOp | expression) colon newlineOrSemicolon ThenBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
ElseExpr {
|
ElseExpr {
|
||||||
"else" colon newlineOrSemicolon ThenBlock
|
@specialize[@name=keyword]<Identifier, "else"> colon newlineOrSemicolon ThenBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
ThenBlock {
|
ThenBlock {
|
||||||
|
|
@ -163,9 +158,14 @@ expression {
|
||||||
expressionWithoutIdentifier | DotGet | Identifier
|
expressionWithoutIdentifier | DotGet | Identifier
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@local tokens {
|
||||||
|
dot { "." }
|
||||||
|
}
|
||||||
|
|
||||||
@skip {} {
|
@skip {} {
|
||||||
DotGet {
|
DotGet {
|
||||||
IdentifierBeforeDot "." Identifier
|
IdentifierBeforeDot dot Identifier
|
||||||
}
|
}
|
||||||
|
|
||||||
String { "'" stringContent* "'" }
|
String { "'" stringContent* "'" }
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,9 @@ export const
|
||||||
Null = 32,
|
Null = 32,
|
||||||
DotGet = 33,
|
DotGet = 33,
|
||||||
FunctionDef = 34,
|
FunctionDef = 34,
|
||||||
Fn = 35,
|
keyword = 50,
|
||||||
Params = 36,
|
Params = 36,
|
||||||
colon = 37,
|
colon = 37,
|
||||||
end = 38,
|
|
||||||
Underscore = 39,
|
Underscore = 39,
|
||||||
NamedArg = 40,
|
NamedArg = 40,
|
||||||
NamedArgPrefix = 41,
|
NamedArgPrefix = 41,
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,27 @@
|
||||||
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
||||||
import {LRParser} from "@lezer/lr"
|
import {LRParser, LocalTokenGroup} from "@lezer/lr"
|
||||||
import {operatorTokenizer} from "./operatorTokenizer"
|
import {operatorTokenizer} from "./operatorTokenizer"
|
||||||
import {tokenizer} from "./tokenizer"
|
import {tokenizer} from "./tokenizer"
|
||||||
import {trackScope} from "./scopeTracker"
|
import {trackScope} from "./scopeTracker"
|
||||||
import {highlighting} from "./highlight"
|
import {highlighting} from "./highlight"
|
||||||
|
const spec_Identifier = {__proto__:null,do:70, end:76, if:88, elsif:96, else:100}
|
||||||
export const parser = LRParser.deserialize({
|
export const parser = LRParser.deserialize({
|
||||||
version: 14,
|
version: 14,
|
||||||
states: ".jQVQrOOO#XQuO'#CrO$RQRO'#CsO$aQRO'#DmO$xQrO'#CqO%gOWO'#CuOOQq'#Dq'#DqO%uOQO'#C}O%zQRO'#DpO&cQrO'#D|OOQp'#DO'#DOOOQO'#Dn'#DnO&kQQO'#DmO&yQrO'#EQOOQO'#DX'#DXO'hQRO'#DaOOQO'#Dm'#DmO'mQQO'#DlOOQp'#Dl'#DlOOQp'#Db'#DbQVQrOOOOQq'#Dp'#DpOOQp'#Cp'#CpO'uQrO'#DUOOQp'#Do'#DoOOQp'#Dc'#DcO(PQtO,59ZO&yQrO,59_O&yQrO,59_O)XQRO'#CsO)iQRO,59]O)zQRO,59]O)uQQO,59]O*uQQO,59]O*}QrO'#CwO+VQ`O'#CxOOOO'#Du'#DuOOOO'#Dd'#DdO+kOWO,59aOOQq,59a,59aO+yOpO,59iOOQp'#De'#DeO,OQrO'#DQO,WQQO,5:hO,]QrO'#DgO,bQQO,59YO,sQRO,5:lO,zQQO,5:lO-PQrO,59{OOQp,5:W,5:WOOQp-E7`-E7`OOQp,59p,59pOOQp-E7a-E7aOOQP1G.y1G.yO-^QRO1G.yO&yQrO,59`O&yQrO,59`OOQq1G.w1G.wOOOO,59c,59cOOOO,59d,59dOOOO-E7b-E7bOOQq1G.{1G.{OOQq1G/T1G/TOOQp-E7c-E7cO-xQrO1G0SO!QQtO'#CrOOQO,5:R,5:ROOQO-E7e-E7eO.YQrO1G0WOOQO1G/g1G/gOOQO1G.z1G.zO.jQRO1G.zO.tQQO7+%nO.yQrO7+%oOO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OPdgj!Q!b!c!f!k!n!q#W#XQ!r!kV!s!n#W#Xe^Od!Q!b!f!k!n!q#W#X",
|
goto: "+m!vPPPPPPPPPPPPPPPPPP!w#W#f#k#W$V$l$xP%a%aPPPP%e&OP&dPPP#fPP&gP&s&v'PP'TP&g'Z'a'h'n't'}(UPPP([(`(t)W)]*WPPP*sPPPPPP*w*wP+X+a+ad`Od!Q!b!f!k!n!q#W#XRpSiZOSd|!Q!b!f!k!n!q#W#XVhPj!czUOPS]dgjkl!Q!X!Y!b!c!f!k!n!q!x#W#XR![rdROd!Q!b!f!k!n!q#W#XQnSQ!VkR!WlQpSQ!P]Q!h!YR#P!x{UOPS]dgjkl!Q!X!Y!b!c!f!k!n!q!x#W#XTtTvdWOd!Q!b!f!k!n!q#W#XgePS]gjkl!X!Y!c!xd`Od!Q!b!f!k!n!q#W#XUfPj!cR!TgR{Xe`Od!Q!b!f!k!n!q#W#XR!m!fQ!t!nQ#Y#WR#Z#XT!y!t!zQ!}!tR#S!zQdOR!SdSjP!cR!UjQvTR!^vQzXR!azW!q!k!n#W#XR!v!qS}[qR!e}Q!z!tR#Q!zTcOdSaOdQ!g!QQ!j!bQ!l!fZ!p!k!n!q#W#Xd[Od!Q!b!f!k!n!q#W#XQqSR!d|ViPj!cdQOd!Q!b!f!k!n!q#W#XUfPj!cQmSQ!O]Q!TgQ!VkQ!WlQ!h!XQ!i!YR#O!xdWOd!Q!b!f!k!n!q#W#XdeP]gjkl!X!Y!c!xRoSTuTvmYOPdgj!Q!b!c!f!k!n!q#W#XQ!r!kV!s!n#W#Xe^Od!Q!b!f!k!n!q#W#X",
|
||||||
nodeNames: "⚠ Star Slash Plus Minus And Or Eq Neq Lt Lte Gt Gte Identifier AssignableIdentifier Word IdentifierBeforeDot Program PipeExpr FunctionCall PositionalArg ParenExpr FunctionCallOrIdentifier BinOp ConditionalOp String StringFragment Interpolation EscapeSeq Number Boolean Regex Null DotGet FunctionDef keyword Params colon end Underscore NamedArg NamedArgPrefix operator IfExpr keyword ThenBlock ThenBlock ElsifExpr keyword ElseExpr keyword Assign",
|
nodeNames: "⚠ Star Slash Plus Minus And Or Eq Neq Lt Lte Gt Gte Identifier AssignableIdentifier Word IdentifierBeforeDot Program PipeExpr FunctionCall PositionalArg ParenExpr FunctionCallOrIdentifier BinOp ConditionalOp String StringFragment Interpolation EscapeSeq Number Boolean Regex Null DotGet FunctionDef keyword Params colon keyword Underscore NamedArg NamedArgPrefix operator IfExpr keyword ThenBlock ThenBlock ElsifExpr keyword ElseExpr keyword Assign",
|
||||||
maxTerm: 84,
|
maxTerm: 84,
|
||||||
context: trackScope,
|
context: trackScope,
|
||||||
nodeProps: [
|
nodeProps: [
|
||||||
["closedBy", 37,"end"],
|
["closedBy", 37,"end"]
|
||||||
["openedBy", 38,"colon"]
|
|
||||||
],
|
],
|
||||||
propSources: [highlighting],
|
propSources: [highlighting],
|
||||||
skippedNodes: [0],
|
skippedNodes: [0],
|
||||||
repeatNodeCount: 7,
|
repeatNodeCount: 7,
|
||||||
tokenData: "JX~R|OX#{XY$jYZ%TZp#{pq$jqt#{tu%nuw#{wx%sxy%xyz&cz{#{{|&||}#{}!O&|!O!P)p!P!Q*Z!Q!['k![!]2v!]!^%T!^#O#{#O#P3a#P#R#{#R#S3f#S#T#{#T#X4P#X#Y5_#Y#Z<e#Z#]4P#]#^Ap#^#b4P#b#cCb#c#f4P#f#gFz#g#h4P#h#iGq#i#o4P#o#p#{#p#qIi#q;'S#{;'S;=`$d<%l~#{~O#{~~JSS$QUjSOt#{uw#{x#O#{#P;'S#{;'S;=`$d<%lO#{S$gP;=`<%l#{_$qUjS!_ZOt#{uw#{x#O#{#P;'S#{;'S;=`$d<%lO#{V%[UjS!rROt#{uw#{x#O#{#P;'S#{;'S;=`$d<%lO#{~%sO!j~~%xO!h~V&PUjS!fROt#{uw#{x#O#{#P;'S#{;'S;=`$d<%lO#{V&jUjS!gROt#{uw#{x#O#{#P;'S#{;'S;=`$d<%lO#{V'RWjSOt#{uw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#P#T#r#T#`3]#`#a:q#a#o3]#o;'S#r;'S;=`$Z<%lO#rU:v[jSOt#ruw#rx!_#r!_!`4Q!`#O#r#P#T#r#T#`3]#`#a;l#a#o3]#o;'S#r;'S;=`$Z<%lO#rU;sYpQjSOt#ruw#rx!_#r!_!`4Q!`#O#r#P#T#r#T#o3]#o;'S#r;'S;=`$Z<%lO#r^<jY!nWjSOt#ruw#rx!_#r!_!`4Q!`#O#r#P#T#r#T#o3]#o;'S#r;'S;=`$Z<%lO#r^=a[!mWjSOt#ruw#rx!_#r!_!`4Q!`#O#r#P#T#r#T#f3]#f#g>V#g#o3]#o;'S#r;'S;=`$Z<%lO#rU>[[jSOt#ruw#rx!_#r!_!`4Q!`#O#r#P#T#r#T#i3]#i#j7X#j#o3]#o;'S#r;'S;=`$Z<%lO#rU?XUzQjSOt#ruw#rx#O#r#P;'S#r;'S;=`$Z<%lO#r~?pO!v~",
|
||||||
tokenizers: [operatorTokenizer, 0, 1, 2, 3, tokenizer],
|
tokenizers: [operatorTokenizer, 1, 2, 3, tokenizer, new LocalTokenGroup("[~RP!O!PU~ZO!o~~", 11)],
|
||||||
topRules: {"Program":[0,17]},
|
topRules: {"Program":[0,17]},
|
||||||
|
specialized: [{term: 13, get: (value: keyof typeof spec_Identifier) => spec_Identifier[value] || -1}],
|
||||||
tokenPrec: 768
|
tokenPrec: 768
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -286,12 +286,12 @@ describe('Assign', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
test('parses assignment with functions', () => {
|
test('parses assignment with functions', () => {
|
||||||
expect('add = fn a b: a + b end').toMatchTree(`
|
expect('add = do a b: a + b end').toMatchTree(`
|
||||||
Assign
|
Assign
|
||||||
AssignableIdentifier add
|
AssignableIdentifier add
|
||||||
Eq =
|
Eq =
|
||||||
FunctionDef
|
FunctionDef
|
||||||
keyword fn
|
keyword do
|
||||||
Params
|
Params
|
||||||
AssignableIdentifier a
|
AssignableIdentifier a
|
||||||
AssignableIdentifier b
|
AssignableIdentifier b
|
||||||
|
|
@ -300,7 +300,7 @@ describe('Assign', () => {
|
||||||
Identifier a
|
Identifier a
|
||||||
Plus +
|
Plus +
|
||||||
Identifier b
|
Identifier b
|
||||||
end end`)
|
keyword end`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ describe('if/elsif/else', () => {
|
||||||
ThenBlock
|
ThenBlock
|
||||||
FunctionCallOrIdentifier
|
FunctionCallOrIdentifier
|
||||||
Identifier yes
|
Identifier yes
|
||||||
end end
|
keyword end
|
||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -68,7 +68,7 @@ describe('if/elsif/else', () => {
|
||||||
ThenBlock
|
ThenBlock
|
||||||
FunctionCallOrIdentifier
|
FunctionCallOrIdentifier
|
||||||
Identifier y
|
Identifier y
|
||||||
end end
|
keyword end
|
||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -92,7 +92,7 @@ describe('if/elsif/else', () => {
|
||||||
ThenBlock
|
ThenBlock
|
||||||
FunctionCallOrIdentifier
|
FunctionCallOrIdentifier
|
||||||
Identifier y
|
Identifier y
|
||||||
end end
|
keyword end
|
||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -133,7 +133,21 @@ describe('if/elsif/else', () => {
|
||||||
ThenBlock
|
ThenBlock
|
||||||
FunctionCallOrIdentifier
|
FunctionCallOrIdentifier
|
||||||
Identifier oh-no
|
Identifier oh-no
|
||||||
end end
|
keyword end
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('does not parse identifiers that start with if', () => {
|
||||||
|
expect('iffy = if true: 2').toMatchTree(`
|
||||||
|
Assign
|
||||||
|
AssignableIdentifier iffy
|
||||||
|
Eq =
|
||||||
|
IfExpr
|
||||||
|
keyword if
|
||||||
|
Boolean true
|
||||||
|
colon :
|
||||||
|
ThenBlock
|
||||||
|
Number 2
|
||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -27,41 +27,41 @@ describe('DotGet', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
test('function parameters are in scope within function body', () => {
|
test('function parameters are in scope within function body', () => {
|
||||||
expect('fn config: config.path end').toMatchTree(`
|
expect('do config: config.path end').toMatchTree(`
|
||||||
FunctionDef
|
FunctionDef
|
||||||
keyword fn
|
keyword do
|
||||||
Params
|
Params
|
||||||
AssignableIdentifier config
|
AssignableIdentifier config
|
||||||
colon :
|
colon :
|
||||||
DotGet
|
DotGet
|
||||||
IdentifierBeforeDot config
|
IdentifierBeforeDot config
|
||||||
Identifier path
|
Identifier path
|
||||||
end end
|
keyword end
|
||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('parameters out of scope outside function', () => {
|
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
|
FunctionDef
|
||||||
keyword fn
|
keyword do
|
||||||
Params
|
Params
|
||||||
AssignableIdentifier x
|
AssignableIdentifier x
|
||||||
colon :
|
colon :
|
||||||
DotGet
|
DotGet
|
||||||
IdentifierBeforeDot x
|
IdentifierBeforeDot x
|
||||||
Identifier prop
|
Identifier prop
|
||||||
end end
|
keyword end
|
||||||
Word x.prop
|
Word x.prop
|
||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('multiple parameters work correctly', () => {
|
test('multiple parameters work correctly', () => {
|
||||||
expect(`fn x y:
|
expect(`do x y:
|
||||||
x.foo
|
x.foo
|
||||||
y.bar
|
y.bar
|
||||||
end`).toMatchTree(`
|
end`).toMatchTree(`
|
||||||
FunctionDef
|
FunctionDef
|
||||||
keyword fn
|
keyword do
|
||||||
Params
|
Params
|
||||||
AssignableIdentifier x
|
AssignableIdentifier x
|
||||||
AssignableIdentifier y
|
AssignableIdentifier y
|
||||||
|
|
@ -72,17 +72,17 @@ end`).toMatchTree(`
|
||||||
DotGet
|
DotGet
|
||||||
IdentifierBeforeDot y
|
IdentifierBeforeDot y
|
||||||
Identifier bar
|
Identifier bar
|
||||||
end end
|
keyword end
|
||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('nested functions with scope isolation', () => {
|
test('nested functions with scope isolation', () => {
|
||||||
expect(`fn x:
|
expect(`do x:
|
||||||
x.outer
|
x.outer
|
||||||
fn y: y.inner end
|
do y: y.inner end
|
||||||
end`).toMatchTree(`
|
end`).toMatchTree(`
|
||||||
FunctionDef
|
FunctionDef
|
||||||
keyword fn
|
keyword do
|
||||||
Params
|
Params
|
||||||
AssignableIdentifier x
|
AssignableIdentifier x
|
||||||
colon :
|
colon :
|
||||||
|
|
@ -90,15 +90,15 @@ end`).toMatchTree(`
|
||||||
IdentifierBeforeDot x
|
IdentifierBeforeDot x
|
||||||
Identifier outer
|
Identifier outer
|
||||||
FunctionDef
|
FunctionDef
|
||||||
keyword fn
|
keyword do
|
||||||
Params
|
Params
|
||||||
AssignableIdentifier y
|
AssignableIdentifier y
|
||||||
colon :
|
colon :
|
||||||
DotGet
|
DotGet
|
||||||
IdentifierBeforeDot y
|
IdentifierBeforeDot y
|
||||||
Identifier inner
|
Identifier inner
|
||||||
end end
|
keyword end
|
||||||
end end
|
keyword end
|
||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,21 +56,21 @@ describe('calling functions', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Fn', () => {
|
describe('Do', () => {
|
||||||
test('parses function no parameters', () => {
|
test('parses function no parameters', () => {
|
||||||
expect('fn: 1 end').toMatchTree(`
|
expect('do: 1 end').toMatchTree(`
|
||||||
FunctionDef
|
FunctionDef
|
||||||
keyword fn
|
keyword do
|
||||||
Params
|
Params
|
||||||
colon :
|
colon :
|
||||||
Number 1
|
Number 1
|
||||||
end end`)
|
keyword end`)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('parses function with single parameter', () => {
|
test('parses function with single parameter', () => {
|
||||||
expect('fn x: x + 1 end').toMatchTree(`
|
expect('do x: x + 1 end').toMatchTree(`
|
||||||
FunctionDef
|
FunctionDef
|
||||||
keyword fn
|
keyword do
|
||||||
Params
|
Params
|
||||||
AssignableIdentifier x
|
AssignableIdentifier x
|
||||||
colon :
|
colon :
|
||||||
|
|
@ -78,13 +78,13 @@ describe('Fn', () => {
|
||||||
Identifier x
|
Identifier x
|
||||||
Plus +
|
Plus +
|
||||||
Number 1
|
Number 1
|
||||||
end end`)
|
keyword end`)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('parses function with multiple parameters', () => {
|
test('parses function with multiple parameters', () => {
|
||||||
expect('fn x y: x * y end').toMatchTree(`
|
expect('do x y: x * y end').toMatchTree(`
|
||||||
FunctionDef
|
FunctionDef
|
||||||
keyword fn
|
keyword do
|
||||||
Params
|
Params
|
||||||
AssignableIdentifier x
|
AssignableIdentifier x
|
||||||
AssignableIdentifier y
|
AssignableIdentifier y
|
||||||
|
|
@ -93,16 +93,16 @@ describe('Fn', () => {
|
||||||
Identifier x
|
Identifier x
|
||||||
Star *
|
Star *
|
||||||
Identifier y
|
Identifier y
|
||||||
end end`)
|
keyword end`)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('parses multiline function with multiple statements', () => {
|
test('parses multiline function with multiple statements', () => {
|
||||||
expect(`fn x y:
|
expect(`do x y:
|
||||||
x * y
|
x * y
|
||||||
x + 9
|
x + 9
|
||||||
end`).toMatchTree(`
|
end`).toMatchTree(`
|
||||||
FunctionDef
|
FunctionDef
|
||||||
keyword fn
|
keyword do
|
||||||
Params
|
Params
|
||||||
AssignableIdentifier x
|
AssignableIdentifier x
|
||||||
AssignableIdentifier y
|
AssignableIdentifier y
|
||||||
|
|
@ -115,6 +115,36 @@ end`).toMatchTree(`
|
||||||
Identifier x
|
Identifier x
|
||||||
Plus +
|
Plus +
|
||||||
Number 9
|
Number 9
|
||||||
end end`)
|
keyword end`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('does not parse identifiers that start with fn', () => {
|
||||||
|
expect('fnnn = do x: x end').toMatchTree(`
|
||||||
|
Assign
|
||||||
|
AssignableIdentifier fnnn
|
||||||
|
Eq =
|
||||||
|
FunctionDef
|
||||||
|
keyword do
|
||||||
|
Params
|
||||||
|
AssignableIdentifier x
|
||||||
|
colon :
|
||||||
|
FunctionCallOrIdentifier
|
||||||
|
Identifier x
|
||||||
|
keyword end`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('does not parse identifiers that start with end', () => {
|
||||||
|
expect('enddd = do x: x end').toMatchTree(`
|
||||||
|
Assign
|
||||||
|
AssignableIdentifier enddd
|
||||||
|
Eq =
|
||||||
|
FunctionDef
|
||||||
|
keyword do
|
||||||
|
Params
|
||||||
|
AssignableIdentifier x
|
||||||
|
colon :
|
||||||
|
FunctionCallOrIdentifier
|
||||||
|
Identifier x
|
||||||
|
keyword end`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ describe('multiline', () => {
|
||||||
|
|
||||||
test('parses multiline functions', () => {
|
test('parses multiline functions', () => {
|
||||||
expect(`
|
expect(`
|
||||||
add = fn a b:
|
add = do a b:
|
||||||
result = a + b
|
result = a + b
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
@ -24,7 +24,7 @@ describe('multiline', () => {
|
||||||
AssignableIdentifier add
|
AssignableIdentifier add
|
||||||
Eq =
|
Eq =
|
||||||
FunctionDef
|
FunctionDef
|
||||||
keyword fn
|
keyword do
|
||||||
Params
|
Params
|
||||||
AssignableIdentifier a
|
AssignableIdentifier a
|
||||||
AssignableIdentifier b
|
AssignableIdentifier b
|
||||||
|
|
@ -39,7 +39,7 @@ describe('multiline', () => {
|
||||||
FunctionCallOrIdentifier
|
FunctionCallOrIdentifier
|
||||||
Identifier result
|
Identifier result
|
||||||
|
|
||||||
end end
|
keyword end
|
||||||
FunctionCall
|
FunctionCall
|
||||||
Identifier add
|
Identifier add
|
||||||
PositionalArg
|
PositionalArg
|
||||||
|
|
@ -53,7 +53,7 @@ describe('multiline', () => {
|
||||||
3
|
3
|
||||||
|
|
||||||
|
|
||||||
fn x y:
|
do x y:
|
||||||
x
|
x
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -61,14 +61,14 @@ end
|
||||||
Number 3
|
Number 3
|
||||||
|
|
||||||
FunctionDef
|
FunctionDef
|
||||||
keyword fn
|
keyword do
|
||||||
Params
|
Params
|
||||||
AssignableIdentifier x
|
AssignableIdentifier x
|
||||||
AssignableIdentifier y
|
AssignableIdentifier y
|
||||||
colon :
|
colon :
|
||||||
FunctionCallOrIdentifier
|
FunctionCallOrIdentifier
|
||||||
Identifier x
|
Identifier x
|
||||||
end end
|
keyword end
|
||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ describe('pipe expressions', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
test('pipe with inline function', () => {
|
test('pipe with inline function', () => {
|
||||||
expect('items | each fn x: x end').toMatchTree(`
|
expect('items | each do x: x end').toMatchTree(`
|
||||||
PipeExpr
|
PipeExpr
|
||||||
FunctionCallOrIdentifier
|
FunctionCallOrIdentifier
|
||||||
Identifier items
|
Identifier items
|
||||||
|
|
@ -75,13 +75,13 @@ describe('pipe expressions', () => {
|
||||||
Identifier each
|
Identifier each
|
||||||
PositionalArg
|
PositionalArg
|
||||||
FunctionDef
|
FunctionDef
|
||||||
keyword fn
|
keyword do
|
||||||
Params
|
Params
|
||||||
AssignableIdentifier x
|
AssignableIdentifier x
|
||||||
colon :
|
colon :
|
||||||
FunctionCallOrIdentifier
|
FunctionCallOrIdentifier
|
||||||
Identifier x
|
Identifier x
|
||||||
end end
|
keyword end
|
||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user