jgm / typst-hs

Haskell library for parsing and evaluating typst
Other
42 stars 5 forks source link

Allow colon at start of dict literal #46

Closed CMDJojo closed 6 months ago

CMDJojo commented 6 months ago

Resolves #45 and #43.

Allowing a colon at the start of a dict literal allows the following expressions, which before this was parsed by typst but not by typst-hs:

#let a = (:a:1)
#let b = ( : b : 2)
#let c = (:..a)

Adding optional (sym ":") *> ... at Parse.hs:993 wasn't quite enough due to:

Regression tests were added (to the existing regression/issue43.typ)

One other test changed: spread-09 compiler test. It tested spreading arrays and dicts, and previously it failed on the parser step (since dict spreading wasn't available). Now it fails due to another bug: apparently #let x = (..none) is parsed as a dict spreading rather than an array spreading. Since array parsing has priority over dict parsing, the error is due to the array parsing not allowing that expression. (You can try this out in the old parser, before this PR, parsing #let x = (..none) fails). We could make a separate case in the dict parser that : is not optional if it only contains spread statements, but I think this is unnecessary since if we fix the array parser, this will be a non-issue, and statements like #let x = (..a, b:2) is allowed in Typst (without initial :). I will create an issue for the array spread parser issue.

jgm commented 6 months ago

Great! Many thanks for this. I've made one small comment in the code.

CMDJojo commented 6 months ago

Thanks for the input! Seems good to avoid backtracking.