jgm / typst-hs

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

Parse error with function-applications as dictionary keys #19

Closed ntjess closed 11 months ago

ntjess commented 11 months ago

Explain the problem. The following is a valid typst document that compiles under typst 0.10.0 (70ca0d25) pandoc online link

#let nums = (1, none, 2)
#nums.map(num => {
  if num == none {
    return 1
  }
  return ((str(num)): 1)
})

But converting with pandoc 3.1.10, it results in the following error:

".\tmp.typ" (line 2, column 17):
unexpected '>'
jgm commented 11 months ago

I think the problem is actually in the second to last line. This simpler case:

#{ return ((str(5)): 1) }

produces

"stdin" (line 1, column 20):
unexpected ":"
expecting "//", "/*", operator or ")"

What is this syntax with the colon?

jgm commented 11 months ago

Sorry, I see now that it's dictionary forming. Better example (actually valid in typst):

#(1,2).map(num => return (str(num): num) )
"stdin" (line 1, column 18):
unexpected '>'
expecting operator

Should produce:

(("1":1),("2":2))
jgm commented 11 months ago

Zeroing in on the real problem:

#(str(3): 3, str(4): 4)
"stdin" (line 1, column 9):
unexpected ":"
expecting "//", "/*", "[", operator or ")"

Apparently typst-hs doesn't like dictionary syntax where the key is not a constant.