diff --git a/spec/fixtures/corpus/c/declarations.txt b/spec/fixtures/corpus/c/declarations.txt index 2445d2e6..358beb06 100644 --- a/spec/fixtures/corpus/c/declarations.txt +++ b/spec/fixtures/corpus/c/declarations.txt @@ -76,3 +76,43 @@ int main() { (expression_statement (call_expression (identifier) (math_expression (identifier) (identifier))))))) + +========================================== +function-like macros that produce types +========================================== + +GIT_INLINE(int) x = 5; + +--- + +(translation_unit (declaration + (macro_type (identifier) (identifier)) + (identifier) + (initializer (number)))) + +============================================ +3-way ambiguities (regression) +============================================ + +int main() { + /* + * Could be either: + * - function call + * - declaration w/ parenthesized declarator + * - declaration w/ macro type, no declarator + */ + ABC(d); + + efg hij; +} + +--- + +(translation_unit + (function_definition + (identifier) + (function_declarator (identifier)) + (compound_statement + (comment) + (expression_statement (call_expression (identifier) (identifier))) + (declaration (identifier) (identifier))))) diff --git a/spec/fixtures/corpus/cpp/statements.txt b/spec/fixtures/corpus/cpp/statements.txt index 90a08cbd..04211929 100644 --- a/spec/fixtures/corpus/cpp/statements.txt +++ b/spec/fixtures/corpus/cpp/statements.txt @@ -36,7 +36,7 @@ template function / relational expression ambiguities int main() { someVariable < someValue > 0.0; - someTemplate(y); + someTemplate(0, 0); } --- @@ -52,7 +52,7 @@ int main() { (expression_statement (call_expression (template_call (identifier) (type_id (type_specifier (identifier)))) - (identifier))))))) + (number) (number))))))) ================================================== template class / relational expression ambiguities diff --git a/src/runtime/parser.c b/src/runtime/parser.c index 5cab589f..0ba3f90a 100644 --- a/src/runtime/parser.c +++ b/src/runtime/parser.c @@ -20,6 +20,12 @@ #define SYM_NAME(sym) self->language->symbol_names[sym] +typedef enum { + ConsumeResultShifted, + ConsumeResultRemoved, + ConsumeResultFinished +} ConsumeResult; + /* * Private */ @@ -139,13 +145,16 @@ static void ts_parser__get_next_lookahead(TSParser *self) { * Parse Actions */ -static void ts_parser__shift(TSParser *self, int head, TSStateId parse_state) { - ts_stack_push(self->stack, head, parse_state, self->lookahead); +static ConsumeResult ts_parser__shift(TSParser *self, int head, TSStateId parse_state) { + if (ts_stack_push(self->stack, head, parse_state, self->lookahead)) + return ConsumeResultRemoved; + else + return ConsumeResultShifted; } -static void ts_parser__shift_extra(TSParser *self, int head, TSStateId state) { +static bool ts_parser__shift_extra(TSParser *self, int head, TSStateId state) { ts_tree_set_extra(self->lookahead); - ts_parser__shift(self, head, state); + return ts_parser__shift(self, head, state); } static TSTree *ts_parser__reduce(TSParser *self, int head, TSSymbol symbol, @@ -288,12 +297,6 @@ static TSTree *ts_parser__finish(TSParser *self) { return root; } -typedef enum { - ConsumeResultShifted, - ConsumeResultRemoved, - ConsumeResultFinished -} ConsumeResult; - /* * Continue performing parse actions for the given head until the current * lookahead symbol is consumed. @@ -345,13 +348,11 @@ static ConsumeResult ts_parser__consume_lookahead(TSParser *self, int head) { case TSParseActionTypeShift: DEBUG("shift state:%u", action.data.to_state); - ts_parser__shift(self, current_head, action.data.to_state); - return ConsumeResultShifted; + return ts_parser__shift(self, current_head, action.data.to_state); case TSParseActionTypeShiftExtra: DEBUG("shift_extra"); - ts_parser__shift_extra(self, current_head, state); - return ConsumeResultShifted; + return ts_parser__shift_extra(self, current_head, state); case TSParseActionTypeReduce: DEBUG("reduce sym:%s, child_count:%u", SYM_NAME(action.data.symbol),