Skip to content

Conversation

@apalala
Copy link
Collaborator

@apalala apalala commented Dec 25, 2025

As it was, a cut (~) could scape to calling rules instead of being limited to the enclosing choice, and that produced unexpected outcomes.

This set of changes limit the scope of cut to the nearest choice.

For example, this grammar would always fail independently of the input, when it is expected that rule two has a chance, and it always succeeds with "something" as output.

GRAMMAR = '''
    start =
        | one
        | two
        ;

    one = 
        | ~ !()   # cut fail
        | 'abc';
        
    two = `something` ; # result is the quoted text
'''

ast = parse(GRAMMAR, 'abc')
print(ast)

@apalala apalala merged commit 3c5cd87 into master Dec 25, 2025
5 checks passed
@apalala apalala deleted the cut_scope branch December 25, 2025 22:14
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.

2 participants