@@ -2188,13 +2188,14 @@ local function parseActions()
2188
2188
end
2189
2189
end
2190
2190
2191
- local function parseParams (params )
2191
+ local function parseParams (params , isLambda )
2192
2192
local lastSep
2193
2193
local hasDots
2194
+ local endToken = isLambda and ' |' or ' )'
2194
2195
while true do
2195
2196
skipSpace ()
2196
2197
local token = Tokens [Index + 1 ]
2197
- if not token or token == ' ) ' then
2198
+ if not token or token == endToken then
2198
2199
if lastSep then
2199
2200
missName ()
2200
2201
end
@@ -2269,7 +2270,7 @@ local function parseParams(params)
2269
2270
Index = Index + 2
2270
2271
goto CONTINUE
2271
2272
end
2272
- skipUnknownSymbol ' %,%) %.'
2273
+ skipUnknownSymbol ( ' %,%' .. endToken .. ' %.' )
2273
2274
:: CONTINUE::
2274
2275
end
2275
2276
return params
@@ -2393,6 +2394,91 @@ local function parseFunction(isLocal, isAction)
2393
2394
return func
2394
2395
end
2395
2396
2397
+ local function parseLambda (isDoublePipe )
2398
+ local lambdaLeft = getPosition (Tokens [Index ], ' left' )
2399
+ local lambdaRight = getPosition (Tokens [Index ], ' right' )
2400
+ local lambda = {
2401
+ type = ' function' ,
2402
+ start = lambdaLeft ,
2403
+ finish = lambdaRight ,
2404
+ bstart = lambdaRight ,
2405
+ keyword = {
2406
+ [1 ] = lambdaLeft ,
2407
+ [2 ] = lambdaRight ,
2408
+ },
2409
+ hasReturn = true
2410
+ }
2411
+ Index = Index + 2
2412
+ local pipeLeft = getPosition (Tokens [Index ], ' left' )
2413
+ local pipeRight = getPosition (Tokens [Index ], ' right' )
2414
+ skipSpace (true )
2415
+ local params
2416
+ local LastLocalCount = LocalCount
2417
+ -- if nonstandardSymbol for '||' is true it is possible for token to be || when there are no params
2418
+ if isDoublePipe then
2419
+ params = {
2420
+ start = pipeLeft ,
2421
+ finish = pipeRight ,
2422
+ parent = lambda ,
2423
+ type = ' funcargs'
2424
+ }
2425
+ else
2426
+ -- fake chunk to store locals
2427
+ pushChunk (lambda )
2428
+ LocalCount = 0
2429
+ params = parseParams ({}, true )
2430
+ params .type = ' funcargs'
2431
+ params .start = pipeLeft
2432
+ params .finish = lastRightPosition ()
2433
+ params .parent = lambda
2434
+ lambda .args = params
2435
+ skipSpace ()
2436
+ if Tokens [Index + 1 ] == ' |' then
2437
+ pipeRight = getPosition (Tokens [Index ], ' right' )
2438
+ lambda .finish = pipeRight
2439
+ lambda .bstart = pipeRight
2440
+ if params then
2441
+ params .finish = pipeRight
2442
+ end
2443
+ Index = Index + 2
2444
+ skipSpace ()
2445
+ else
2446
+ lambda .finish = lastRightPosition ()
2447
+ lambda .bstart = lambda .finish
2448
+ if params then
2449
+ params .finish = lambda .finish
2450
+ end
2451
+ missSymbol ' |'
2452
+ end
2453
+ end
2454
+ local child = parseExp ()
2455
+
2456
+
2457
+ -- don't want popChunk logic here as this is not a real chunk
2458
+ Chunk [# Chunk ] = nil
2459
+
2460
+ if child then
2461
+ -- create dummy return
2462
+ local rtn = {
2463
+ type = ' return' ,
2464
+ start = child .start ,
2465
+ finish = child .finish ,
2466
+ parent = lambda ,
2467
+ [1 ] = child }
2468
+ child .parent = rtn
2469
+ lambda [1 ] = rtn
2470
+ lambda .returns = {rtn }
2471
+ lambda .finish = child .finish
2472
+ lambda .keyword [3 ] = child .finish
2473
+ lambda .keyword [4 ] = child .finish
2474
+ else
2475
+ lambda .finish = lastRightPosition ()
2476
+ missExp ()
2477
+ end
2478
+ LocalCount = LastLocalCount
2479
+ return lambda
2480
+ end
2481
+
2396
2482
local function checkNeedParen (source )
2397
2483
local token = Tokens [Index + 1 ]
2398
2484
if token ~= ' .'
@@ -2485,6 +2571,12 @@ local function parseExpUnit()
2485
2571
return parseFunction ()
2486
2572
end
2487
2573
2574
+ -- FIXME: Use something other than nonstandardSymbol to check for lambda support
2575
+ if State .options .nonstandardSymbol [' |lambda|' ] and (token == ' |'
2576
+ or token == ' ||' ) then
2577
+ return parseLambda (token == ' ||' )
2578
+ end
2579
+
2488
2580
local node = parseName ()
2489
2581
if node then
2490
2582
local nameNode = resolveName (node )
0 commit comments