Skip to content

Commit

Permalink
Fixed some template identifier precedence
Browse files Browse the repository at this point in the history
  • Loading branch information
tsoj committed Dec 7, 2024
1 parent 01324f0 commit 97595e2
Show file tree
Hide file tree
Showing 4 changed files with 276 additions and 14 deletions.
3 changes: 2 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,8 @@ module.exports = grammar(CPP1, {
choice($.cpp2_non_template_identifier, $._cpp2_template_identifier),

_cpp2_template_identifier: ($) =>
seq($.cpp2_non_template_identifier, $.cpp2_template_call_arguments),
// dynamic precedence for preferring this to _cpp2_no_namespace_identifier
prec.dynamic(1, seq($.cpp2_non_template_identifier, $.cpp2_template_call_arguments)),

cpp2_non_template_identifier: ($) =>
choice($.cpp2_operator_keyword, $.cpp2_ordinary_identifier),
Expand Down
26 changes: 15 additions & 11 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/parser.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

257 changes: 257 additions & 0 deletions test/corpus/template_precedence.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
===========================================================
unary operator
===========================================================

a: () = -a<int>(x);
a: () = a<int>(x);

-----------------------------------------------------------

(translation_unit
(cpp2_expression_declaration
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier)))
(cpp2_expression_definition
(cpp2_left_side_of_definition
(cpp2_expression
(cpp2_type
(cpp2_function_type
(cpp2_function_type_without_return_type)))))
(cpp2_expression
(cpp2_unary_expression
(cpp2_unary_prefix_expression
(cpp2_expression
(cpp2_function_call
(cpp2_expression
(cpp2_any_identifier
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier)))
(cpp2_template_call_arguments
(cpp2_comma_expressions
(cpp2_expression
(cpp2_keyword
(cpp2_primitive_type
(primitive_type))))))))
(cpp2_parentheses_expression
(cpp2_comma_expressions
(cpp2_expression
(cpp2_any_identifier
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier))))))))))))))
(cpp2_expression_declaration
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier)))
(cpp2_expression_definition
(cpp2_left_side_of_definition
(cpp2_expression
(cpp2_type
(cpp2_function_type
(cpp2_function_type_without_return_type)))))
(cpp2_expression
(cpp2_function_call
(cpp2_expression
(cpp2_any_identifier
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier)))
(cpp2_template_call_arguments
(cpp2_comma_expressions
(cpp2_expression
(cpp2_keyword
(cpp2_primitive_type
(primitive_type))))))))
(cpp2_parentheses_expression
(cpp2_comma_expressions
(cpp2_expression
(cpp2_any_identifier
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier))))))))))))

===========================================================
binary operator
===========================================================

a: () = a<int>(piece) - a<int>(Piece::pawn);
a: () = a<int>(piece) - (a<int>(Piece::pawn));
a: () = (a<int>(piece)) - a<int>(Piece::pawn);


-----------------------------------------------------------

(translation_unit
(cpp2_expression_declaration
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier)))
(cpp2_expression_definition
(cpp2_left_side_of_definition
(cpp2_expression
(cpp2_type
(cpp2_function_type
(cpp2_function_type_without_return_type)))))
(cpp2_expression
(cpp2_binary_expression
(cpp2_expression
(cpp2_function_call
(cpp2_expression
(cpp2_any_identifier
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier)))
(cpp2_template_call_arguments
(cpp2_comma_expressions
(cpp2_expression
(cpp2_keyword
(cpp2_primitive_type
(primitive_type))))))))
(cpp2_parentheses_expression
(cpp2_comma_expressions
(cpp2_expression
(cpp2_any_identifier
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier)))))))))
(cpp2_expression
(cpp2_function_call
(cpp2_expression
(cpp2_any_identifier
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier)))
(cpp2_template_call_arguments
(cpp2_comma_expressions
(cpp2_expression
(cpp2_keyword
(cpp2_primitive_type
(primitive_type))))))))
(cpp2_parentheses_expression
(cpp2_comma_expressions
(cpp2_expression
(cpp2_any_identifier
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier)))
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier)))))))))))))
(cpp2_expression_declaration
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier)))
(cpp2_expression_definition
(cpp2_left_side_of_definition
(cpp2_expression
(cpp2_type
(cpp2_function_type
(cpp2_function_type_without_return_type)))))
(cpp2_expression
(cpp2_binary_expression
(cpp2_expression
(cpp2_function_call
(cpp2_expression
(cpp2_any_identifier
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier)))
(cpp2_template_call_arguments
(cpp2_comma_expressions
(cpp2_expression
(cpp2_keyword
(cpp2_primitive_type
(primitive_type))))))))
(cpp2_parentheses_expression
(cpp2_comma_expressions
(cpp2_expression
(cpp2_any_identifier
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier)))))))))
(cpp2_expression
(cpp2_parentheses_expression
(cpp2_comma_expressions
(cpp2_expression
(cpp2_function_call
(cpp2_expression
(cpp2_any_identifier
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier)))
(cpp2_template_call_arguments
(cpp2_comma_expressions
(cpp2_expression
(cpp2_keyword
(cpp2_primitive_type
(primitive_type))))))))
(cpp2_parentheses_expression
(cpp2_comma_expressions
(cpp2_expression
(cpp2_any_identifier
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier)))
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier))))))))))))))))
(cpp2_expression_declaration
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier)))
(cpp2_expression_definition
(cpp2_left_side_of_definition
(cpp2_expression
(cpp2_type
(cpp2_function_type
(cpp2_function_type_without_return_type)))))
(cpp2_expression
(cpp2_binary_expression
(cpp2_expression
(cpp2_parentheses_expression
(cpp2_comma_expressions
(cpp2_expression
(cpp2_function_call
(cpp2_expression
(cpp2_any_identifier
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier)))
(cpp2_template_call_arguments
(cpp2_comma_expressions
(cpp2_expression
(cpp2_keyword
(cpp2_primitive_type
(primitive_type))))))))
(cpp2_parentheses_expression
(cpp2_comma_expressions
(cpp2_expression
(cpp2_any_identifier
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier))))))))))))
(cpp2_expression
(cpp2_function_call
(cpp2_expression
(cpp2_any_identifier
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier)))
(cpp2_template_call_arguments
(cpp2_comma_expressions
(cpp2_expression
(cpp2_keyword
(cpp2_primitive_type
(primitive_type))))))))
(cpp2_parentheses_expression
(cpp2_comma_expressions
(cpp2_expression
(cpp2_any_identifier
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier)))
(cpp2_non_template_identifier
(cpp2_ordinary_identifier
(identifier))))))))))))))

0 comments on commit 97595e2

Please sign in to comment.