You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Typst has multiple parsing modes, two of which being markup and code. To switch from markup to code, you would use #, after which an expression or statement would follow. Users may end expressions with a ;, while they have to end statements using either a semicolon, or a newline. In the case of statements, before the ending character can be some spacing or a comment ("trivia").
Now, for some reason, semicolons after expressions are not considered part of the embedded_code_expr:
================================================================================
Inline code expression with semicolon and newline
================================================================================
#bar;
baz
--------------------------------------------------------------------------------
(source_file
(markup
(embedded_code_expr
(variable
(code_ident)))
- (text) ;; This should not be here!
(space)
(text)))
And, the other problem: If any spacing follows the statement, an error is detected:
================================================================================
Let binding, trailing semicolon with spacing
================================================================================
#let test ;
--------------------------------------------------------------------------------
(source_file
(markup
(embedded_code_expr
(let_binding
(space)
pattern: (pattern
(code_ident)))
- (ERROR- (space)))))+ (space))))
You can test this locally by cloning tree-sitter-typst and running tree-sitter test.
Thank you for reading this, I'd appreciate any ideas on the cause, or on how to fix it. :)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm working on tree-sitter-typst, a grammar to parse typst, a typesetting language.
Typst has multiple parsing modes, two of which being markup and code. To switch from markup to code, you would use
#
, after which an expression or statement would follow. Users may end expressions with a;
, while they have to end statements using either a semicolon, or a newline. In the case of statements, before the ending character can be some spacing or a comment ("trivia").I modelled the corresponding grammar rule here.
Now, for some reason, semicolons after expressions are not considered part of the
embedded_code_expr
:================================================================================ Inline code expression with semicolon and newline ================================================================================ #bar; baz -------------------------------------------------------------------------------- (source_file (markup (embedded_code_expr (variable (code_ident))) - (text) ;; This should not be here! (space) (text)))
And, the other problem: If any spacing follows the statement, an error is detected:
You can test this locally by cloning tree-sitter-typst and running
tree-sitter test
.Thank you for reading this, I'd appreciate any ideas on the cause, or on how to fix it. :)
Beta Was this translation helpful? Give feedback.
All reactions