Skip to content

Add Comprehensive Operator Support and Improve Expression Parsing#42

Merged
vagetman merged 21 commits intomainfrom
quoteless-variables
Oct 27, 2025
Merged

Add Comprehensive Operator Support and Improve Expression Parsing#42
vagetman merged 21 commits intomainfrom
quoteless-variables

Conversation

@vagetman
Copy link
Collaborator

@vagetman vagetman commented Oct 12, 2025

Changes Made

🔧 New Operators Added

  • Equality operators: == (equals), != (not equals)
  • Comparison operators: < (less than), <= (less than or equal), > (greater than), >= (greater than or equal)
  • Logical operators: && (logical AND), || (logical OR)
  • Unary operator: ! (negation)

🏷️ XML Attribute Parsing

  • ESI include tag support: Full parsing of <esi:include src="..." alt="..." /> tags
  • Attribute extraction: Proper handling of XML attributes with quoted values

🎯 Expression Features

  • Type-aware comparison: Numeric comparison for integers, string comparison for text values
  • Bareword support in variable subscripts: Allow unquoted identifiers in variable lookups (e.g., $(QUERY_STRING{param}))
  • Contextual bareword parsing: Barewords only treated as strings in variable subscript position
  • Parenthesized expressions: Support for (expression) syntax for grouping and precedence
  • Enhanced error handling: Improved error messages and proper error propagation

🏗️ Architecture Changes

  • Unified operator handling: Refactored to use Token::Operation(Operator) for all operators
  • Improved lexer: Added support for multi-character operators
  • Better parser structure: Enhanced maintainability and extensibility
  • Type-aware evaluation: Different evaluation logic for numeric vs string comparisons

📚 Documentation

  • Fixed doctests: Updated all code examples in documentation to compile and pass
  • Improved examples: Added working examples for new operator functionality
  • Better API docs: Enhanced documentation with accurate usage patterns

Testing

  • Added comprehensive tests for all new operators and operator combinations
  • Added tests for bareword variable subscripts
  • Added tests for ESI include tag parsing
  • Added tests for complex expressions with negation and parentheses
  • Added tests for type coercion and mixed expression types
  • All existing tests continue to pass

Examples

ESI Include Tags

<!-- Include with expression in src -->
<esi:include src="/api/user/$(QUERY_STRING{user_id})" />

Standard HTML Tags with Attributes

<a href="/page/$(QUERY_STRING{id})">Dynamic Link</a>
<img src="/images/$(HTTP_HEADER{theme})/logo.png" alt="Logo" />

New Equality Operations

<esi:choose>
    <esi:when test="$(QUERY_STRING{param}) == 'value'">
        Parameter matches!
    </esi:when>
    <esi:when test="$(HTTP_HOST) != 'localhost'">
        Not running locally
    </esi:when>
</esi:choose>

Bareword Variable Subscripts

<esi:vars>
    $(QUERY_STRING{param})          <!-- New: bareword subscript -->
    $(QUERY_STRING{'param'})        <!-- Still supported: quoted -->
</esi:vars>

Complex Expressions with Negation

<esi:when test="!($(QUERY_STRING{debug}) == 'true')">
    Debug mode is off
</esi:when>

Breaking Changes

None - all changes are additive and maintain backward compatibility.

Performance Impact

Minimal - changes are primarily to parsing logic with no impact on runtime evaluation performance.

Ready for review 🚀

vagetman added 9 commits July 25, 2025 19:38
- Added debug logging for query string retrieval and expression evaluation.
- Improved error handling for lexing interpolated expressions.
- Updated tests to cover various scenarios including missing closing brackets, standalone barewords, and mixed subfield types.
- Enhanced the Processor documentation with examples for better clarity.
- Implemented tests for nested subfields and compatibility with ESI choose/when constructs.
- Refactored the variable parsing logic to handle special characters and edge cases more robustly.
…ation and enhance tests for ESI choose/when compatibility
…operators, and update tests for new functionality
@vagetman vagetman changed the title Enhance ESI expression parsing and evaluation support Add Comprehensive Operator Support and Improve Expression Parsing Oct 13, 2025
@vagetman vagetman marked this pull request as ready for review October 13, 2025 18:55
@kailan kailan self-requested a review October 14, 2025 08:58
@kailan kailan added the enhancement New feature or request label Oct 14, 2025
Copy link
Member

@kailan kailan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fantastic, thank you so much for your work here!

I made a few minor suggestions, most of which are just clippy lints. Apart from that it looks good to go 👍

vagetman and others added 8 commits October 27, 2025 09:17
Co-authored-by: Kailan Blanks <kblanks@fastly.com>
Co-authored-by: Kailan Blanks <kblanks@fastly.com>
Co-authored-by: Kailan Blanks <kblanks@fastly.com>
Co-authored-by: Kailan Blanks <kblanks@fastly.com>
Co-authored-by: Kailan Blanks <kblanks@fastly.com>
Co-authored-by: Kailan Blanks <kblanks@fastly.com>
Co-authored-by: Kailan Blanks <kblanks@fastly.com>
Co-authored-by: Kailan Blanks <kblanks@fastly.com>
Copy link
Member

@kailan kailan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ship it! :shipit:

@vagetman vagetman merged commit e35dc20 into main Oct 27, 2025
3 checks passed
@vagetman vagetman deleted the quoteless-variables branch October 27, 2025 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants