stadelmanma / tree-sitter-fortran

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

Parameterised types #75

Open ZedThree opened 1 year ago

ZedThree commented 1 year ago

Currently, parameterised intrinsic types such as:

real(kind=real64) :: var
character(len=:) :: char

are parsed like:

    (variable_declaration
      (intrinsic_type) 
      (size (argument_list (keyword_argument (identifier) (identifier))))
      (identifier))

    (variable_declaration
      (intrinsic_type)
      (size (argument_list (keyword_argument (identifier) (assumed_shape))))
      (identifier))

It might be more useful to instead parse them to (strawperson proposal):

    (variable_declaration
      (intrinsic_type
        (type_parameter
          kind: (type_kind (identifier))))
      (identifier))

    (variable_declaration
      (intrinsic_type
        (type_parameter
          len: (type_len (assumed_shape))))
      (identifier))

Intrinsic types can certainly only have kind and len, although annoyingly the numeric types have kind as the default and character has len. I don't have my reference book in front of me today, but I believe that derived types can also only have kind and len parameters.