Skip to content
This repository was archived by the owner on Feb 6, 2019. It is now read-only.

Grammar builder ergonomics — throw if incorrect signature used #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

queerviolet
Copy link
Contributor

Specifically, throw if grammar builder functions are passed wrong number of args. This catches the common (for me) problem of doing something like optional('+', $.term) when I meant to do optional(seq('+', term)).

error = e;
}
assert.propertyVal(error, 'message',
`repeat takes a single argument, but 0 were given. Did you mean to use blank()?`)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we probably shouldn't suggest blank here, since repeat(blank()) wouldn't be useful. Maybe just the initial sentence in that case?

@@ -67,15 +67,15 @@ prec.right = function(number, rule) {
};
}

prec.dynamic = function(number, rule) {
prec.dynamic = maxArgs(function(number, rule) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we wrap prec, prec.left, and prec.right in maxArgs too?

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants