Skip to content

Commit adcec33

Browse files
authored
Temporarily disable all parsing of lambda body/return statement (#1)
* Killing a kitten - Removed all parsing of return statements - All tests are failing - Ambiguity increased to 2 - Hopefully we can come back and try to address this once we have Cypher parser available * making tests pass
1 parent 3cb8efc commit adcec33

File tree

4 files changed

+144
-657
lines changed

4 files changed

+144
-657
lines changed

debug.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import parseLambda from './parse-lambda';
1+
import {parseLambda} from './src';
22

33
const something = `[{x}] => { CALL db.labels() YIELD label
44
@@ -9,10 +9,10 @@ foo
99
1010
RETURN 1
1111
}`;
12-
const result1 = parseLambda(something)
13-
const result2 = parseLambda('x => {asdsd RETURN rand() }')
14-
const result3 = parseLambda('[{rand():x}] => { RETURN rand() AS bar }')
15-
const result4 = parseLambda('x1 => "foo"')
12+
// const result1 = parseLambda(something)
13+
const result2 = parseLambda('x => { \n \n \n asdsd RETURN rand() }')
14+
// const result3 = parseLambda('[{rand():x}] => { RETURN rand() AS bar }')
15+
// const result4 = parseLambda('x1 => "foo"')
1616

17-
console.log(JSON.stringify(result1, null, 2));
18-
console.log(`Ambiguity ${result1.length}`)
17+
console.log(JSON.stringify(result2, null, 2));
18+
console.log(`Ambiguity ${result2.length}`)

src/grammar.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,10 @@ let ParserRules = [
144144
},
145145
{"name": "lambda", "symbols": ["explicitParameters", "FAT_ARROW", "explicitReturn"], "postprocess": ([parameters,,body]) => ({type: 'lambda', variant: 'explicit', parameters, body})},
146146
{"name": "lambda", "symbols": ["implicitParameters", "FAT_ARROW", "implicitReturn"], "postprocess": ([parameters,,body]) => ({type: 'lambda', variant: 'implicit', parameters, body})},
147-
{"name": "explicitReturn", "symbols": ["L_CURLY", "singleLine", "multiLine", "__", "RETURN", "returnValues", "R_CURLY"], "postprocess": ([,statement1, statement2,,, returnValues]) => ({statement: [statement1, statement2].join('\n').trim(), returnValues})},
148-
{"name": "explicitReturn", "symbols": ["L_CURLY", "multiLine", "__", "RETURN", "returnValues", "R_CURLY"], "postprocess": ([,statement,,, returnValues]) => ({statement, returnValues})},
149-
{"name": "explicitReturn", "symbols": ["L_CURLY", "singleLine", "__", "RETURN", "returnValues", "R_CURLY"], "postprocess": ([,statement,,, returnValues]) => ({statement, returnValues})},
150-
{"name": "explicitReturn", "symbols": ["L_CURLY", "_", "RETURN", "returnValues", "R_CURLY"], "postprocess": ([,,, returnValues]) => ({statement: '', returnValues})},
151-
{"name": "implicitReturn", "symbols": ["returnValue"], "postprocess": ([returnValue]) => ({returnValues: [returnValue]})},
147+
{"name": "explicitReturn", "symbols": ["L_CURLY", "singleLine", "multiLine", "R_CURLY"], "postprocess": ([,statement1, statement2]) => ({statement: [statement1, statement2].join('\n').trim(), returnValues: []})},
148+
{"name": "explicitReturn", "symbols": ["L_CURLY", "multiLine", "R_CURLY"], "postprocess": ([,statement]) => ({statement, returnValues: []})},
149+
{"name": "explicitReturn", "symbols": ["L_CURLY", "singleLine", "R_CURLY"], "postprocess": ([,statement]) => ({statement, returnValues: []})},
150+
{"name": "implicitReturn", "symbols": ["singleLine"], "postprocess": ([statement], _, reject) => statement.trim().startsWith('{') ? reject : ({returnValues: []})},
152151
{"name": "returnValues", "symbols": ["returnValue", "COMMA", "returnValues"], "postprocess": ([hit,, rest]) => [hit, ...rest]},
153152
{"name": "returnValues", "symbols": ["returnValue"]},
154153
{"name": "returnValue", "symbols": ["value", "AS", "token"], "postprocess": ([original,, name]) => ({...original, alias: name.value})},
@@ -197,6 +196,7 @@ let ParserRules = [
197196
{"name": "chars", "symbols": [/[a-zA-Z]/, "chars$ebnf$1"], "postprocess": ([value, rest]) => `${value}${rest.join('')}`},
198197
{"name": "multiLine", "symbols": ["newLine", "singleLine", "multiLine"], "postprocess": ([, hit, rest], _ , reject) => rest ? [hit, rest].join('\n').trim()reject},
199198
{"name": "multiLine", "symbols": ["newLine", "multiLine"], "postprocess": ([hit, rest]) => [hit, rest].join('\n').trim()},
199+
{"name": "multiLine", "symbols": ["newLine", "singleLine"], "postprocess": ([hit, rest]) => [hit, rest].join('\n').trim()},
200200
{"name": "multiLine", "symbols": ["newLine"], "postprocess": id},
201201
{"name": "singleLine$ebnf$1", "symbols": [/[^\n]/]},
202202
{"name": "singleLine$ebnf$1", "symbols": ["singleLine$ebnf$1", /[^\n]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},

src/grammar.ne

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ lambda -> explicitParameters FAT_ARROW explicitReturn {% ([parameters,,body]) =>
1111
| implicitParameters FAT_ARROW implicitReturn {% ([parameters,,body]) => ({type: 'lambda', variant: 'implicit', parameters, body}) %}
1212

1313
# { RETURN ... }
14-
explicitReturn -> L_CURLY singleLine multiLine __ RETURN returnValues R_CURLY {% ([,statement1, statement2,,, returnValues]) => ({statement: [statement1, statement2].join('\n').trim(), returnValues}) %}
15-
| L_CURLY multiLine __ RETURN returnValues R_CURLY {% ([,statement,,, returnValues]) => ({statement, returnValues}) %}
16-
| L_CURLY singleLine __ RETURN returnValues R_CURLY {% ([,statement,,, returnValues]) => ({statement, returnValues}) %}
17-
| L_CURLY _ RETURN returnValues R_CURLY {% ([,,, returnValues]) => ({statement: '', returnValues}) %}
14+
explicitReturn -> L_CURLY singleLine multiLine R_CURLY {% ([,statement1, statement2]) => ({statement: [statement1, statement2].join('\n').trim(), returnValues: []}) %}
15+
| L_CURLY multiLine R_CURLY {% ([,statement]) => ({statement, returnValues: []}) %}
16+
| L_CURLY singleLine R_CURLY {% ([,statement]) => ({statement, returnValues: []}) %}
1817

1918
# ...
20-
implicitReturn -> returnValue {% ([returnValue]) => ({returnValues: [returnValue]}) %}
19+
implicitReturn -> singleLine {% ([statement], _, reject) => statement.trim().startsWith('{') ? reject : ({returnValues: []}) %}
2120

2221
# RETURN hi AS foo, rand() AS bar
2322
returnValues -> returnValue COMMA returnValues {% ([hit,, rest]) => [hit, ...rest] %}
@@ -105,6 +104,7 @@ chars -> [a-zA-Z] [a-zA-Z0-9]:* {% ([value, rest]) => `${value}${rest.join('')}`
105104

106105
multiLine -> newLine singleLine multiLine {% ([, hit, rest], _ , reject) => rest ? [hit, rest].join('\n').trim() : reject %}
107106
| newLine multiLine {% ([hit, rest]) => [hit, rest].join('\n').trim() %} # щ(゚Д゚щ)
107+
| newLine singleLine {% ([hit, rest]) => [hit, rest].join('\n').trim() %}
108108
| newLine {% id %}
109109

110110
singleLine -> [^\n]:+ {% ([hit], _, reject) => hit.join('').trim() %}

0 commit comments

Comments
 (0)