Skip to content

Commit ab9aa00

Browse files
authored
Merge pull request stadelmanma#148 from stadelmanma/supertypes
Add supertypes
2 parents b7ed36e + 3ef6401 commit ab9aa00

File tree

8 files changed

+638596
-663771
lines changed

8 files changed

+638596
-663771
lines changed

grammar.js

Lines changed: 76 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ module.exports = grammar({
100100
[$.format_statement, $.identifier],
101101
[$._inline_if_statement, $.arithmetic_if_statement, $._block_if_statement, $.identifier],
102102
[$.file_position_statement, $.identifier],
103+
[$.cray_pointer_declaration, $.identifier],
104+
],
105+
106+
supertypes: $ => [
107+
$._specification_parts,
108+
$._expression,
109+
$._statements,
110+
$._argument_item,
103111
],
104112

105113
rules: {
@@ -403,7 +411,7 @@ module.exports = grammar({
403411
},
404412

405413
assignment: $ => seq(caseInsensitive('assignment'), '(', '=', ')'),
406-
operator: $ => seq(caseInsensitive('operator'), '(', /[^()]+/, ')'),
414+
operator: $ => seq(caseInsensitive('operator'), '(', alias(/[^()]+/, $.operator_name), ')'),
407415
defined_io_procedure: $ => seq(
408416
choice(caseInsensitive('read'), caseInsensitive('write')),
409417
'(',
@@ -527,25 +535,14 @@ module.exports = grammar({
527535
// Variable Declarations
528536

529537
_specification_part: $ => prec(1, choice(
530-
$.include_statement,
531-
seq($.use_statement, $._end_of_statement),
532-
seq($.implicit_statement, $._end_of_statement),
533-
seq($.save_statement, $._end_of_statement),
534-
seq($.import_statement, $._end_of_statement),
535-
$.public_statement,
536-
$.private_statement,
537-
$.enum,
538-
$.enumeration_type,
538+
// Split out so it can be used as a supertype
539+
seq($._specification_parts, $._end_of_statement),
540+
// These two can't be included in the above because or we
541+
// duplicate the end_of_statement in the end block rule
539542
$.interface,
540543
$.derived_type_definition,
541-
seq($.namelist_statement, $._end_of_statement),
542-
seq($.common_statement, $._end_of_statement),
543-
seq($.variable_declaration, $._end_of_statement),
544-
seq($.variable_modification, $._end_of_statement),
545-
seq($.parameter_statement, $._end_of_statement),
546-
seq($.equivalence_statement, $._end_of_statement),
547-
seq($.data_statement, $._end_of_statement),
548-
seq($.assignment_statement, $._end_of_statement),
544+
// This allows format statements in the specification part,
545+
// without making the statements rule particularly awkward
549546
prec(1, seq($.statement_label, $.format_statement, $._end_of_statement)),
550547
$.preproc_include,
551548
$.preproc_def,
@@ -556,6 +553,28 @@ module.exports = grammar({
556553
';',
557554
)),
558555

556+
_specification_parts: $ => prec(1, choice(
557+
$.include_statement,
558+
$.use_statement,
559+
$.implicit_statement,
560+
$.save_statement,
561+
$.import_statement,
562+
$.public_statement,
563+
$.private_statement,
564+
$.enum,
565+
$.enumeration_type,
566+
$.namelist_statement,
567+
$.common_statement,
568+
$.variable_declaration,
569+
$.variable_modification,
570+
$.parameter_statement,
571+
$.equivalence_statement,
572+
$.data_statement,
573+
$.cray_pointer_declaration,
574+
// This catches statement functions, which are completely ambiguous
575+
$.assignment_statement,
576+
)),
577+
559578
use_statement: $ => seq(
560579
caseInsensitive('use'),
561580
choice(
@@ -570,7 +589,7 @@ module.exports = grammar({
570589
seq(',', commaSep1($.use_alias)),
571590
$.included_items
572591
)
573-
)
592+
),
574593
),
575594

576595
included_items: $ => seq(
@@ -611,7 +630,7 @@ module.exports = grammar({
611630
')'
612631
))
613632
)
614-
)
633+
),
615634
),
616635

617636
save_statement: $ => prec(1, seq(
@@ -622,7 +641,7 @@ module.exports = grammar({
622641
$.identifier,
623642
seq('/', $.identifier, '/'),
624643
)),
625-
))
644+
)),
626645
)),
627646

628647
private_statement: $ => prec.right(1, seq(
@@ -631,7 +650,6 @@ module.exports = grammar({
631650
optional('::'),
632651
commaSep1(choice($.identifier, $._generic_procedure))
633652
)),
634-
$._end_of_statement,
635653
)),
636654

637655
public_statement: $ => prec.right(1, seq(
@@ -640,20 +658,19 @@ module.exports = grammar({
640658
optional('::'),
641659
commaSep1(choice($.identifier, $._generic_procedure))
642660
)),
643-
$._end_of_statement,
644661
)),
645662

646663
namelist_statement: $ => seq(
647664
caseInsensitive('namelist'),
648-
repeat1($.variable_group)
665+
repeat1($.variable_group),
649666
),
650667

651668
common_statement: $ => seq(
652669
caseInsensitive('common'),
653670
repeat1(choice(
654671
$.variable_group,
655672
commaSep1($._variable_declarator)
656-
))
673+
)),
657674
),
658675

659676
variable_group: $ => seq(
@@ -670,7 +687,7 @@ module.exports = grammar({
670687

671688
import_statement: $ => prec.left(seq(
672689
caseInsensitive('import'),
673-
optional($._import_names)
690+
optional($._import_names),
674691
)),
675692
_import_names: $ => choice(
676693
seq(optional('::'), commaSep1($.identifier)),
@@ -686,14 +703,16 @@ module.exports = grammar({
686703
derived_type_definition: $ => seq(
687704
$.derived_type_statement,
688705
repeat(choice(
689-
$.public_statement,
690-
$.private_statement,
691706
seq(
707+
choice(
708+
$.public_statement,
709+
$.private_statement,
692710
alias(caseInsensitive('sequence'), $.sequence_statement),
693-
$._end_of_statement
711+
$.include_statement,
712+
),
713+
$._end_of_statement
694714
),
695-
$.include_statement,
696-
seq($.variable_declaration, $._end_of_statement),
715+
$.variable_declaration,
697716
$.preproc_include,
698717
$.preproc_def,
699718
$.preproc_function_def,
@@ -734,7 +753,6 @@ module.exports = grammar({
734753
seq(',', commaSep1($._derived_type_qualifier), '::', $._type_name)
735754
),
736755
optional(alias($.argument_list, $.derived_type_parameter_list)),
737-
$._end_of_statement
738756
),
739757

740758
end_type_statement: $ => blockStructureEnding($, 'type'),
@@ -767,7 +785,6 @@ module.exports = grammar({
767785
$.method_name,
768786
$.binding,
769787
))),
770-
$._end_of_statement,
771788
),
772789
binding: $ => seq($.binding_name, '=>', $.method_name),
773790
binding_name: $ => choice(
@@ -817,7 +834,7 @@ module.exports = grammar({
817834
)
818835
)),
819836
optional('::'),
820-
$._declaration_targets
837+
$._declaration_targets,
821838
),
822839

823840
procedure_declaration: $ => seq(
@@ -1016,14 +1033,14 @@ module.exports = grammar({
10161033
caseInsensitive('parameter'),
10171034
'(',
10181035
commaSep1($.parameter_assignment),
1019-
')'
1036+
')',
10201037
)),
10211038

10221039
parameter_assignment: $ => seq($.identifier, '=', $._expression),
10231040

10241041
equivalence_statement: $ => seq(
10251042
caseInsensitive('equivalence'),
1026-
commaSep1($.equivalence_set)
1043+
commaSep1($.equivalence_set),
10271044
),
10281045

10291046
equivalence_set: $ => seq(
@@ -1034,6 +1051,18 @@ module.exports = grammar({
10341051
')'
10351052
),
10361053

1054+
cray_pointer_declaration: $ => seq(
1055+
caseInsensitive('pointer'),
1056+
commaSep1($.cray_pointer_pair),
1057+
),
1058+
cray_pointer_pair: $ => seq(
1059+
'(',
1060+
field('pointer', $.identifier),
1061+
',',
1062+
field('target', $._variable_declarator),
1063+
')',
1064+
),
1065+
10371066
// Statements
10381067

10391068
_statement: $ => choice(
@@ -1048,7 +1077,6 @@ module.exports = grammar({
10481077
$._statements,
10491078
$._end_of_statement
10501079
),
1051-
$.include_statement,
10521080
';'
10531081
),
10541082

@@ -1088,6 +1116,7 @@ module.exports = grammar({
10881116
$.coarray_critical_statement,
10891117
// Not strictly valid, but can catch extensions and preprocessor macros
10901118
$.call_expression,
1119+
$.include_statement,
10911120
),
10921121

10931122
statement_label: $ => prec(1, alias($._integer_literal, 'statement_label')),
@@ -1163,12 +1192,11 @@ module.exports = grammar({
11631192
include_statement: $ => prec(1, seq(
11641193
caseInsensitive('include'),
11651194
field("path", alias($.string_literal, $.filename)),
1166-
$._end_of_statement,
11671195
)),
11681196

11691197
data_statement: $ => seq(
11701198
caseInsensitive('data'),
1171-
sep1($.data_set, optional(','))
1199+
sep1($.data_set, optional(',')),
11721200
),
11731201
data_set: $ => prec(1, seq(
11741202
commaSep1(
@@ -1663,7 +1691,6 @@ module.exports = grammar({
16631691
$.enum_statement,
16641692
repeat($.enumerator_statement),
16651693
$.end_enum_statement,
1666-
$._end_of_statement
16671694
),
16681695

16691696
enum_statement: $ => seq(
@@ -1677,7 +1704,6 @@ module.exports = grammar({
16771704
$.enumeration_type_statement,
16781705
repeat($.enumerator_statement),
16791706
$.end_enumeration_type_statement,
1680-
$._end_of_statement
16811707
),
16821708

16831709
enumeration_type_statement: $ => seq(
@@ -1964,21 +1990,16 @@ module.exports = grammar({
19641990
// Unnamed node so we can reuse it for e.g. kind
19651991
_argument_list: $ => prec.dynamic(
19661992
1,
1967-
seq(
1968-
'(',
1969-
commaSep(choice(
1970-
$.keyword_argument,
1971-
$.extent_specifier,
1972-
$.assumed_size,
1973-
$.assumed_rank,
1974-
$._expression,
1975-
$.multiple_subscript,
1976-
$.multiple_subscript_triplet,
1977-
)),
1978-
')'
1979-
)
1993+
seq('(', commaSep(choice($._expression, $._argument_item)), ')')
1994+
),
1995+
_argument_item: $ => choice(
1996+
$.keyword_argument,
1997+
$.extent_specifier,
1998+
$.assumed_size,
1999+
$.assumed_rank,
2000+
$.multiple_subscript,
2001+
$.multiple_subscript_triplet,
19802002
),
1981-
19822003
argument_list: $ => $._argument_list,
19832004

19842005
// precedence is used to prevent conflict with assignment expression

0 commit comments

Comments
 (0)