tree-sitter / tree-sitter-c

C grammar for tree-sitter
MIT License
225 stars 100 forks source link

Parser can't handle type qualifiers coming after primitives #178

Closed ribru17 closed 7 months ago

ribru17 commented 9 months ago

Did you check existing issues?

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

No response

Describe the bug

Type qualifiers coming after a primitive (e.g. int short myint = 5) are errors, where short is treated like an identifier and myint is treated as ERROR.

Steps To Reproduce/Bad Parse Tree

(declaration) ; [1:1 - 19]
 type: (primitive_type) ; [1:1 - 3]
 declarator: (init_declarator) ; [1:5 - 18]
  declarator: (identifier) ; [1:5 - 9]
  (ERROR) ; [1:11 - 14]
   (identifier) ; [1:11 - 14]
  "=" ; [1:16 - 16]
  value: (number_literal) ; [1:18 - 18]
 ";" ; [1:19 - 19]
(declaration) ; [2:1 - 19]
 type: (sized_type_specifier) ; [2:1 - 9]
  "short" ; [2:1 - 5]
  type: (primitive_type) ; [2:7 - 9]
 declarator: (init_declarator) ; [2:11 - 18]
  declarator: (identifier) ; [2:11 - 14]
  "=" ; [2:16 - 16]
  value: (number_literal) ; [2:18 - 18]
 ";" ; [2:19 - 19]

Expected Behavior/Parse Tree

(declaration) ; [1:1 - 19]
 type: (sized_type_specifier) ; [1:1 - 9]
  type: (primitive_type) ; [1:1 - 3]
  "short" ; [1:5 - 9]
 declarator: (init_declarator) ; [1:11 - 18]
  declarator: (identifier) ; [1:11 - 14]
  "=" ; [1:16 - 16]
  value: (number_literal) ; [1:18 - 18]
 ";" ; [1:19 - 19]
(declaration) ; [2:1 - 19]
 type: (sized_type_specifier) ; [2:1 - 9]
  "short" ; [2:1 - 5]
  type: (primitive_type) ; [2:7 - 9]
 declarator: (init_declarator) ; [2:11 - 18]
  declarator: (identifier) ; [2:11 - 14]
  "=" ; [2:16 - 16]
  value: (number_literal) ; [2:18 - 18]
 ";" ; [2:19 - 19]

Repro

int short int1 = 5;  // does not work
short int int2 = 5;  // works
amaanq commented 7 months ago

Fixed on master