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

Eliminate lookbehind in grammar #300

Open
Thom1729 opened this issue Mar 8, 2023 · 0 comments
Open

Eliminate lookbehind in grammar #300

Thom1729 opened this issue Mar 8, 2023 · 0 comments

Comments

@Thom1729
Copy link
Collaborator

Thom1729 commented Mar 8, 2023

The 1.2.2 spec defined the parsing algorithm to be very similar to a PEG. One significant difference is that the spec grammar uses a negative lookbehind, which is not part of the PEG model. This lookbehind is used only to ensure that the string # cannot appear in a plain scalar.

In 1.2.1:

[130] ns-plain-char(c)  ::= ( ns-plain-safe(c) - “:” - “#” )
                          | ( /* An ns-char preceding */ “#” )
                          | ( “:” /* Followed by an ns-plain-safe(c) */ )

In 1.2.2, we formalized this as:

[130] ns-plain-char(c) ::=
    (
        ns-plain-safe(c)
      - c-mapping-value    # ':'
      - c-comment          # '#'
    )
  | (
      [ lookbehind = ns-char ]
      c-comment          # '#'
    )
  | (
      c-mapping-value    # ':'
      [ lookahead = ns-plain-safe(c) ]
    )

I think we can avoid the lookbehind by adding [ lookahead ≠ '#' ] in a couple of places instead.

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

No branches or pull requests

1 participant