stadelmanma / tree-sitter-fortran

Fortran grammar for tree-sitter
MIT License
30 stars 15 forks source link

Better program rule? #57

Closed ghost closed 3 years ago

ghost commented 3 years ago

Does this looks like a slightly better implementation of the program rule? It follows the module rule. Program can also support internal procedures like modules for example which are now supported.

and I have a question, why do we need prec.right in the original implementation of the program_block?

-    program_block: $ => seq(
-      prec.right(seq(
-        caseInsensitive('program'),
-        $.identifier
-      )),
-      optional($.comment),
-      $._end_of_statement,
+    program: $ => seq(
+      $.program_statement,
       repeat($._specification_part),
       repeat($._statement),
+      optional($.internal_procedures),
       $.end_program_statement
     ),

+    program_statement: $ => seq(caseInsensitive('program'), $._name),
     end_program_statement: $ => blockStructureEnding($, 'program'),
stadelmanma commented 3 years ago

@oponkork I'm not sure why prec.right was needed before. I assume that sometimes the program name identifier was stolen sometimes or there used to be a conflict in a previous version of the grammar. If all the tests pass without the prec.right I'm fine with dropping it.

As for adding support for internal procedures to the program block if the language supports it please do, just add a test case to Program section of the test/corpus/constructs.txt file.