Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: wrongly parsing #define when the right side of the definition is empty #212

Open
2 tasks done
abougouffa opened this issue Jul 24, 2024 · 0 comments
Open
2 tasks done
Labels

Comments

@abougouffa
Copy link

Did you check existing issues?

  • I have read all the tree-sitter docs if it relates to using the parser
  • I have searched the existing issues of tree-sitter-c

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

0.22.6

Describe the bug

The AST for C code with empty right side #define gets parsed incorrectly when a space or more is placed after.

Steps To Reproduce/Bad Parse Tree

In the code below, add a space after the second #define id(x)

(translation_unit
 (preproc_include #include path: (system_lib_string))
 (preproc_ifdef #ifdef name: (identifier)
  (preproc_function_def #define name: (identifier)
   parameters: (preproc_params ( (identifier) ))
   value: (preproc_arg))
  alternative: 
   (preproc_else #else
    (preproc_function_def #define name: (identifier)
     parameters: (preproc_params ( (identifier) ))
     value: (preproc_arg))
    (function_definition type: (primitive_type)
     declarator: 
      (function_declarator declarator: (identifier)
       parameters: (parameter_list ( )))
     body: 
      (compound_statement {
       (return_statement return (number_literal) ;)
       })))
  alternative: #endif))

Expected Behavior/Parse Tree

(translation_unit
 (preproc_include #include path: (system_lib_string))
 (preproc_ifdef #ifdef name: (identifier)
  (preproc_function_def #define name: (identifier)
   parameters: (preproc_params ( (identifier) ))
   value: (preproc_arg))
  alternative: 
   (preproc_else #else
    (preproc_function_def #define name: (identifier)
     parameters: (preproc_params ( (identifier) ))))
  #endif)
 (function_definition type: (primitive_type)
  declarator: 
   (function_declarator declarator: (identifier)
    parameters: (parameter_list ( )))
  body: 
   (compound_statement {
    (return_statement return (number_literal) ;)
    })))

Repro

#include <stdio.h>

#ifdef ID
#define id(x)    (x)
#else
#define id(x)    
#endif

int main() {
  return 0;
}
@abougouffa abougouffa added the bug label Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant