Razen grammar for tree-sitter.
This grammar supports all Razen language features including:
- Keywords:
const,var,fun,struct,enum,impl,type,mod,use,pub - Control Flow:
if,else,elif,while,for,in,match,return,break,continue - Exception Handling:
try,catch,throw - Types:
int,float,str,bool,char,array,map,any - Operators: All arithmetic, comparison, logical, bitwise, and assignment operators
- Special Features:
- F-strings with interpolation:
f"Hello {name}" - Null coalescing:
?? - Power operator:
** - Range operators:
..,..=,... - Update operators:
++,--
- F-strings with interpolation:
- Comments: Single-line (
//) and multi-line (/* */)
npm install tree-sitter-razen[dependencies]
tree-sitter-razen = "0.1.0"const Parser = require('tree-sitter');
const Razen = require('tree-sitter-razen');
const parser = new Parser();
parser.setLanguage(Razen);
const sourceCode = `
fun main() {
const name = "World";
println(f"Hello, {name}!");
}
`;
const tree = parser.parse(sourceCode);
console.log(tree.rootNode.toString());use tree_sitter::Parser;
use tree_sitter_razen::LANGUAGE;
fn main() {
let mut parser = Parser::new();
parser.set_language(&LANGUAGE.into()).unwrap();
let source_code = r#"
fun main() {
const name = "World";
println(f"Hello, {name}!");
}
"#;
let tree = parser.parse(source_code, None).unwrap();
println!("{}", tree.root_node().to_sexp());
}- Node.js (v16+)
- tree-sitter-cli:
npm install -g tree-sitter-cli
# Generate the parser
tree-sitter generate
# Test the parser
tree-sitter test
# Try the playground
tree-sitter playground# Run tests
tree-sitter test
# Parse a file
tree-sitter parse examples/example.rzThis grammar includes comprehensive syntax highlighting queries:
- highlights.scm: Main syntax highlighting
- locals.scm: Local variable scoping
- injections.scm: Language injections (f-string interpolation)
- tags.scm: Symbol tagging for code navigation
- indents.scm: Indentation rules
.rz.razen
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License - see LICENSE file for details.