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

Implicit whitespace rules #554

Open
1 task done
alexchandel opened this issue Jan 11, 2018 · 3 comments
Open
1 task done

Implicit whitespace rules #554

alexchandel opened this issue Jan 11, 2018 · 3 comments
Labels
Milestone

Comments

@alexchandel
Copy link

alexchandel commented Jan 11, 2018

Issue type

  • Feature Request

Description

Manually inserting whitespace rules is somewhat cumbersome & error-prone, especially for larger grammars with 100s of rules. One of the nicest features of Perl's grammar-parsing package, Regexp::Grammars, is its implicit whitespace rule.

Essentially, Regexp::Grammars has two types of rules, "tokens" and "rules." In rule definitions, most sequences of whitespace are treated as implicit invocations of the <.ws> rule, which is automatically predefined to \s* & captures nothing (since matching whitespace is often useless). In token definitions, whitespace is ignored as in PEG.js.

It would be nice if PEG.js had an alternate rule type, like ::=, that implicitly matched whitespace.

@futagoza
Copy link
Member

This has been bought up before (see #11), but before I tackle this, I want #256 to be implemented first. Would also prefer #311 and #523 to be done first, but they just ease the use of this feature request.

As for an alternative rule type invoked by syntax sugar like ::=, after #256 is done, it should be easier to implement (quite simply, it would just enable the rule annotation for ignoring whitespace, e.g @ignore(...ruleNames)).

@futagoza futagoza added this to the post-1.0.0 milestone Jan 11, 2018
@alexchandel
Copy link
Author

I've made do with the _ rule for now. Since regex anchors like \b are missing from pegjs, I had to cook up a &[^A-Za-z0-9_] rule to terminate words with instead.

@futagoza
Copy link
Member

futagoza commented Jan 22, 2018

PEG.js doesn't support using JavaScript native RegExps as expressions, which is why there is
no support for any anchors (see docs).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants