Update grammar, expand CRC32 function #2

Merged
dominic merged 4 commits from grammar into master 2026-04-25 10:26:06 +00:00
Owner

Summary

This PR introduces several significant updates to the XN grammar and transformation engine, including support for bitwise operations, improved function parameter handling, and enhanced error reporting.

Major Changes

  1. Language & Grammar Updates
    Bitwise Operations: Added support for bitwise XOR (^), AND (&), and OR (|) operators.
    Power Operator: Renamed the power operator from ^ to ** to align with common mathematical notation and avoid conflict with bitwise XOR.
    Hexadecimal Literals: Added support for hex numbers in expressions (e.g., 0xDEADBEEF).
    Stricter Semicolon Grammar: Rules and Bangs now strictly require a semicolon terminator for better parsing reliability and clearer error hints when one is missing.
    Multi-Rule Support: The parser now supports multiple root-level rules in a single .xn file.
  2. Built-in Functions & Transformations
    Parameterized CRC32: The crc() function has been renamed to crc32() and expanded to support custom polynomials, initial values, and bit reflection. It defaults to the MPEG-2 standard.
    String Utilities:
    Renamed hex() to hexlit(), which now defaults to lowercase output.
    Added lower() and upper() functions for string case conversion.
    require() Function: Added a new require(message) function that throws a RequireException if a node is missing during transformation, allowing for explicit validation of XML structures.
  3. Error Handling & Plumbing
    Default Parameter Support: The function resolution logic now correctly handles C# methods with optional/default parameters.
    Enhanced Parse Errors: Added hints to the CLI output when a missing semicolon is likely the cause of a parsing failure.
    RequireException: Introduced a specific exception type for failed requirements, which includes source location tracking for precise error reporting in the input files.
## Summary This PR introduces several significant updates to the XN grammar and transformation engine, including support for bitwise operations, improved function parameter handling, and enhanced error reporting. ## Major Changes 1. Language & Grammar Updates Bitwise Operations: Added support for bitwise XOR (^), AND (&), and OR (|) operators. Power Operator: Renamed the power operator from ^ to ** to align with common mathematical notation and avoid conflict with bitwise XOR. Hexadecimal Literals: Added support for hex numbers in expressions (e.g., 0xDEADBEEF). Stricter Semicolon Grammar: Rules and Bangs now strictly require a semicolon terminator for better parsing reliability and clearer error hints when one is missing. Multi-Rule Support: The parser now supports multiple root-level rules in a single .xn file. 2. Built-in Functions & Transformations Parameterized CRC32: The crc() function has been renamed to crc32() and expanded to support custom polynomials, initial values, and bit reflection. It defaults to the MPEG-2 standard. String Utilities: Renamed hex() to hexlit(), which now defaults to lowercase output. Added lower() and upper() functions for string case conversion. require() Function: Added a new require(message) function that throws a RequireException if a node is missing during transformation, allowing for explicit validation of XML structures. 3. Error Handling & Plumbing Default Parameter Support: The function resolution logic now correctly handles C# methods with optional/default parameters. Enhanced Parse Errors: Added hints to the CLI output when a missing semicolon is likely the cause of a parsing failure. RequireException: Introduced a specific exception type for failed requirements, which includes source location tracking for precise error reporting in the input files.
dominic added 4 commits 2026-04-25 10:20:30 +00:00
To easily spot semicolon errors, they are now
mandatory delimiters after each construct.

Add require() to raise an error if a match is unsucessful.

Multiple rules in one xn files now possible.
dominic merged commit 01e08f1902 into master 2026-04-25 10:26:06 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dominic/xn#2
No description provided.