fix #1214
This commit is contained in:
parent
8cbbdf5489
commit
19a44eb12f
|
@ -197,7 +197,7 @@ describe("Peggy parse", () => {
|
||||||
|
|
||||||
describe("lambda", () => {
|
describe("lambda", () => {
|
||||||
testParse("{|x| x}", "{{|:x| :x}}")
|
testParse("{|x| x}", "{{|:x| :x}}")
|
||||||
testParse("f={|x| x}", "{:f = {{|:x| :x}}}")
|
testParse("f={|x| x}", "{:f = {|:x| :x}}")
|
||||||
testParse("f(x)=x", "{:f = {|:x| {:x}}}") // Function definitions are lambda assignments
|
testParse("f(x)=x", "{:f = {|:x| {:x}}}") // Function definitions are lambda assignments
|
||||||
testParse("f(x)=x ? 1 : 0", "{:f = {|:x| {(::$$_ternary_$$ :x 1 0)}}}") // Function definitions are lambda assignments
|
testParse("f(x)=x ? 1 : 0", "{:f = {|:x| {(::$$_ternary_$$ :x 1 0)}}}") // Function definitions are lambda assignments
|
||||||
})
|
})
|
||||||
|
|
|
@ -135,7 +135,7 @@ describe("Peggy to Expression", () => {
|
||||||
|
|
||||||
describe("lambda", () => {
|
describe("lambda", () => {
|
||||||
testToExpression("{|x| x}", "{|x| x}", ~v="lambda(x=>internal code)", ())
|
testToExpression("{|x| x}", "{|x| x}", ~v="lambda(x=>internal code)", ())
|
||||||
testToExpression("f={|x| x}", "f = {{|x| x}}", ())
|
testToExpression("f={|x| x}", "f = {|x| x}", ())
|
||||||
testToExpression("f(x)=x", "f = {|x| {x}}", ()) // Function definitions are lambda assignments
|
testToExpression("f(x)=x", "f = {|x| {x}}", ()) // Function definitions are lambda assignments
|
||||||
testToExpression("f(x)=x ? 1 : 0", "f = {|x| {x ? (1) : (0)}}", ())
|
testToExpression("f(x)=x ? 1 : 0", "f = {|x| {x ? (1) : (0)}}", ())
|
||||||
})
|
})
|
||||||
|
|
|
@ -102,7 +102,7 @@ describe("stacktraces", () => {
|
||||||
)->toBe(`Error: There are function matches for add(), but with different arguments: [add(number, number)]; [add(distribution, number)]; [add(number, distribution)]; [add(distribution, distribution)]; [add(date, duration)]; [add(duration, duration)]
|
)->toBe(`Error: There are function matches for add(), but with different arguments: [add(number, number)]; [add(distribution, number)]; [add(number, distribution)]; [add(distribution, distribution)]; [add(date, duration)]; [add(duration, duration)]
|
||||||
Stack trace:
|
Stack trace:
|
||||||
f at line 4, column 5
|
f at line 4, column 5
|
||||||
<anonymous> at line 6, column 12
|
g at line 6, column 12
|
||||||
h at line 7, column 10
|
h at line 7, column 10
|
||||||
<top> at line 8, column 3
|
<top> at line 8, column 3
|
||||||
`)
|
`)
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
start
|
start
|
||||||
= _nl start:outerBlock _nl finalComment? {return start}
|
= _nl start:outerBlock _nl finalComment? {return start}
|
||||||
|
|
||||||
zeroOMoreArgumentsBlockOrExpression = innerBlockOrExpression / lambda
|
zeroOMoreArgumentsBlockOrExpression = lambda / innerBlockOrExpression
|
||||||
|
|
||||||
outerBlock
|
outerBlock
|
||||||
= statements:array_statements finalExpression: (statementSeparator @expression)?
|
= statements:array_statements finalExpression: (statementSeparator @expression)?
|
||||||
|
|
|
@ -228,7 +228,9 @@ export function nodeLetStatement(
|
||||||
value: AnyPeggyNode,
|
value: AnyPeggyNode,
|
||||||
location: LocationRange
|
location: LocationRange
|
||||||
): NodeLetStatement {
|
): NodeLetStatement {
|
||||||
return { type: "LetStatement", variable, value, location };
|
const patchedValue =
|
||||||
|
value.type === "Lambda" ? { ...value, name: variable.value } : value;
|
||||||
|
return { type: "LetStatement", variable, value: patchedValue, location };
|
||||||
}
|
}
|
||||||
export function nodeModuleIdentifier(value: string, location: LocationRange) {
|
export function nodeModuleIdentifier(value: string, location: LocationRange) {
|
||||||
return { type: "ModuleIdentifier", value, location };
|
return { type: "ModuleIdentifier", value, location };
|
||||||
|
|
Loading…
Reference in New Issue
Block a user