npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

delphi13-preprocessor

v1.1.0

Published

Standalone Delphi 13 preprocessor — resolves {$IFDEF}/{$IF}/{$ELSE}/{$ENDIF} chains, {$DEFINE}/{$UNDEF}, {$I X.inc} includes, and numeric directives. Produces preprocessor-resolved text suitable for tree-sitter-delphi13-pure or any other consumer that pre

Readme

delphi13-preprocessor

npm license

Standalone Delphi 13 preprocessor — resolves {$IFDEF} / {$IF} / {$ELSE} / {$ENDIF} chains, {$DEFINE} / {$UNDEF}, {$I X.inc} includes, and numeric directives. Produces preprocessor-resolved text suitable for tree-sitter-delphi13-pure or any other consumer that prefers flat source.

Pairs with the pure tree-sitter sub-grammar to reach 99.33% parse rate on real-world Delphi 13 corpora.

Install

npm install delphi13-preprocessor

Library usage

const fs = require('fs');
const { preprocess } = require('delphi13-preprocessor');

const raw = fs.readFileSync('MyUnit.pas', 'utf8');

const { text, defines } = preprocess(raw, {
  defines: ['MSWINDOWS', 'WIN64', 'CPU64BITS', 'UNICODE',
            'COMPILER_VERSION_37', 'VER370',
            'SUPPORTS_GENERICS', 'SUPPORTS_INLINE',
            'ASSEMBLER'],
  numericDefines: {
    CompilerVersion: 37,
    RTLVersion: 37,
  },
  baseDir: 'C:/MyProject',     // for {$I X.inc} resolution (same-dir only)
  includeMode: 'expand',       // 'expand' (default) | 'defines-only' | 'off'
});

// Returns `{ text, defines }`:
//   text    — the active-branch source with inactive branches (and directives)
//             replaced by whitespace, preserving line AND byte offsets so
//             tree-sitter positions map 1:1 back to the ORIGINAL file.
//   defines — the final define set (Array) after all {$DEFINE}/{$UNDEF}.

// `includeMode` controls {$I X.inc} handling:
//   'expand'       — splice the resolved .inc body into the output (default).
//                    Shifts offsets after the include point.
//   'defines-only' — apply the .inc's {$DEFINE}/{$UNDEF} to the parent (so a
//                    later {$IFDEF X} in the parent resolves correctly) but do
//                    NOT splice the body. Keeps output 1:1 with input, and does
//                    not duplicate .inc symbols for consumers that index .inc
//                    files separately.
//   'off'          — blank the {$I} directive, ignore its defines. 1:1 offsets.

CLI

node node_modules/delphi13-preprocessor/cli.js path/to/file.pas [--defines defines.json]

Emits preprocessed pure-Pascal text to stdout.

Supported directives

  • Conditional: {$IFDEF} / {$IFNDEF} / {$IF expr} / {$ELSEIF expr} / {$ELSE} / {$ENDIF} / {$IFEND}
  • Define management: {$DEFINE Name}, {$UNDEF Name}
  • Includes: {$I X.inc} and {$INCLUDE X.inc} (same-directory resolution)
  • Expression evaluation in {$IF}:
    • defined(X), not defined(X)
    • Boolean and / or / not
    • Numeric comparison: CompilerVersion >= 21.0, RTLVersion < 31
    • Parenthesized sub-expressions

What it does NOT do

  • {$IF declared(SymName)} always returns false. Implementing this would require a lightweight symbol pre-scan (TYPE/CONST/VAR/FUNCTION declarations in the same unit). On the TODO list.
  • Cross-directory {$I} search paths. Currently the include file must live in the same directory as the file being preprocessed. Search-path support is on the TODO list.
  • {$INLINE} / {$EXTERNALSYM} / {$WARN} and other purely-compiler directives — these are passed through as-is (consumers see them in extras).

Per-project defines profiles

For real-world parsing, you often need project-specific defines to pick the right IFDEF branches. The orchestrator in the parent repo uses path-based regex profiles for EurekaLog, AsyncPro, FireDAC, fibplus, and Indy. Example:

const PATH_DEFINES = [
  { re: /EurekaLog/i, defs: ['EUREKALOG', 'USE_NAMESPACES', 'COMPILER37', /* ... */] },
  { re: /AsyncPro/i, defs: ['PRNDRV', 'APAX', 'Ver130', 'Ver140', 'Ver150'] },
  { re: /FireDAC/i, defs: ['FireDAC_64', 'FireDAC_SQLITE_EXTERNAL'] },
];

See tools/parse-corpus-orchestrated.js in the parent repo for the full reference set.

License

MIT.