latex-lsp / tree-sitter-latex

LaTeX grammar for tree-sitter
MIT License
87 stars 21 forks source link

Wrong parsing of `new_command_definition` #129

Open jdujava opened 4 weeks ago

jdujava commented 4 weeks ago

Following code

\NewDocumentCommand{\foo}{}{foo}
\NewDocumentCommand{\bar}{O{def}}{#1}

is (wrongly) parsed as

(source_file ; [0, 0] - [2, 0]
  (new_command_definition ; [0, 0] - [0, 27]
    declaration: (curly_group_command_name ; [0, 19] - [0, 25]
      command: (command_name)) ; [0, 20] - [0, 24]
    implementation: (curly_group)) ; [0, 25] - [0, 27]
  (curly_group ; [0, 27] - [0, 32]
    (text ; [0, 28] - [0, 31]
      word: (word))) ; [0, 28] - [0, 31]
  (new_command_definition ; [1, 0] - [1, 33]
    declaration: (curly_group_command_name ; [1, 19] - [1, 25]
      command: (command_name)) ; [1, 20] - [1, 24]
    implementation: (curly_group ; [1, 25] - [1, 33]
      (text ; [1, 26] - [1, 27]
        word: (word)) ; [1, 26] - [1, 27]
      (curly_group ; [1, 27] - [1, 32]
        (text ; [1, 28] - [1, 31]
          word: (word))))) ; [1, 28] - [1, 31]
  (curly_group ; [1, 33] - [1, 37]
    (text ; [1, 34] - [1, 36]
      word: (placeholder)))) ; [1, 34] - [1, 36]

The signature of \NewDocumentCommand-type macros is different from \newcommand. They always have parameter specification as second curly group.

Probably the same applies to \NewDocumentEnvironment-type definitions.