Open sahashirshendu opened 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.
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.
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.
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?
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.
Added a repo to catch this work eventually, https://github.com/stadelmanma/tree-sitter-fixed-form-fortran.
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*
.