@@ -356,8 +356,8 @@ IMPORT_NAME_LIST :: { [Expression A0] }
356
356
BLOCKS :: { [ Block A0 ] } : BLOCKS BLOCK { $ 2 : $ 1 } | {- EMPTY -} { [ ] }
357
357
358
358
BLOCK :: { Block A0 }
359
- : IF_BLOCK NEWLINE { $ 1 }
360
- | CASE_BLOCK NEWLINE { $ 1 }
359
+ : IF_BLOCK MAYBE_COMMENT NEWLINE { $ 1 }
360
+ | CASE_BLOCK MAYBE_COMMENT NEWLINE { $ 1 }
361
361
| INTEGER_LITERAL STATEMENT MAYBE_COMMENT NEWLINE
362
362
{ BlStatement () (getTransSpan $ 1 $ 2 ) (Just $ 1 ) $ 2 }
363
363
| STATEMENT MAYBE_COMMENT NEWLINE { BlStatement () (getSpan $ 1 ) Nothing $ 1 }
@@ -369,38 +369,38 @@ BLOCK :: { Block A0 }
369
369
370
370
IF_BLOCK :: { Block A0 }
371
371
IF_BLOCK
372
- : if ' (' EXPRESSION ' )' then NEWLINE BLOCKS ELSE_BLOCKS
372
+ : if ' (' EXPRESSION ' )' then MAYBE_COMMENT NEWLINE BLOCKS ELSE_BLOCKS
373
373
{ let { startSpan = getSpan $ 1 ;
374
- (endSpan, conds, blocks, endLabel) = $ 8 ;
374
+ (endSpan, conds, blocks, endLabel) = $ 9 ;
375
375
span = getTransSpan startSpan endSpan }
376
- in BlIf () span Nothing Nothing ((Just $ 3 ): conds) ((reverse $ 7 ): blocks) endLabel }
377
- | id ' :' if ' (' EXPRESSION ' )' then NEWLINE BLOCKS ELSE_BLOCKS
376
+ in BlIf () span Nothing Nothing ((Just $ 3 ): conds) ((reverse $ 8 ): blocks) endLabel }
377
+ | id ' :' if ' (' EXPRESSION ' )' then MAYBE_COMMENT NEWLINE BLOCKS ELSE_BLOCKS
378
378
{ let { TId startSpan startName = $ 1 ;
379
- (endSpan, conds, blocks, endLabel) = $ 10 ;
379
+ (endSpan, conds, blocks, endLabel) = $ 11 ;
380
380
span = getTransSpan startSpan endSpan }
381
- in BlIf () span Nothing (Just startName) ((Just $ 5 ): conds) ((reverse $ 9 ): blocks) endLabel }
382
- | INTEGER_LITERAL if ' (' EXPRESSION ' )' then NEWLINE BLOCKS ELSE_BLOCKS
381
+ in BlIf () span Nothing (Just startName) ((Just $ 5 ): conds) ((reverse $ 10 ): blocks) endLabel }
382
+ | INTEGER_LITERAL if ' (' EXPRESSION ' )' then MAYBE_COMMENT NEWLINE BLOCKS ELSE_BLOCKS
383
383
{ let { startSpan = getSpan $ 1 ;
384
384
startLabel = Just $ 1 ;
385
- (endSpan, conds, blocks, endLabel) = $ 9 ;
385
+ (endSpan, conds, blocks, endLabel) = $ 10 ;
386
386
span = getTransSpan startSpan endSpan }
387
- in BlIf () span startLabel Nothing ((Just $ 4 ): conds) ((reverse $ 8 ): blocks) endLabel }
388
- | INTEGER_LITERAL id ' :' if ' (' EXPRESSION ' )' then NEWLINE BLOCKS ELSE_BLOCKS
387
+ in BlIf () span startLabel Nothing ((Just $ 4 ): conds) ((reverse $ 9 ): blocks) endLabel }
388
+ | INTEGER_LITERAL id ' :' if ' (' EXPRESSION ' )' then MAYBE_COMMENT NEWLINE BLOCKS ELSE_BLOCKS
389
389
{ let { startSpan = getSpan $ 1 ;
390
390
startLabel = Just $ 1 ;
391
391
TId _ startName = $ 2 ;
392
- (endSpan, conds, blocks, endLabel) = $ 11 ;
392
+ (endSpan, conds, blocks, endLabel) = $ 12 ;
393
393
span = getTransSpan startSpan endSpan }
394
- in BlIf () span startLabel (Just startName) ((Just $ 6 ): conds) ((reverse $ 10 ): blocks) endLabel }
394
+ in BlIf () span startLabel (Just startName) ((Just $ 6 ): conds) ((reverse $ 11 ): blocks) endLabel }
395
395
396
396
ELSE_BLOCKS :: { (SrcSpan , [Maybe (Expression A0 )], [[Block A0 ]], Maybe (Expression A0 )) }
397
397
ELSE_BLOCKS
398
- : maybe (INTEGER_LITERAL ) elsif ' (' EXPRESSION ' )' then NEWLINE BLOCKS ELSE_BLOCKS
399
- { let (endSpan, conds, blocks, endLabel) = $ 9
400
- in (endSpan, Just $ 4 : conds, reverse $ 8 : blocks, endLabel) }
401
- | maybe (INTEGER_LITERAL ) else NEWLINE BLOCKS END_IF
402
- { let (endSpan, endLabel) = $ 5
403
- in (endSpan, [Nothing ], [reverse $ 4 ], endLabel) }
398
+ : maybe (INTEGER_LITERAL ) elsif ' (' EXPRESSION ' )' then MAYBE_COMMENT NEWLINE BLOCKS ELSE_BLOCKS
399
+ { let (endSpan, conds, blocks, endLabel) = $ 10
400
+ in (endSpan, Just $ 4 : conds, reverse $ 9 : blocks, endLabel) }
401
+ | maybe (INTEGER_LITERAL ) else MAYBE_COMMENT NEWLINE BLOCKS END_IF
402
+ { let (endSpan, endLabel) = $ 6
403
+ in (endSpan, [Nothing ], [reverse $ 5 ], endLabel) }
404
404
| END_IF { let (endSpan, endLabel) = $ 1 in (endSpan, [] , [] , endLabel) }
405
405
406
406
END_IF :: { (SrcSpan , Maybe (Expression A0 )) }
@@ -412,32 +412,40 @@ END_IF
412
412
413
413
CASE_BLOCK :: { Block A0 }
414
414
CASE_BLOCK
415
- : selectcase ' (' EXPRESSION ' )' NEWLINE CASES
416
- { let { (caseRanges, blocks, endLabel, endSpan) = $ 6 ;
415
+ : selectcase ' (' EXPRESSION ' )' MAYBE_COMMENT NEWLINE CASES
416
+ { let { (caseRanges, blocks, endLabel, endSpan) = $ 7 ;
417
417
span = getTransSpan $ 1 endSpan }
418
418
in BlCase () span Nothing Nothing $ 3 caseRanges blocks endLabel }
419
- | INTEGER_LITERAL selectcase ' (' EXPRESSION ' )' NEWLINE CASES
420
- { let { (caseRanges, blocks, endLabel, endSpan) = $ 7 ;
419
+ | INTEGER_LITERAL selectcase ' (' EXPRESSION ' )' MAYBE_COMMENT NEWLINE CASES
420
+ { let { (caseRanges, blocks, endLabel, endSpan) = $ 8 ;
421
421
span = getTransSpan $ 1 endSpan }
422
422
in BlCase () span (Just $ 1 ) Nothing $ 4 caseRanges blocks endLabel }
423
- | id ' :' selectcase ' (' EXPRESSION ' )' NEWLINE CASES
424
- { let { (caseRanges, blocks, endLabel, endSpan) = $ 8 ;
423
+ | id ' :' selectcase ' (' EXPRESSION ' )' MAYBE_COMMENT NEWLINE CASES
424
+ { let { (caseRanges, blocks, endLabel, endSpan) = $ 9 ;
425
425
TId s startName = $ 1 ;
426
426
span = getTransSpan s endSpan }
427
427
in BlCase () span Nothing (Just startName) $ 5 caseRanges blocks endLabel }
428
- | INTEGER_LITERAL id ' :' selectcase ' (' EXPRESSION ' )' NEWLINE CASES
429
- { let { (caseRanges, blocks, endLabel, endSpan) = $ 9 ;
428
+ | INTEGER_LITERAL id ' :' selectcase ' (' EXPRESSION ' )' MAYBE_COMMENT NEWLINE CASES
429
+ { let { (caseRanges, blocks, endLabel, endSpan) = $ 10 ;
430
430
TId s startName = $ 2 ;
431
431
span = getTransSpan s endSpan }
432
432
in BlCase () span (Just $ 1 ) (Just startName) $ 6 caseRanges blocks endLabel }
433
433
434
+ -- We store line comments as statements, but this raises an issue: we have
435
+ -- nowhere to place comments after a SELECT CASE but before a CASE. So we drop
436
+ -- them. The inner CASES_ rule does /not/ use this, because comments can always
437
+ -- be parsed as belonging to to the above CASE block.
434
438
CASES :: { ([Maybe (AList Index A0 )], [[Block A0 ]], Maybe (Expression A0 ), SrcSpan ) }
435
- : maybe (INTEGER_LITERAL ) case ' (' INDICIES ' )' NEWLINE BLOCKS CASES
436
- { let (scrutinees, blocks, endLabel, endSpan) = $ 8
437
- in (Just (fromReverseList $ 4 ) : scrutinees, reverse $ 7 : blocks, endLabel, endSpan) }
438
- | maybe (INTEGER_LITERAL ) case default NEWLINE BLOCKS END_SELECT
439
- { let (endLabel, endSpan) = $ 6
440
- in ([Nothing ], [$ 5 ], endLabel, endSpan) }
439
+ : COMMENT_BLOCK CASES_ { $ 2 }
440
+ | CASES_ { $ 1 }
441
+
442
+ CASES_ :: { ([Maybe (AList Index A0 )], [[Block A0 ]], Maybe (Expression A0 ), SrcSpan ) }
443
+ : maybe (INTEGER_LITERAL ) case ' (' INDICIES ' )' MAYBE_COMMENT NEWLINE BLOCKS CASES_
444
+ { let (scrutinees, blocks, endLabel, endSpan) = $ 9
445
+ in (Just (fromReverseList $ 4 ) : scrutinees, reverse $ 8 : blocks, endLabel, endSpan) }
446
+ | maybe (INTEGER_LITERAL ) case default MAYBE_COMMENT NEWLINE BLOCKS END_SELECT
447
+ { let (endLabel, endSpan) = $ 7
448
+ in ([Nothing ], [$ 6 ], endLabel, endSpan) }
441
449
| END_SELECT
442
450
{ let (endLabel, endSpan) = $ 1
443
451
in ([] , [] , endLabel, endSpan) }
0 commit comments