Skip to content

Commit

Permalink
Fix issue with expression parsing involving labels.
Browse files Browse the repository at this point in the history
Closes #59.
  • Loading branch information
jgm committed Dec 12, 2024
1 parent 2d6ee91 commit cea4bc7
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/Typst/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -713,12 +713,12 @@ pLabelInContent = Code <$> getPosition <*> pLabel
pLabel :: P Expr
pLabel =
Label . T.pack
<$> try
<$> lexeme (try
( char '<'
*> many1 (satisfy isIdentContinue <|>
char '_' <|> char '.' <|> char ':')
<* char '>'
)
))

pRef :: P Markup
pRef =
Expand Down
2 changes: 0 additions & 2 deletions test/out/compiler/label-01.out
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
, Space
, Code
"test/typ/compiler/label-01.typ" ( line 7 , column 4 ) (Label "v")
, Space
, Code
"test/typ/compiler/label-01.typ"
( line 7 , column 9 )
Expand All @@ -92,6 +91,5 @@ document(body: { text(body: [
strong(body: text(body: [A])),
text(body: [ ]),
<v>,
text(body: [ ]),
strong(body: text(body: [B])),
parbreak() })
2 changes: 0 additions & 2 deletions test/out/compiler/label-03.out
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
"test/typ/compiler/label-03.typ"
( line 6 , column 9 )
(Label "red")
, Space
, Strong [ Text "C" ]
, Space
, Code
Expand All @@ -91,7 +90,6 @@ document(body: { text(body: [
strong(body: text(body: [B])),
text(body: [ ]),
<red>,
text(body: [ ]),
strong(body: text(body: [C])),
text(body: [ ]),
<blue>,
Expand Down
7 changes: 0 additions & 7 deletions test/out/meta/counter-01.out
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@
"test/typ/meta/counter-01.typ"
( line 3 , column 2 )
(Let (BasicBind (Just (Identifier "label"))) (Label "heya"))
, Space
, Code
"test/typ/meta/counter-01.typ"
( line 3 , column 14 )
(Label "heya")
, SoftBreak
, Code
"test/typ/meta/counter-01.typ"
Expand Down Expand Up @@ -112,8 +107,6 @@
--- evaluated ---
document(body: { text(body: [
]),
text(body: [ ]),
<heya>,
text(body: [
]),
text(body: [
Expand Down
56 changes: 56 additions & 0 deletions test/out/regression/issue59.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
--- parse tree ---
[ Code
"test/typ/regression/issue59.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/issue59.typ"
( line 1 , column 47 )
(FuncCall
(Ident (Identifier "repr"))
[ NormalArg (Ident (Identifier "x")) ])
, Space
, Text "/"
, Text "="
, Space
, Code
"test/typ/regression/issue59.typ"
( line 1 , column 59 )
(FuncCall
(Ident (Identifier "repr"))
[ NormalArg (Ident (Identifier "y")) ])
, Text ")"
])
)
]
]))))
, SoftBreak
, Code
"test/typ/regression/issue59.typ"
( line 2 , column 2 )
(If
[ ( Not (Equals (Literal (Int 5)) (Label "foo"))
, Block (CodeBlock [ Block (Content [ Text "a" ]) ])
)
])
, ParBreak
]
--- evaluated ---
document(body: { text(body: [
]),
text(body: [a]),
parbreak() })
1 change: 1 addition & 0 deletions test/typ/regression/issue59.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#if 5 != <foo> {[a]}

0 comments on commit cea4bc7

Please sign in to comment.