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

ERROR when putting "else { }" block below "#else" #70

Open
botbotty opened this issue May 26, 2021 · 1 comment
Open

ERROR when putting "else { }" block below "#else" #70

botbotty opened this issue May 26, 2021 · 1 comment

Comments

@botbotty
Copy link

Versions:

tree-sitter-c@0.19.0
tree-sitter-cli@0.19.5

Code to reproduce this issue:

#include <stdio.h>
int main()
{
	int i;

	scanf("%d", &i);
	if (i > 10) {
		printf("big\n");
	}
#ifdef ONE_MORE_CHANCE
	else {
		printf("small\n");
	}
#endif

	return 0;
}

What tree-sitter parse gives:

(translation_unit [0, 0] - [17, 0]
  (preproc_include [0, 0] - [1, 0]
    path: (system_lib_string [0, 9] - [0, 18]))
  (function_definition [1, 0] - [16, 1]
    type: (primitive_type [1, 0] - [1, 3])
    declarator: (function_declarator [1, 4] - [1, 10]
      declarator: (identifier [1, 4] - [1, 8])
      parameters: (parameter_list [1, 8] - [1, 10]))
    body: (compound_statement [2, 0] - [16, 1]
      (declaration [3, 1] - [3, 7]
        type: (primitive_type [3, 1] - [3, 4])
        declarator: (identifier [3, 5] - [3, 6]))
      (expression_statement [5, 1] - [5, 17]
        (call_expression [5, 1] - [5, 16]
          function: (identifier [5, 1] - [5, 6])
          arguments: (argument_list [5, 6] - [5, 16]
            (string_literal [5, 7] - [5, 11])
            (pointer_expression [5, 13] - [5, 15]
              argument: (identifier [5, 14] - [5, 15])))))
      (if_statement [6, 1] - [8, 2]
        condition: (parenthesized_expression [6, 4] - [6, 12]
          (binary_expression [6, 5] - [6, 11]
            left: (identifier [6, 5] - [6, 6])
            right: (number_literal [6, 9] - [6, 11])))
        consequence: (compound_statement [6, 13] - [8, 2]
          (expression_statement [7, 2] - [7, 18]
            (call_expression [7, 2] - [7, 17]
              function: (identifier [7, 2] - [7, 8])
              arguments: (argument_list [7, 8] - [7, 17]
                (string_literal [7, 9] - [7, 16]
                  (escape_sequence [7, 13] - [7, 15])))))))
      (preproc_ifdef [9, 0] - [13, 6]
        name: (identifier [9, 7] - [9, 22])
        (ERROR [10, 1] - [10, 5] <----------------------------------- ERROR HERE
          (identifier [10, 1] - [10, 5]))
        (compound_statement [10, 6] - [12, 2]
          (expression_statement [11, 2] - [11, 20]
            (call_expression [11, 2] - [11, 19]
              function: (identifier [11, 2] - [11, 8])
              arguments: (argument_list [11, 8] - [11, 19]
                (string_literal [11, 9] - [11, 18]
                  (escape_sequence [11, 15] - [11, 17])))))))
      (return_statement [15, 1] - [15, 10]
        (number_literal [15, 8] - [15, 9])))))
/tmp/test.c     0 ms    (ERROR [10, 1] - [10, 5])
@tristan957
Copy link

Just ran into this with some code that looks like:

	if (argc > 1 && strcmp(argv[1], "--check") == 0)
		BootstrapModeMain(argc, argv, true);
	else if (argc > 1 && strcmp(argv[1], "--boot") == 0)
		BootstrapModeMain(argc, argv, false);
#ifdef EXEC_BACKEND
	else if (argc > 1 && strncmp(argv[1], "--fork", 6) == 0)
		SubPostmasterMain(argc, argv);
#endif
	else if (argc > 1 && strcmp(argv[1], "--describe-config") == 0)
		GucInfoMain();
	else if (argc > 1 && strcmp(argv[1], "--single") == 0)
		PostgresSingleUserMain(argc, argv,
							   strdup(get_user_name_or_exit(progname)));
	else if (argc > 1 && strcmp(argv[1], "--wal-redo") == 0)
		CallExtMain("neon_walredo", "WalRedoMain", argc, argv, false);
	else if (argc > 1 && strcmp(argv[1], "--sync-safekeepers") == 0)
		CallExtMain("neon", "WalProposerSync", argc, argv, true);
	else
		PostmasterMain(argc, argv);

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

No branches or pull requests

2 participants