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

Allow plural lone wildcard #158

Merged
merged 8 commits into from
Jul 26, 2022
Merged

Allow plural lone wildcard #158

merged 8 commits into from
Jul 26, 2022

Conversation

samhh
Copy link
Contributor

@samhh samhh commented Jul 23, 2022

Closes #108. #136 will follow in another PR.

Given:

{
  "f": { "message": "{n, plural, other {}}" },
  "g": { "message": "{n, selectordinal, other {}}" },
}

Previously:

$ intlc compile -l foo ./bar.json
./bar.json:2:34:
  |
2 |   "f": { "message": "{n, plural, other {}}" },
  |                                  ^^^^
unexpected "othe"
expecting "few", "many", "one", "two", "zero", '=', or white space

./bar.json:3:41:
  |
3 |   "g": { "message": "{n, selectordinal, other {}}" },
  |                                         ^^^^
unexpected "othe"
expecting "few", "many", "one", "two", "zero", '=', or white space

Now:

$ intlc compile -l foo ./bar.json
export const f: (x: { n: number }) => string = x => `${(() => { switch (x.n as typeof x.n) {  default: return ``; } })()}`
export const g: (x: { n: number }) => string = x => `${(() => { switch (new Intl.PluralRules('xyz', { type: 'ordinal' }).select(x.n)) {  default: return ``; } })()}`

Most of the diff is due to changes to the shape of the AST. Most attention should be paid to those AST changes themselves, and then the drastically simplified parsing (:smiley:). The tests should have caught any potential regressions... in theory!

Looking at the output there's a lot of space for optimisation, but I'm avoiding anything like that for now in pursuit of a simple compiler, as with how we solved #111.

The parser doesn't allow it yet, but this change means that the AST now
supports cardinal plurals with only a wildcard. This redundancy will now
be allowed but linted against.
As with the last commit, this is towards a more forgiving parser.
@samhh samhh requested a review from a team as a code owner July 23, 2022 18:12
@samhh samhh requested a review from Magellol July 23, 2022 18:12
@samhh samhh merged commit 6c94c91 into master Jul 26, 2022
@samhh samhh deleted the allow-plural-lone-wildcard branch July 26, 2022 11:52
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.

plural and selectordinal: allow single case other
1 participant