A tree-sitter grammar for the FreeMarker Template Language (FTL).
- Core FTL directives:
assign,if/elseif/else,list/as/items/sep,ftl,function,macro,switch/on/case/default,import,local,return,break,continue - Full expression grammar: arithmetic, comparison, equality, logical/bitwise,
in,??, unary!/-/+, member/subscript access, function calls, and the?builtinfamily - Interpolations (
${...}), strings (single/double with escapes), numbers, arrays, and objects - Both the default
<#...>and the square-bracket[#...]tag syntaxes, mutually exclusive per file (the mode defaults to angle brackets and is declared by the first<#ftl>/[#ftl]directive; wrong-syntax tags are treated as static text -
<#-- ... -->and[#-- ... --]comments
[dependencies]
tree-sitter = "0.26"
tree-sitter-freemarker = "0.1"use tree_sitter::Parser;
use tree_sitter_freemarker::LANGUAGE;
let mut parser = Parser::new();
parser
.set_language(&LANGUAGE.into())
.expect("Error loading FreeMarker parser");
let source = "<#if user.age >= 18>Adult<#else>Minor</#if>";
let tree = parser.parse(source, None).unwrap();
assert!(!tree.root_node().has_error());tree-sitter parse example.ftl # pretty-print a parse tree
tree-sitter test # run the corpus testsPrerequisites are pinned in docs/toolchain.md
(tree-sitter-cli, Node, Rust).
npm install # installs tree-sitter-cli
tree-sitter generate --abi=15 # regenerate src/parser.c from grammar.js
cargo test # Rust bindings + scanner tests
npm test # corpus tests (tree-sitter test)
npm run format:check # clang-format check on the scannerMIT — see LICENSE.
