Skip to content

AlexanderBrevig/tree-sitter-forth

Repository files navigation

tree-sitter-forth

build

Forth grammar for tree-sitter - a fast, incremental parser for syntax highlighting and code analysis.

Features

  • Complete number support: Decimal, hex (0xFF, $FF), binary (%1010), octal (&77), character literals ('c'), floats (3.14, 1.5e-10), and double-cell numbers (123.)
  • Semantic categorization: Control flow, operators, I/O, and core words are distinct AST nodes for better syntax highlighting
  • Case-insensitive: All Forth keywords are case-insensitive as per standard
  • Comment types: Line comments (\), block comments, and stack effect comments (( n -- result )) parsed separately
  • String types: s", S", c", C", and ." with proper tokenization
  • Bindings: Node.js and Rust support

Installation

npm install tree-sitter-forth

Usage

# Generate parser
npm run build

# Run tests
npm test

# Parse a file
npm run parse -- file.fs

Grammar Structure

The grammar categorizes Forth words into semantic groups:

  • Control Flow: IF/THEN/ELSE, BEGIN/UNTIL, DO/LOOP, CASE/OF, etc.
  • Operators: Stack manipulation (DUP, SWAP, ROT), arithmetic (+, -, MOD), logic (AND, OR)
  • I/O: Input/output words (., EMIT, KEY, ACCEPT)
  • Core: Defining words, memory operations, compilation words

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •