Skip to content

Commit 3ef6401

Browse files
committed
Small optimisation of supertypes
Moving the `_end_of_statement` out of each rule into `_specification_part` reduces the total number of states and makes it slightly faster to generate the grammar. Also means that the newline isn't included in the node itself
1 parent b4c3566 commit 3ef6401

File tree

4 files changed

+585473
-709088
lines changed

4 files changed

+585473
-709088
lines changed

grammar.js

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,11 @@ module.exports = grammar({
536536

537537
_specification_part: $ => prec(1, choice(
538538
// Split out so it can be used as a supertype
539-
$._specification_parts,
540-
// This catches statement functions, which are completely ambiguous
541-
seq($.assignment_statement, $._end_of_statement),
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
542+
$.interface,
543+
$.derived_type_definition,
542544
// This allows format statements in the specification part,
543545
// without making the statements rule particularly awkward
544546
prec(1, seq($.statement_label, $.format_statement, $._end_of_statement)),
@@ -561,8 +563,6 @@ module.exports = grammar({
561563
$.private_statement,
562564
$.enum,
563565
$.enumeration_type,
564-
$.interface,
565-
$.derived_type_definition,
566566
$.namelist_statement,
567567
$.common_statement,
568568
$.variable_declaration,
@@ -571,6 +571,8 @@ module.exports = grammar({
571571
$.equivalence_statement,
572572
$.data_statement,
573573
$.cray_pointer_declaration,
574+
// This catches statement functions, which are completely ambiguous
575+
$.assignment_statement,
574576
)),
575577

576578
use_statement: $ => seq(
@@ -588,7 +590,6 @@ module.exports = grammar({
588590
$.included_items
589591
)
590592
),
591-
$._end_of_statement,
592593
),
593594

594595
included_items: $ => seq(
@@ -630,7 +631,6 @@ module.exports = grammar({
630631
))
631632
)
632633
),
633-
$._end_of_statement
634634
),
635635

636636
save_statement: $ => prec(1, seq(
@@ -642,7 +642,6 @@ module.exports = grammar({
642642
seq('/', $.identifier, '/'),
643643
)),
644644
)),
645-
$._end_of_statement,
646645
)),
647646

648647
private_statement: $ => prec.right(1, seq(
@@ -651,7 +650,6 @@ module.exports = grammar({
651650
optional('::'),
652651
commaSep1(choice($.identifier, $._generic_procedure))
653652
)),
654-
$._end_of_statement,
655653
)),
656654

657655
public_statement: $ => prec.right(1, seq(
@@ -660,13 +658,11 @@ module.exports = grammar({
660658
optional('::'),
661659
commaSep1(choice($.identifier, $._generic_procedure))
662660
)),
663-
$._end_of_statement,
664661
)),
665662

666663
namelist_statement: $ => seq(
667664
caseInsensitive('namelist'),
668665
repeat1($.variable_group),
669-
$._end_of_statement
670666
),
671667

672668
common_statement: $ => seq(
@@ -675,7 +671,6 @@ module.exports = grammar({
675671
$.variable_group,
676672
commaSep1($._variable_declarator)
677673
)),
678-
$._end_of_statement
679674
),
680675

681676
variable_group: $ => seq(
@@ -693,7 +688,6 @@ module.exports = grammar({
693688
import_statement: $ => prec.left(seq(
694689
caseInsensitive('import'),
695690
optional($._import_names),
696-
$._end_of_statement
697691
)),
698692
_import_names: $ => choice(
699693
seq(optional('::'), commaSep1($.identifier)),
@@ -709,13 +703,15 @@ module.exports = grammar({
709703
derived_type_definition: $ => seq(
710704
$.derived_type_statement,
711705
repeat(choice(
712-
$.public_statement,
713-
$.private_statement,
714706
seq(
707+
choice(
708+
$.public_statement,
709+
$.private_statement,
715710
alias(caseInsensitive('sequence'), $.sequence_statement),
716-
$._end_of_statement
711+
$.include_statement,
712+
),
713+
$._end_of_statement
717714
),
718-
$.include_statement,
719715
$.variable_declaration,
720716
$.preproc_include,
721717
$.preproc_def,
@@ -757,7 +753,6 @@ module.exports = grammar({
757753
seq(',', commaSep1($._derived_type_qualifier), '::', $._type_name)
758754
),
759755
optional(alias($.argument_list, $.derived_type_parameter_list)),
760-
$._end_of_statement
761756
),
762757

763758
end_type_statement: $ => blockStructureEnding($, 'type'),
@@ -790,7 +785,6 @@ module.exports = grammar({
790785
$.method_name,
791786
$.binding,
792787
))),
793-
$._end_of_statement,
794788
),
795789
binding: $ => seq($.binding_name, '=>', $.method_name),
796790
binding_name: $ => choice(
@@ -841,7 +835,6 @@ module.exports = grammar({
841835
)),
842836
optional('::'),
843837
$._declaration_targets,
844-
$._end_of_statement
845838
),
846839

847840
procedure_declaration: $ => seq(
@@ -860,7 +853,6 @@ module.exports = grammar({
860853
)),
861854
optional('::'),
862855
commaSep1(field('declarator', $._variable_declarator)),
863-
$._end_of_statement,
864856
),
865857

866858
variable_attributes: $ => seq(
@@ -1042,15 +1034,13 @@ module.exports = grammar({
10421034
'(',
10431035
commaSep1($.parameter_assignment),
10441036
')',
1045-
$._end_of_statement
10461037
)),
10471038

10481039
parameter_assignment: $ => seq($.identifier, '=', $._expression),
10491040

10501041
equivalence_statement: $ => seq(
10511042
caseInsensitive('equivalence'),
10521043
commaSep1($.equivalence_set),
1053-
$._end_of_statement,
10541044
),
10551045

10561046
equivalence_set: $ => seq(
@@ -1064,7 +1054,6 @@ module.exports = grammar({
10641054
cray_pointer_declaration: $ => seq(
10651055
caseInsensitive('pointer'),
10661056
commaSep1($.cray_pointer_pair),
1067-
$._end_of_statement
10681057
),
10691058
cray_pointer_pair: $ => seq(
10701059
'(',
@@ -1088,7 +1077,6 @@ module.exports = grammar({
10881077
$._statements,
10891078
$._end_of_statement
10901079
),
1091-
$.include_statement,
10921080
';'
10931081
),
10941082

@@ -1128,6 +1116,7 @@ module.exports = grammar({
11281116
$.coarray_critical_statement,
11291117
// Not strictly valid, but can catch extensions and preprocessor macros
11301118
$.call_expression,
1119+
$.include_statement,
11311120
),
11321121

11331122
statement_label: $ => prec(1, alias($._integer_literal, 'statement_label')),
@@ -1203,13 +1192,11 @@ module.exports = grammar({
12031192
include_statement: $ => prec(1, seq(
12041193
caseInsensitive('include'),
12051194
field("path", alias($.string_literal, $.filename)),
1206-
$._end_of_statement,
12071195
)),
12081196

12091197
data_statement: $ => seq(
12101198
caseInsensitive('data'),
12111199
sep1($.data_set, optional(',')),
1212-
$._end_of_statement,
12131200
),
12141201
data_set: $ => prec(1, seq(
12151202
commaSep1(
@@ -1704,7 +1691,6 @@ module.exports = grammar({
17041691
$.enum_statement,
17051692
repeat($.enumerator_statement),
17061693
$.end_enum_statement,
1707-
$._end_of_statement
17081694
),
17091695

17101696
enum_statement: $ => seq(
@@ -1718,7 +1704,6 @@ module.exports = grammar({
17181704
$.enumeration_type_statement,
17191705
repeat($.enumerator_statement),
17201706
$.end_enumeration_type_statement,
1721-
$._end_of_statement
17221707
),
17231708

17241709
enumeration_type_statement: $ => seq(

0 commit comments

Comments
 (0)