Skip to content

feat: add Enforce Script (DayZ) language support#1183

Open
Demandss wants to merge 3 commits into
colbymchenry:mainfrom
Demandss:feat/enforcescript-language-support
Open

feat: add Enforce Script (DayZ) language support#1183
Demandss wants to merge 3 commits into
colbymchenry:mainfrom
Demandss:feat/enforcescript-language-support

Conversation

@Demandss

@Demandss Demandss commented Jul 5, 2026

Copy link
Copy Markdown

Feature: Enforce Script (DayZ modding language) support via C# grammar reuse

I've implemented opt-in support for Enforce Script (.c files, the scripting
language for Bohemia's Enfusion engine used in DayZ modding) as a new
language token enforcescript, reusing the existing tree-sitter-csharp
grammar rather than vendoring a new one.

Why this approach

Enforce Script's syntax is close to C# (class inheritance via :, C-style
method signatures), but it diverges in ways that break the C# grammar
outright. Most critically, foreach (Type v: coll) (C# requires in) and
void ~ClassName() destructors (extra void before ~) each cascade into
hundreds of ERROR nodes on real files once hit. It also handles the
extends inheritance form (used alongside : in the same codebase), the
proto/event/notnull/inout modifiers, and DayZ's modded class Foo
mechanism: a language quirk where modded class Foo: Bar silently drops
the : Bar clause at compile time, so Foo stays a descendant of its
original declaration, not Bar.

Approach

  • New enforcescript language token, not auto-mapped to .c by
    default. It's opt-in only via codegraph.json
    ({"extensions": {".c": "enforcescript"}}), with no change to existing
    C/C++ project behavior.
  • Reuses tree-sitter-csharp.wasm, so there's no new grammar to vendor.
  • A preParse text-transform layer normalizes the syntax deltas before
    handing off to the C# parser (foreach : to in, destructor void
    removal, extends to :, stripping proto/event/notnull/inout/ref/autoptr
    modifiers, #ifdef/#endif handling).
  • A dedicated resolver (enforcescript-modded.ts) links modded class Foo
    to the original class Foo declared elsewhere in the codebase via a
    sentinel-prefixed reference (__enforcescript_modded__:Foo), rather than
    a plain name reference. This avoids a self-loop edge in projects where
    the modded class is the only same-named symbol currently indexed, since
    general name-matching has no self-exclusion.

Tested on Bohemia's own official source dump

(BohemiaInteractive/DayZ-Script-Diff, ~2,800 files):

  • Impact analysis on core vanilla classes now shows real inheritance
    chains that were invisible under plain c/cpp mapping. PlayerBase
    went from 1-7 affected symbols to 2,245, because the old mapping's
    foreach/destructor parsing failures were cascading into ERROR nodes
    that dropped most of the file from the graph in the first place.
  • No regression: a fresh project with plain .c files and no config
    override still resolves as c.
  • Full extraction test suite passes.

Demandss added 3 commits July 5, 2026 21:57
Adds enforcescript (DayZ modding language, .c) as a language token that reuses the vendored C# grammar.
Built-in EXTENSION_MAP is untouched (.c stays c by default) — enforcescript only activates via a project's codegraph.json extensions override.
preParse rewrites EnforceScript-only syntax (foreach colon form, void ~destructor, modded class inheritance, extends, proto/event/notnull/inout/autoptr, #ifdef) into shapes the C# grammar parses cleanly.
modded class Foo silently drops any inheritance clause at compile time, so the extractor emits a sentinel-prefixed reference (__enforcescript_modded__:Foo) instead of a real name. Only this dedicated resolver ever claims that prefix — general name-matching has no self-exclusion and would risk a self-loop edge when the modded class is the only same-named symbol in the project.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant