feat: add Enforce Script (DayZ) language support#1183
Open
Demandss wants to merge 3 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-csharpgrammar rather than vendoring a new one.
Why this approach
Enforce Script's syntax is close to C# (class inheritance via
:, C-stylemethod signatures), but it diverges in ways that break the C# grammar
outright. Most critically,
foreach (Type v: coll)(C# requiresin) andvoid ~ClassName()destructors (extravoidbefore~) each cascade intohundreds of ERROR nodes on real files once hit. It also handles the
extendsinheritance form (used alongside:in the same codebase), theproto/event/notnull/inoutmodifiers, and DayZ'smodded class Foomechanism: a language quirk where
modded class Foo: Barsilently dropsthe
: Barclause at compile time, soFoostays a descendant of itsoriginal declaration, not
Bar.Approach
enforcescriptlanguage token, not auto-mapped to.cbydefault. It's opt-in only via
codegraph.json(
{"extensions": {".c": "enforcescript"}}), with no change to existingC/C++ project behavior.
tree-sitter-csharp.wasm, so there's no new grammar to vendor.preParsetext-transform layer normalizes the syntax deltas beforehanding off to the C# parser (foreach
:toin, destructorvoidremoval,
extendsto:, stripping proto/event/notnull/inout/ref/autoptrmodifiers,
#ifdef/#endifhandling).enforcescript-modded.ts) linksmodded class Footo the original
class Foodeclared elsewhere in the codebase via asentinel-prefixed reference (
__enforcescript_modded__:Foo), rather thana 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):
chains that were invisible under plain
c/cppmapping.PlayerBasewent 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.
.cfiles and no configoverride still resolves as
c.