stadelmanma / tree-sitter-fortran

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

In fortran fixed format files, comments beginning with other characters than ! (e.g, c, C etc) are not treated as comments #61

Open sahashirshendu opened 2 years ago

gzagatti commented 2 years ago

I am having a similar problem. As I am working with LAPACK code, line comments start with *.

It seems like FORTRAN 77 comments are line that start with letter c or an *.

stadelmanma commented 2 years ago

Fixed form format isn't perfectly supported. I think some code would need added to the scanner.cc file to detect non-standard comment characters.

ZedThree commented 1 year ago

I suspect that fixed form will be fundamentally incompatible with free form in the same parser. Any character in column 1 indicates a comment in fixed form, and I don't think there's any way of passing options into the parser. In the C++ parser, for instance, they've squashed all the different standards into one.

One option is to use something like fixed2free.py to convert the source to free form, and then use tree-sitter.

stadelmanma commented 1 year ago

I wonder if we could do Fixed Form Fortran by importing this language into it and customizing the scanner part to deal with columns 1-7? I don’t really know how tree sitter “imports” other languages but you mentioned the CPP parser doing that. I suspect it would be more liberal than an actual fixed form complier but it also wouldn’t require massive code duplication.

ZedThree commented 1 year ago

I think that would be the most economical way of doing things. Here's the important bits from the C++ parser:

const C = require("tree-sitter-c/grammar")

module.exports = grammar(C, {
  // C++ specific rules
  ...

They then have tree-sitter-c in devDependencies in package.json, so I guess that would require having tree-sitter-fortran on npm?

stadelmanma commented 1 year ago

I’d wager we could reference a git repo in the package.json but pushing this to NPM eventually makes sense. Seems the mainline tree-sitter languages all have 0.X tags versus committing to a “stable” 1.X release.

stadelmanma commented 1 year ago

Added a repo to catch this work eventually, https://github.com/stadelmanma/tree-sitter-fixed-form-fortran.