unsplash / intlc

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

Embed list directly into AST type #170

Closed samhh closed 1 year ago

samhh commented 1 year ago

Rather than our Node constructors containing [Node], they now contain Node in those places, and an additional Node sibling. In a sense this is directly embedding Haskell's singly-linked list into our core AST type, hence the addition of the Fin constructor, equivalent to list Nil. Alternative primed constructors are supplied via patterns, so instead of String x Fin you can write String' x.

With this PR alone it's a relatively neutral change, but it enables more powerful recursion schemes in #171.

Additionally an IsString instance has been added, which can be backported to the previous AST representation if this PR isn't merged. It transforms "xy" directly into Char 'x' (Char 'y' Fin) (previously Plaintext "xy").

Oh, and with us embracing holding chars rather than strings, we can say goodbye to mergePlaintext.

Before (with IsString sugar): ["Hello ", String "name", etc]

After: mconcat ["Hello", String' "name", etc]