Skip to content

Fix Molang parser treating namespaced identifiers as expressions#149

Merged
DaanV2 merged 2 commits into
mainfrom
copilot/fix-invalid-molang-errors
Dec 20, 2025
Merged

Fix Molang parser treating namespaced identifiers as expressions#149
DaanV2 merged 2 commits into
mainfrom
copilot/fix-invalid-molang-errors

Conversation

Copilot AI commented Dec 20, 2025

Copy link
Copy Markdown
Contributor

The Molang diagnoser was throwing errors on valid resource identifiers like minecraft:geometry.full_block because the regex matched geometry. anywhere in the string, treating namespaced identifiers as Molang expressions.

Changes

  • Modified regex pattern in packages/molang/src/molang/functions.ts

    • Added negative lookbehind (?<!:) to prevent matching after colons
    • Pattern now correctly distinguishes minecraft:geometry.full_block (identifier) from geometry.custom (Molang)
  • Added test coverage in packages/molang/test/data/dataset-lookslike.ts

    • Tests for namespace:geometry.*, namespace:texture.*, namespace:material.* patterns

Example

// Before: Both matched as Molang
isMolang('minecraft:geometry.full_block')  // true ❌
isMolang('geometry.custom')                 // true

// After: Only valid Molang matches
isMolang('minecraft:geometry.full_block')  // false ✓
isMolang('geometry.custom')                 // true ✓
Original prompt

There are errors being thrown by the diagnoser because of invalid molang:

minecraft:geometry.full_block

However this is valid, but probally shouldn't tried to parsed or add the to list of resources used


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Modified the molang detection regex to use negative lookbehind (?<!:) to prevent
matching patterns like 'minecraft:geometry.full_block' which are resource identifiers,
not molang expressions. Added comprehensive test cases to prevent regression.

Co-authored-by: DaanV2 <2393905+DaanV2@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix errors thrown by diagnoser for valid molang Fix Molang parser treating namespaced identifiers as expressions Dec 20, 2025
Copilot AI requested a review from DaanV2 December 20, 2025 22:09
@DaanV2

DaanV2 commented Dec 20, 2025

Copy link
Copy Markdown
Contributor

@copilot check that diagnoser doesn't look through the molang and tries to find out what is used / defined, we need to ensure that this doesn't skip out check of resources made

Copilot AI commented Dec 20, 2025

Copy link
Copy Markdown
Contributor Author

@copilot check that diagnoser doesn't look through the molang and tries to find out what is used / defined, we need to ensure that this doesn't skip out check of resources made

Resource tracking is not affected by the regex fix. The system has two independent code paths:

Path 1: Molang harvesting (harvestMolang) - Uses isMolang() to parse expressions. Our fix prevents "minecraft:geometry.full_block" from being incorrectly parsed as Molang.

Path 2: Resource tracking (getUsingResources in packages/bedrock-project/src/internal/resource-pack/resources.ts) - Directly iterates over geometry/material/texture definitions and adds them to assigned WITHOUT using isMolang().

Example from entity/process.ts:

molang: harvestMolang(content, description),  // Path 1
// ...
getUsingResources(out.molang, description, doc);  // Path 2

The getUsingResources function explicitly adds ALL resource identifiers (including "minecraft:geometry.full_block") regardless of our regex change. Both paths continue to work correctly.

@DaanV2 DaanV2 marked this pull request as ready for review December 20, 2025 22:18
@github-actions github-actions Bot added dependencies Pull requests that update a dependency file release vscode ide packages labels Dec 20, 2025
@DaanV2 DaanV2 merged commit 983d671 into main Dec 20, 2025
5 checks passed
@DaanV2 DaanV2 added this to the next-release milestone Dec 26, 2025
@DaanV2 DaanV2 deleted the copilot/fix-invalid-molang-errors branch January 15, 2026 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file ide packages release vscode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants