|
|
|
@ -50,6 +50,10 @@ const ASSIGNMENT_OPERATORS = [ |
|
|
|
'xor_eq', |
|
|
|
]; |
|
|
|
|
|
|
|
const commaSep = C.commaSep; |
|
|
|
const commaSep1 = C.commaSep1; |
|
|
|
const preprocIf = C.preprocIf; |
|
|
|
|
|
|
|
module.exports = grammar(C, { |
|
|
|
name: 'cpp', |
|
|
|
|
|
|
|
@ -133,8 +137,12 @@ module.exports = grammar(C, { |
|
|
|
alias($.operator_cast_definition, $.function_definition), |
|
|
|
alias($.operator_cast_declaration, $.declaration), |
|
|
|
), |
|
|
|
|
|
|
|
_block_item: ($, original) => choice( |
|
|
|
...original.members.filter((member) => member.content?.name != '_old_style_function_definition'), |
|
|
|
...original.members.filter((member) => |
|
|
|
member.content?.name != '_old_style_function_definition' && |
|
|
|
!member.name.startsWith('preproc_if'), |
|
|
|
), |
|
|
|
$.namespace_definition, |
|
|
|
$.concept_definition, |
|
|
|
$.namespace_alias_definition, |
|
|
|
@ -144,11 +152,18 @@ module.exports = grammar(C, { |
|
|
|
$.consteval_block_declaration, |
|
|
|
$.template_declaration, |
|
|
|
$.template_instantiation, |
|
|
|
$.export_declaration, |
|
|
|
$.import_declaration, |
|
|
|
alias($.preproc_if_in_block, $.preproc_if), |
|
|
|
alias($.preproc_ifdef_in_block, $.preproc_ifdef), |
|
|
|
alias($.constructor_or_destructor_definition, $.function_definition), |
|
|
|
alias($.operator_cast_definition, $.function_definition), |
|
|
|
alias($.operator_cast_declaration, $.declaration), |
|
|
|
), |
|
|
|
|
|
|
|
...preprocIf('', $ => $._top_level_item), |
|
|
|
...preprocIf('_in_block', $ => $._block_item), |
|
|
|
|
|
|
|
// Types
|
|
|
|
|
|
|
|
placeholder_type_specifier: $ => prec(1, seq( |
|
|
|
@ -371,13 +386,12 @@ module.exports = grammar(C, { |
|
|
|
';', |
|
|
|
), |
|
|
|
|
|
|
|
export_declaration: $ => seq( |
|
|
|
export_declaration: $ => prec(1, seq( |
|
|
|
'export', |
|
|
|
choice($._block_item, seq('{', repeat($._block_item), '}')), |
|
|
|
), |
|
|
|
choice($._block_item, $.declaration_list), |
|
|
|
)), |
|
|
|
|
|
|
|
import_declaration: $ => seq( |
|
|
|
optional('export'), |
|
|
|
'import', |
|
|
|
choice( |
|
|
|
field('name', $.module_name), |
|
|
|
@ -1587,25 +1601,3 @@ module.exports = grammar(C, { |
|
|
|
_namespace_identifier: $ => alias($.identifier, $.namespace_identifier), |
|
|
|
}, |
|
|
|
}); |
|
|
|
|
|
|
|
/** |
|
|
|
* Creates a rule to optionally match one or more of the rules separated by a comma |
|
|
|
* |
|
|
|
* @param {Rule} rule |
|
|
|
* |
|
|
|
* @returns {ChoiceRule} |
|
|
|
*/ |
|
|
|
function commaSep(rule) { |
|
|
|
return optional(commaSep1(rule)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Creates a rule to match one or more of the rules separated by a comma |
|
|
|
* |
|
|
|
* @param {Rule} rule |
|
|
|
* |
|
|
|
* @returns {SeqRule} |
|
|
|
*/ |
|
|
|
function commaSep1(rule) { |
|
|
|
return seq(rule, repeat(seq(',', rule))); |
|
|
|
} |