Skip to content

Commit 401fd71

Browse files
committed
fix special CASE block comment parse fail (F90)
Comments after SELECT CASE but before a CASE weren't being handled (parse fail), and have nowhere to go in the AST. The CASE block transformation removed these comments: we do the same.
1 parent b05075a commit 401fd71

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/Language/Fortran/Parser/Fortran90.y

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,16 +360,15 @@ END_IF
360360
| INTEGER_LITERAL endif id { (getSpan $3, Just $1) }
361361

362362
CASE_BLOCK :: { Block A0 }
363-
CASE_BLOCK
364-
: selectcase '(' EXPRESSION ')' MAYBE_COMMENT NEWLINE CASES
363+
: selectcase '(' EXPRESSION ')' MAYBE_COMMENT NEWLINE CASES
365364
{ let { (caseRanges, blocks, endLabel, endSpan) = $7;
366365
span = getTransSpan $1 endSpan }
367366
in BlCase () span Nothing Nothing $3 caseRanges blocks endLabel }
368-
| INTEGER_LITERAL selectcase '(' EXPRESSION ')' MAYBE_COMMENT NEWLINE CASES
367+
| INTEGER_LITERAL selectcase '(' EXPRESSION ')' MAYBE_COMMENT NEWLINE CASES
369368
{ let { (caseRanges, blocks, endLabel, endSpan) = $8;
370369
span = getTransSpan $1 endSpan }
371370
in BlCase () span (Just $1) Nothing $4 caseRanges blocks endLabel }
372-
| id ':' selectcase '(' EXPRESSION ')' MAYBE_COMMENT NEWLINE CASES
371+
| id ':' selectcase '(' EXPRESSION ')' MAYBE_COMMENT NEWLINE CASES
373372
{ let { (caseRanges, blocks, endLabel, endSpan) = $9;
374373
TId s startName = $1;
375374
span = getTransSpan s endSpan }
@@ -380,8 +379,16 @@ CASE_BLOCK
380379
span = getTransSpan s endSpan }
381380
in BlCase () span (Just $1) (Just startName) $6 caseRanges blocks endLabel }
382381

382+
-- We store line comments as statements, but this raises an issue: we have
383+
-- nowhere to place comments after a SELECT CASE but before a CASE. So we drop
384+
-- them. The inner CASES_ rule does /not/ use this, because comments can always
385+
-- be parsed as belonging to to the above CASE block.
383386
CASES :: { ([Maybe (AList Index A0)], [[Block A0]], Maybe (Expression A0), SrcSpan) }
384-
: maybe(INTEGER_LITERAL) case '(' INDICIES ')' MAYBE_COMMENT NEWLINE BLOCKS CASES
387+
: COMMENT_BLOCK CASES_ { $2 }
388+
| CASES_ { $1 }
389+
390+
CASES_ :: { ([Maybe (AList Index A0)], [[Block A0]], Maybe (Expression A0), SrcSpan) }
391+
: maybe(INTEGER_LITERAL) case '(' INDICIES ')' MAYBE_COMMENT NEWLINE BLOCKS CASES_
385392
{ let (scrutinees, blocks, endLabel, endSpan) = $9
386393
in (Just (fromReverseList $4) : scrutinees, reverse $8 : blocks, endLabel, endSpan) }
387394
| maybe(INTEGER_LITERAL) case default MAYBE_COMMENT NEWLINE BLOCKS END_SELECT

0 commit comments

Comments
 (0)