jgm / typst-hs

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

Support `context` #53

Open KaiAragaki opened 1 week ago

KaiAragaki commented 1 week ago

Hello!

I'm rather new to Typst, so please forgive me if what I'm saying doesn't make sense or is otherwise insane!

I was having issues where Typst would compile a document fine, but Pandoc would not. It appeared to be an issue with library code in CeTZ

This appears to reproduce the issue:

#let fun() = context {
    _ = "hi"
}

However, both of these are fine:

#let fun() = {
    _ = "hi"
}
#let fun() = context {
    x = "hi"
}

Additionally, this compiles fine, leading me to believe that _ might be misinterpreted as the beginning of an emphasis marker:

#let fun() = context {
    __ = "hi"
}
jgm commented 13 hours ago

Actually the second example isn't parsed correctly at all:

ld: warning: -U option is redundant when using -undefined dynamic_lookup
#let fun() = context {
    x = "hi"
}
--- parse tree ---
[ Code
    "stdin"
    ( line 1 , column 2 )
    (LetFunc (Identifier "fun") [] (Ident (Identifier "context")))
, Space
, Text "{"
, SoftBreak
, Text "x"
, Space
, Text "="
, Space
, Quote '"'
, Text "hi"
, Quote '"'
, SoftBreak
, Text "}"
, ParBreak
]

The issue is that we don't currently support context.

jgm commented 13 hours ago

I'm not sure I completely understand what context does; but I suppose as a first measure we should at least support the syntax so we don't get these crashes. That should not be hard.

jgm commented 12 hours ago

If I understand correctly, context can occur before any expression and it makes that expression into a special "contextualized" thing that is evaluated only in context.