Skip to content

Alexl-git/tree-sitter-dfm

Repository files navigation

tree-sitter-dfm

npm license

Tree-sitter grammar for Delphi DFM/FMX form files (text format).

100.00% pass rate on 11,044 real text-DFM files across a 39K-file Delphi corpus (zero ERROR nodes).

What is DFM?

DFM (and its FireMonkey sibling FMX) is the text-serialization of VCL/FMX form trees emitted by the Delphi IDE. Every form, frame, and data module in a Delphi project has a .dfm / .fmx companion alongside the .pas source. The grammar handles the standard object/inherited/inline declaration tree with properties, values, nested collections, and hex binary blobs.

Install

npm install tree-sitter-dfm tree-sitter

Usage

const fs = require('fs');
const Parser = require('tree-sitter');
const DFM = require('tree-sitter-dfm');

const parser = new Parser();
parser.setLanguage(DFM);

const source = fs.readFileSync('MainForm.dfm', 'utf8');
const tree = parser.parse(source);
console.log(tree.rootNode.toString());

What's covered

  • object / inherited / inline headers (with optional class type and position index)
  • Nested children of arbitrary depth
  • Properties with qualified names (Font.Style.fsBold)
  • String values with #NN character codes and + concatenation across lines
  • Numeric values (integer, float, hex $00FF8800)
  • Datetime literals (Value = 0d)
  • Boolean values
  • Set and list collections
  • Items collections (Items = <>)
  • Hex blobs (Picture.Data = {0AFC...})
  • Identifier values (enum members, references)
  • Line comments //

What's not covered

  • Binary DFM (TPF0 record-stream format, ~706 files in the corpus). Different format — separate parser needed.
  • JCL templates with %FORMNAME% placeholders (~2 files). These aren't valid DFM until text-substitution runs.

These are excluded by the harness, not counted as failures.

Build from source

git clone https://github.com/Alexl-git/tree-sitter-dfm
cd tree-sitter-dfm
npm install --ignore-scripts
./node_modules/.bin/tree-sitter generate
node-gyp rebuild

Companion

A separate grammar pipeline for Delphi source code (.pas / .dpr / .dpk) lives at tree-sitter-delphi13.

npm install tree-sitter-delphi13

License

MIT.

About

tree sitter for Delphi DFM files

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors