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

Refactor messageformat-parser, moving from PEG.js to moo #288

Merged
merged 6 commits into from Sep 13, 2020
Merged

Conversation

eemeli
Copy link
Member

@eemeli eemeli commented Sep 5, 2020

As PEG.js is clearly not currently under active development (see pegjs/pegjs#639), this PR completely refactors the parser by reimplementing it in TypeScript and using moo to generate an efficient lexer.

The main benefit of the change is a significant improvement in error reporting, as the errors now include a pointer to the source of the error. Tokens now also include a ctx object, with information about tis source context. All of this is also partly groundwork for supporting any later spec changes that might arise from the MessageFormat Working Group

This PR does introduce some breaking changes:

  • Static strings are wrapped in a { type: 'content', value: string } token, rather than plain strings.
  • For plural & selectordinal tokens, the offset is renamed as pluralOffset.
  • Some of the errors change; braces {} with contents that are not MessageFormat are mostly parsed without error.
  • The TypeScript types are slightly refactored, as they're no longer manually maintained.

BREAKING CHANGE: The parser is completely rewritten in TypeScript. The
new implementation uses `moo` to create a lexer, rather than PEG.js.
During this change, the AST output changes slightly:
- Static strings are wrapped in a { type: 'content', value: string }
  token, rather than plain strings.
- Each token includes a `ctx` object, with information about its source
  context.
- For plural & selectordinal tokens, the offset is renamed as
  `pluralOffset`.
- Some of the errors change; braces with contents that are not
  MessageFormat are mostly parsed without error.
- The TypeScript types are slightly refactored, as they're no longer
  manually maintained.
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.

None yet

1 participant