stadelmanma / tree-sitter-fortran

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

Fortran 2008 Features #63

Closed e-kwsm closed 1 year ago

e-kwsm commented 1 year ago

The followings do not seem to be supported:

vickysharma0812 commented 1 year ago

Also, following are missing we should add:

stadelmanma commented 1 year ago

I don’t have a planned ETA on when I will get to this since I’m pretty backlogged but if you could attach files showing these in use that would be a great start. If you want to take a crack at implementing it I’ll be happy to try and squeeze some time in for code review. Thanks!

vickysharma0812 commented 1 year ago

@stadelmanma thank you for replying!

Last night, I read about tree-sitter, and tried to make changes.

At first, I want to treat submodules just like modules (this is simplest approach for getting the syntax highlighing correctly)

What are modules and submodules

For example:

Module: Vector_Class.F90


MODULE Vector_Class
USE stmt
implicit none
private stmt
public stmt

!! header only

interface
module subroutine foo1( arg1, arg2)
real :: arg1
integer :: arg2
end subroutine foo1
end interface

public :: foo1

!! similarly goes the function

interface
module function foo2(arg1, arg3) results(ans)
integer :: arg1
real :: arg2
end function foo2 
end interface

public ::  foo2

END MODULE Vector_Class

As you can see, we have just declared the interface of methods.

We will provide interface in submodules. A module can have many submodules, I think this is called child.

But each submodule can have only a unique parent module.

Let us define two submodules, each implementing a method in module.

File: Vector_Class@foo1Methods.F90

submodule(Vector_Class) foo1Methods
contains

module procedure foo1
!! implementation
end module procedure foo1
end submodule foo1Methods

File: Vector_Class@foo2Methods.F90

submodule(Vector_Class) foo2Methods
contains

module procedure foo2
!! implementation
end module procedure foo2

end submodule foo2Methods

As you can see, foo1 and foo2 contains only the implementation.

So a submodule structure is as follows:

submodule(module_name) submodule_name
use stmt
implicit none
contains

implementation plus new routines

... 

end submodule submodule_name

Regards Vikas

vickysharma0812 commented 1 year ago

@stadelmanma I have created a PR, please check if possible.

If you can guide me, then I would like to implement this feature and learn tree-sitter.

regards Vikas

e-kwsm commented 1 year ago

if you could attach files showing these in use that would be a great start

PROGRAM BLOCK_EXAMPLE
  IMPLICIT NONE

  BLOCK
    INTEGER :: I
  END BLOCK

  label: BLOCK
    INTEGER :: J
    EXIT label
    PRINT *, "unreachable"
  END BLOCK label
  ! block-construct-name, i.e. "label", must be appended
END PROGRAM
PROGRAM DO_CONCURRENT_EXAMPLE
  IMPLICIT NONE
  INTEGER :: a(3, 4)
  INTEGER :: i, j

  DO CONCURRENT (j=1:4)
    a(:, j) = j
  END DO

  label: DO CONCURRENT (i=1:3, j=1:4)
    a(i, j) = i + j * 10
  END DO label
  ! do-construct-name, i.e. "label", must be appended
END PROGRAM
PROGRAM ERROR_STOP_EXAMPLE
  ERROR STOP
  ERROR STOP 1
  ERROR STOP 2, QUIET=.TRUE.
  ERROR STOP "message"
  ERROR STOP "message", QUIET=.TRUE.
END PROGRAM
INTEGER IMPURE FUNCTION f1()
END FUNCTION

IMPURE FUNCTION f2() RESULT(r)
  REAL :: r
END FUNCTION

IMPURE SUBROUTINE g()
END SUBROUTINE
e-kwsm commented 1 year ago

Also, the following attribute is missed:

stadelmanma commented 1 year ago

@vickysharma0812 merged in your changes, @e-kwsm added support for the two missing keywords. Some of the new statements I will need to visit later when I have some more time. Apologies for the delay, I didn't intend for it to take me this long to review the PR.

vickysharma0812 commented 1 year ago

@stadelmanma Thanks a lot, I will check it. I really appreciate you for this creation and update.

ZedThree commented 1 year ago

Support for block added in #76

I think just do concurrent missing from this issue?