satya-das / cppparser

A library to parse C/C++ source as AST
MIT License
270 stars 33 forks source link

Static arrays initialization causes parse errors #18

Open litdarya opened 1 year ago

litdarya commented 1 year ago

There are some cases with initializing static arrays in sequences which the parser fails to process.

Example 1:

int main()
{
  int variable, array_one[100], array_two[500];
  return 0;
}

produces:

./cppparsertest -p failed_testcases/many_arrays.cpp 
Error: Unexpected '[', while in context=ctxGeneral(1), found at line#2
    int variable, array_one[100], array_two[

Example 2:

int main()
{
  int variable = 0, array[100];
  return 0;
}

produces:

./cppparsertest -p failed_testcases/one_array.cpp 
Error: Unexpected '[', while in context=ctxGeneral(1), found at line#2
    int variable=0, array[

At the same time it parses these examples:

int main()
{
  int variable_one = 0, variable_two = 1;
  return 0;
}
int main()
{
  int array_one[500], array_two[500];
  return 0;
}
satya-das commented 1 year ago

Thanks for reporting. I see the problem and can be fixed. I will tackle it soon after completion of the major refactoring I am doing as of now.

litdarya commented 1 year ago

Hello, @satya-das! Looks like I've fixed it, can I create MR?

satya-das commented 1 year ago

Hello, @satya-das! Looks like I've fixed it, can I create MR?

Please go ahead. And thanks for taking initiative. :)