unsplash / intlc

Compile ICU messages into code. Supports TypeScript and JSX. No runtime.
MIT License
57 stars 3 forks source link

Fix nested plural hash #69

Closed samhh closed 2 years ago

samhh commented 2 years ago

Fixes #65.

We have a recursive token parser. Previously to support # we tacked support on inside the plural parser with <|>. This worked for shallow usages, but not for nested/deep usages in which we'd recurse back around to the aforementioned token parser sans # support.

We now instead keep track of plural State. When we encounter # in that top-level token parser, we inspect what plural context we're in. If we're in one, we parse as an interpolation. If we're not, we fail/skip the parse leading to it parsing as plaintext.

In order to support State in our Parser, we now use the ParsecT type where the T stands for "transformer". The previously used Parsec type was a mere alias around this with the Identity monad instead of our State monad, hence how little code changed.