uben0/tree-sitter-typst

Unreachable when writing a square bracket and a list

Closed this issue · 2 comments

monaqa commented

In text mode, if a list is written after a square bracket without escaping, an unreachable error is displayed during parsing.
The list does not have to be immediately after the square bracket, and it seems to reproduce even when placed across paragraphs and apart.

  • Example code:

    [foo] bar
    
    baz
    
    - foo
  • Result:

    unreachable src/scanner.c:237
    (source_file [0, 0] - [5, 0]
      (text [0, 0] - [0, 1])
      (text [0, 1] - [0, 4])
      (text [0, 4] - [0, 5])
      (text [0, 6] - [0, 9])
      (parbreak [0, 9] - [2, 0])
      (text [2, 0] - [2, 3])
      (parbreak [2, 3] - [4, 0])
      (item [4, 0] - [4, 5]
        (text [4, 2] - [4, 5])))
    

Since installing tree-sitter-typst, my Typst environment has become much more comfortable. Thank you so much!

uben0 commented

I found the bug and fixed it.

Explanation:

Plain text square brackets, as they have an effect on the semantic:

#strong[Hello [] World]
#strong[Hello  ] World]

They are considered as containers, and as they do not effect the indentation, no indentation level is pushed on the indentation stack. But when the ] was encountered, the indentation stack was pop of one level. I removed this pop.

monaqa commented

I tried ecf8596 it in my environment and confirmed that the problem has been resolved. Thank you for your quick response and fix!