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

Unexpected trailing newlines in preprocessor nodes #97

Closed
Wilfred opened this issue Mar 28, 2022 · 1 comment · Fixed by #156
Closed

Unexpected trailing newlines in preprocessor nodes #97

Wilfred opened this issue Mar 28, 2022 · 1 comment · Fixed by #156

Comments

@Wilfred
Copy link

Wilfred commented Mar 28, 2022

Given the C code:

#include "foo.h"
#include "novel.h"


struct Bar {};

The parse tree produced is:

{Node translation_unit (0, 0) - (5, 0)}
  {Node preproc_include (0, 0) - (1, 0)}
    {Node #include (0, 0) - (0, 8)} "#include"
    {Node string_literal (0, 9) - (0, 16)}
      {Node " (0, 9) - (0, 10)} "\""
      {Node " (0, 15) - (0, 16)} "\""
    {Node '\n' (0, 16) - (1, 0)} "\n"
  {Node preproc_include (1, 0) - (4, 0)}
    {Node #include (1, 0) - (1, 8)} "#include"
    {Node string_literal (1, 9) - (1, 18)}
      {Node " (1, 9) - (1, 10)} "\""
      {Node " (1, 17) - (1, 18)} "\""
    {Node '\n' (1, 18) - (4, 0)} "\n\n\n"
  {Node struct_specifier (4, 0) - (4, 13)}
    {Node struct (4, 0) - (4, 6)} "struct"
    {Node type_identifier (4, 7) - (4, 10)} "Bar"
    {Node field_declaration_list (4, 11) - (4, 13)}
      {Node { (4, 11) - (4, 12)} "{"
      {Node } (4, 12) - (4, 13)} "}"
  {Node ; (4, 13) - (4, 14)} ";"

Note that the second preproc_include looks like it includes all the trailing newlines.

Wilfred added a commit to Wilfred/difftastic that referenced this issue Mar 28, 2022
These are from the preprocessor grammar rules, but they're not useful
for difftastic.

Reported upstream: tree-sitter/tree-sitter-c#97

Closes #180
@maxbrunsfeld
Copy link
Contributor

I agree; it'd be better to not have the trailing newline as part of the node.

@amaanq amaanq mentioned this issue Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants