Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

peg: add support for "true" and "false" primitives to always/never match #1187

Merged
merged 2 commits into from
Jun 18, 2023

Commits on Jun 11, 2023

  1. peg: add support for "true" and "false" primitives to always/never match

    The use cases involve user-expandable grammars.
    For example, consider the IRC nickname specification.
    > They SHOULD NOT contain any dot character ('.', 0x2E).
    > Servers MAY have additional implementation-specific nickname restrictions.
    
    To implement this, we can do something along these lines:
    ```janet
    (def nickname @{:main '(some :allowed)
                    :allowed (! (+ :forbidden/dot :forbidden/user))
    	        # for lax mode, (put nickname :forbidden/dot false)
    	        :forbidden/dot "."
    		# to add your own requirements
    		# (put nickname :forbidden/user 'something)
    		:forbidden/user false})
    ```
    
    Additionally, it's common in parsing theory to allow matches of the
    empty string (epsilon). `true` essentially allows for this.
    
    Note that this does not strictly add new functionality, you could
    emulate this previously using `0` and `(! 0)` respectively, but this
    should be faster and more intuitive.
    The speed improvement primarily comes from `(! 0)` which is now a single
    step.
    CosmicToast committed Jun 11, 2023
    Configuration menu
    Copy the full SHA
    f9ab915 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    e54ea7a View commit details
    Browse the repository at this point in the history