diff --git a/src/Typst/Parse.hs b/src/Typst/Parse.hs index f66a384..7ab2219 100644 --- a/src/Typst/Parse.hs +++ b/src/Typst/Parse.hs @@ -189,11 +189,13 @@ mathOperatorTable = -- but we still don't match typst for "!"(a), which typst DOES consider -- a function guard $ case lastMathTok of + Just (pos', MGroup _ (Just t) _) + | pos == pos' -> T.all isLetter t Just (pos', Text t) | pos == pos' - -> not (T.all (\c -> isDigit c || - isSymbol c || - isPunctuation c) t) + -> case T.unsnoc t of + Nothing -> True + Just (_,c) -> isLetter c _ -> True args <- mGrouped '(' ')' True pure $ \expr -> MGroup Nothing Nothing [expr, args] diff --git a/test/out/math/attach-03.out b/test/out/math/attach-03.out index 69b2efd..3d7a7dc 100644 --- a/test/out/math/attach-03.out +++ b/test/out/math/attach-03.out @@ -42,18 +42,14 @@ , Comment , Equation False - [ MGroup + [ MAttach + (Just (Text "1")) Nothing - Nothing - [ MAttach - (Just (Text "1")) - Nothing - (Code - "test/typ/math/attach-03.typ" - ( line 3 , column 2 ) - (Ident (Identifier "pi"))) - , MGroup (Just "(") (Just ")") [ Text "Y" ] - ] + (Code + "test/typ/math/attach-03.typ" + ( line 3 , column 2 ) + (Ident (Identifier "pi"))) + , MGroup (Just "(") (Just ")") [ Text "Y" ] , Text "," , MAttach (Just @@ -103,11 +99,7 @@ (MGroup Nothing Nothing - [ MGroup - Nothing - Nothing - [ Text "1" , MGroup (Just "(") (Just ")") [ Text "Y" ] ] - ])) + [ Text "1" , MGroup (Just "(") (Just ")") [ Text "Y" ] ])) Nothing (Code "test/typ/math/attach-03.typ" diff --git a/test/out/math/frac-06.out b/test/out/math/frac-06.out index 003285f..1aa5232 100644 --- a/test/out/math/frac-06.out +++ b/test/out/math/frac-06.out @@ -107,12 +107,8 @@ , Text "+" , MFrac (MGroup (Just "[") (Just "]") [ Text "x" ]) (Text "2") , Text "," - , MFrac - (MGroup - Nothing - Nothing - [ Text "1" , MGroup (Just "(") (Just ")") [ Text "x" ] ]) - (Text "2") + , Text "1" + , MFrac (MGroup (Just "(") (Just ")") [ Text "x" ]) (Text "2") , Text "," , Text "2" , MFrac (MGroup (Just "[") (Just "]") [ Text "x" ]) (Text "2") @@ -202,11 +198,9 @@ document(body: { text(body: [ text(body: [x]), []] }))), text(body: [,]), + text(body: [1]), math.frac(denom: text(body: [2]), - num: { text(body: [1]), - math.lr(body: ({ [(], - text(body: [x]), - [)] })) }), + num: text(body: [x])), text(body: [,]), text(body: [2]), math.frac(denom: text(body: [2]), diff --git a/test/out/math/multiline-05.out b/test/out/math/multiline-05.out index 48fbaf0..80efb6f 100644 --- a/test/out/math/multiline-05.out +++ b/test/out/math/multiline-05.out @@ -75,12 +75,8 @@ (MGroup (Just "(") (Just ")") - [ MGroup - Nothing - Nothing - [ Text "5" - , MGroup (Just "(") (Just ")") [ Text "5" , Text "+" , Text "1" ] - ] + [ Text "5" + , MGroup (Just "(") (Just ")") [ Text "5" , Text "+" , Text "1" ] ]) (Text "2") , Text "=" diff --git a/test/out/math/op-01.out b/test/out/math/op-01.out index 9c48f81..a1d0dbb 100644 --- a/test/out/math/op-01.out +++ b/test/out/math/op-01.out @@ -65,18 +65,14 @@ ( line 4 , column 5 ) (FuncCall (Ident (Identifier "sin")) [ BlockArg [ Text "x" ] ]) , Text "+" - , MGroup - Nothing + , MAttach + (Just (Text "2")) Nothing - [ MAttach - (Just (Text "2")) - Nothing - (Code - "test/typ/math/op-01.typ" - ( line 4 , column 14 ) - (Ident (Identifier "log"))) - , MGroup (Just "(") (Just ")") [ Text "x" ] - ] + (Code + "test/typ/math/op-01.typ" + ( line 4 , column 14 ) + (Ident (Identifier "log"))) + , MGroup (Just "(") (Just ")") [ Text "x" ] ] , ParBreak ] diff --git a/test/out/math/unbalanced-00.out b/test/out/math/unbalanced-00.out index 510e1d4..f1782ed 100644 --- a/test/out/math/unbalanced-00.out +++ b/test/out/math/unbalanced-00.out @@ -78,11 +78,7 @@ , MGroup (Just "(") (Just ")") - [ MGroup - Nothing - Nothing - [ Text "2" , MGroup (Just "(") (Just ")") [ Text "3" ] ] - ] + [ Text "2" , MGroup (Just "(") (Just ")") [ Text "3" ] ] ]) ] , ParBreak diff --git a/test/out/regression/issue17.out b/test/out/regression/issue17.out index 2fdff77..b2053b0 100644 --- a/test/out/regression/issue17.out +++ b/test/out/regression/issue17.out @@ -52,12 +52,8 @@ , ParBreak , Equation False - [ MGroup - Nothing - Nothing - [ MAttach (Just (Text "1")) Nothing (Text "a") - , MGroup (Just "(") (Just ")") [ Text "x" ] - ] + [ MAttach (Just (Text "1")) Nothing (Text "a") + , MGroup (Just "(") (Just ")") [ Text "x" ] ] , ParBreak , Equation diff --git a/test/out/regression/issue54.out b/test/out/regression/issue54.out index 85d8bf9..c9a8566 100644 --- a/test/out/regression/issue54.out +++ b/test/out/regression/issue54.out @@ -50,13 +50,9 @@ Nothing (Text "c") , HardBreak - , MGroup - Nothing - Nothing - [ MAttach - (Just (MGroup Nothing Nothing [ Text "a" ])) Nothing (Text "c") - , MGroup (Just "(") (Just ")") [ Text "b" ] - ] + , MAttach + (Just (MGroup Nothing Nothing [ Text "a" ])) Nothing (Text "c") + , MGroup (Just "(") (Just ")") [ Text "b" ] , HardBreak , MAttach (Just (MGroup Nothing Nothing [ Text "a" , Text "!" ])) diff --git a/test/out/regression/issue55.out b/test/out/regression/issue55.out new file mode 100644 index 0000000..a078402 --- /dev/null +++ b/test/out/regression/issue55.out @@ -0,0 +1,76 @@ +--- parse tree --- +[ Code + "test/typ/regression/issue55.typ" + ( line 1 , column 2 ) + (Let + (BasicBind (Just (Identifier "test"))) + (FuncExpr + [ NormalParam (Identifier "x") , NormalParam (Identifier "y") ] + (Block + (CodeBlock + [ If + [ ( Equals (Ident (Identifier "x")) (Ident (Identifier "y")) + , Block (Content [ Text "\9989" ]) + ) + , ( Literal (Boolean True) + , Block + (Content + [ Text "\10060" + , Text "(" + , Code + "test/typ/regression/issue55.typ" + ( line 1 , column 47 ) + (FuncCall + (Ident (Identifier "repr")) + [ NormalArg (Ident (Identifier "x")) ]) + , Space + , Text "/" + , Text "=" + , Space + , Code + "test/typ/regression/issue55.typ" + ( line 1 , column 59 ) + (FuncCall + (Ident (Identifier "repr")) + [ NormalArg (Ident (Identifier "y")) ]) + , Text ")" + ]) + ) + ] + ])))) +, SoftBreak +, Equation + True + [ MGroup (Just "(") (Just ")") [ Text "b" ] + , MFrac + (MGroup (Just "(") (Just ")") [ Text "c" ]) + (MGroup Nothing Nothing [ Text "d" ]) + , Text "!" + , MFrac + (MGroup (Just "(") (Just ")") [ Text "a" ]) + (MGroup Nothing Nothing [ Text "b" ]) + , MGroup Nothing Nothing [ HardBreak , Text "!" ] + , MFrac + (MGroup (Just "(") (Just ")") [ Text "a" ]) + (MGroup Nothing Nothing [ Text "b" ]) + ] +, ParBreak +] +--- evaluated --- +document(body: { text(body: [ +]), + math.equation(block: true, + body: { math.lr(body: ({ [(], + text(body: [b]), + [)] })), + math.frac(denom: text(body: [d]), + num: text(body: [c])), + text(body: [!]), + math.frac(denom: text(body: [b]), + num: text(body: [a])), + linebreak(), + text(body: [!]), + math.frac(denom: text(body: [b]), + num: text(body: [a])) }, + numbering: none), + parbreak() }) diff --git a/test/typ/regression/issue55.typ b/test/typ/regression/issue55.typ new file mode 100644 index 0000000..ce066e8 --- /dev/null +++ b/test/typ/regression/issue55.typ @@ -0,0 +1,5 @@ +$ + (b)(c)/(d) + !(a)/(b) + \ !(a)/(b) +$