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:
On input (:a:1), pEmptyDict successfully parsed all its content (the symbol :)
Since it consumed input, <|> killed the second branch (pNonemptyDict)
inParens failed since it looked for the closing bracket, when there were still elements to be parsed, making the parsing fail
I resolved it by first trying to parse it as a non-empty dict, with try allowing it to fallback to an empty dict if it finds an initial : and starts parsing, but then fails due to no entries being in the dict
This may possibly lead to worse error messages (possibly, I am unsure), feel free to change this if you have a better idea
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.
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:
Adding
optional (sym ":") *> ...
atParse.hs:993
wasn't quite enough due to:(:a:1)
,pEmptyDict
successfully parsed all its content (the symbol:
)<|>
killed the second branch (pNonemptyDict
)inParens
failed since it looked for the closing bracket, when there were still elements to be parsed, making the parsing failtry
ing to parse it as a non-empty dict, withtry
allowing it to fallback to an empty dict if it finds an initial:
and starts parsing, but then fails due to no entries being in the dictRegression 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.