Registry / devops / tree-sitter-fortran

tree-sitter-fortran

JSON →
library0.6.0pypypi✓ verified 85d ago

Fortran grammar for tree-sitter, providing a parser and syntax tree generation for Fortran code (versions 0.6.0). Released as a Python package; also available as an npm package for language bindings. Maintained community grammar with occasional releases.

pip install tree-sitter-fortran
INSTALL
IMPORT
SIG · TREE-SITTER-FORTRA
T
tree-sitter-fortran
devopspythonv0.6.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

language
from tree_sitter_fortran import language
from tree_sitter import Language
Do not import Language from tree-sitter; use the language function from the grammar package. Also ensure tree_sitter is installed first.
Parser
from tree_sitter import Parser
from tree_sitter_fortran import Parser
Parser is from the core tree-sitter package, not from the grammar package.

Parse a simple Fortran program and print the syntax tree.

from tree_sitter import Parser from tree_sitter_fortran import language FORTURN_LANG = language() parser = Parser() parser.set_language(FORTURN_LANG) tree = parser.parse(b"""program hello print *, 'Hello, World!' end program hello""") print(tree.root_node.sexp())
Debug
Known issues
gotchaThe language object is created by calling `language()` (a function), not by importing a constant. This is different from some other tree-sitter grammars that expose a `LANGUAGE` constant.
fix
Use `from tree_sitter_fortran import language` and then `lang = language()`.
affects: all
deprecatedTree-sitter Python package changed import paths for grammars around v0.20. Older code may use `Language('build/my-languages.so', 'fortran')` which is deprecated.
fix
Use the grammar-specific package (`tree-sitter-fortran`) and import `language` directly.
affects: 0.6.0 (library)
gotchaThe grammar package (0.6.0) requires Python >=3.9 and tree-sitter >=0.20. Installing on older Python or tree-sitter versions will fail.
fix
Ensure your environment uses Python 3.9+ and run `pip install 'tree-sitter>=0.20'` before or alongside the grammar.
affects: 0.6.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'tree_sitter_fortran'
The grammar package is not installed or installed in the wrong environment.
fix
Run `pip install tree-sitter-fortran` in the correct Python environment.
ImportError: cannot import name 'LANGUAGE' from 'tree_sitter_fortran'
The grammar used to have a LANGUAGE constant (or user expected one) but now exposes a `language()` function.
fix
Replace `from tree_sitter_fortran import LANGUAGE` with `from tree_sitter_fortran import language` and call `language()`.
TypeError: Parser.set_language() argument must be a Language object, not function
Forgot to call the `language()` function, passing the function itself instead.
fix
Use `parser.set_language(language())` (with parentheses).
Upgrade
Version history
0.6.0latest on PyPI · released Apr 24, 2026
Audit
Dependencies
tree-sitterrequiredCore Tree-sitter Python bindings required for all versions
Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
tree-sitter-fortran — pip install tree-sitter-fortran · libregistry