Skip to content

Commit 7da5f9c

Browse files
committed
add associate block parsing to Fortran2003
1 parent 689150e commit 7da5f9c

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

src/Language/Fortran/Parser/Fortran2003.y

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ import Debug.Trace
158158
case { TCase _ }
159159
selectcase { TSelectCase _ }
160160
endselect { TEndSelect _ }
161+
associate { TAssociate _ }
162+
endassociate { TEndAssociate _ }
161163
default { TDefault _ }
162164
cycle { TCycle _ }
163165
exit { TExit _ }
@@ -358,6 +360,7 @@ BLOCKS :: { [ Block A0 ] } : BLOCKS BLOCK { $2 : $1 } | {- EMPTY -} { [ ] }
358360
BLOCK :: { Block A0 }
359361
: IF_BLOCK MAYBE_COMMENT NEWLINE { $1 }
360362
| CASE_BLOCK MAYBE_COMMENT NEWLINE { $1 }
363+
| ASSOCIATE_BLOCK MAYBE_COMMENT NEWLINE { $1 }
361364
| INTEGER_LITERAL STATEMENT MAYBE_COMMENT NEWLINE
362365
{ BlStatement () (getTransSpan $1 $2) (Just $1) $2 }
363366
| STATEMENT MAYBE_COMMENT NEWLINE { BlStatement () (getSpan $1) Nothing $1 }
@@ -454,6 +457,60 @@ END_SELECT :: { (Maybe (Expression A0), SrcSpan) }
454457
: maybe(INTEGER_LITERAL) endselect maybe(id)
455458
{ ($1, maybe (getSpan $2) getSpan $3) }
456459

460+
ASSOCIATE_BLOCK :: { Block A0 }
461+
: INTEGER_LITERAL id ':' associate '(' ABBREVIATIONS ')' MAYBE_COMMENT NEWLINE BLOCKS END_ASSOCIATE
462+
{ let { startSpan = getSpan $1;
463+
mLabel = Just $1;
464+
TId _ name = $2;
465+
mName = Just name;
466+
abbrevs = fromReverseList $6;
467+
body = reverse $10;
468+
(endSpan, mEndLabel) = $11;
469+
span = getTransSpan startSpan endSpan }
470+
in BlAssociate () span mLabel mName abbrevs body mEndLabel }
471+
| INTEGER_LITERAL associate '(' ABBREVIATIONS ')' MAYBE_COMMENT NEWLINE BLOCKS END_ASSOCIATE
472+
{ let { startSpan = getSpan $1;
473+
mLabel = Just $1;
474+
mName = Nothing;
475+
abbrevs = fromReverseList $4;
476+
body = reverse $8;
477+
(endSpan, mEndLabel) = $9;
478+
span = getTransSpan startSpan endSpan }
479+
in BlAssociate () span mLabel mName abbrevs body mEndLabel }
480+
| id ':' associate '(' ABBREVIATIONS ')' MAYBE_COMMENT NEWLINE BLOCKS END_ASSOCIATE
481+
{ let { startSpan = getSpan $1;
482+
TId _ name = $1;
483+
mLabel = Nothing;
484+
mName = Just name;
485+
abbrevs = fromReverseList $5;
486+
body = reverse $9;
487+
(endSpan, mEndLabel) = $10;
488+
span = getTransSpan startSpan endSpan }
489+
in BlAssociate () span mLabel mName abbrevs body mEndLabel }
490+
| associate '(' ABBREVIATIONS ')' MAYBE_COMMENT NEWLINE BLOCKS END_ASSOCIATE
491+
{ let { startSpan = getSpan $1;
492+
mLabel = Nothing;
493+
mName = Nothing;
494+
abbrevs = fromReverseList $3;
495+
body = reverse $7;
496+
(endSpan, mEndLabel) = $8;
497+
span = getTransSpan startSpan endSpan }
498+
in BlAssociate () span mLabel mName abbrevs body mEndLabel }
499+
500+
-- TODO: Copied verbatim from END_IF. Should attempt to functionalise.
501+
END_ASSOCIATE :: { (SrcSpan, Maybe (Expression A0)) }
502+
: endassociate { (getSpan $1, Nothing) }
503+
| endassociate id { (getSpan $2, Nothing) }
504+
| INTEGER_LITERAL endassociate { (getSpan $2, Just $1) }
505+
| INTEGER_LITERAL endassociate id { (getSpan $3, Just $1) }
506+
507+
-- (var (ExpValue (ValVariable)), assoc. expr)
508+
ABBREVIATIONS :: { [(ATuple Expression Expression A0)] }
509+
: ABBREVIATIONS ',' ABBREVIATION { $3 : $1 }
510+
| ABBREVIATION { [ $1 ] }
511+
ABBREVIATION :: { ATuple Expression Expression A0 }
512+
: VARIABLE '=>' EXPRESSION { ATuple () (getTransSpan $1 $3) $1 $3 }
513+
457514
ABSTRACTP :: { Bool }
458515
: abstract { True }
459516
| {- EMPTY -} { False }

0 commit comments

Comments
 (0)