Skip to content

Commit 333b098

Browse files
committed
refactor(c): modify macro declaration in C.g4 #24
Refactor the macro declaration in C.g4 to improve readability and maintainability. The `defineMacro` rule is now split into three separate rules: `macroAssignDeclaration`, `macroAliasDeclaration`, and `macroStructureDeclaration`. The `macroStatementDeclaration` rule now accepts `macroFunctionExpression` as an optional argument.
1 parent 6f160bb commit 333b098

File tree

1 file changed

+9
-5
lines changed
  • chapi-ast-c/src/main/antlr

1 file changed

+9
-5
lines changed

Diff for: chapi-ast-c/src/main/antlr/C.g4

+9-5
Original file line numberDiff line numberDiff line change
@@ -496,15 +496,20 @@ macroStatement
496496
// : include (StringLiteral | Identifier | ('<' includeIdentifier '>' )) #includeDeclaration
497497
// | ('ifdef' | 'ifndef' | 'if') Identifier statement* ('#' 'else' statement*)? '#' 'endif'
498498
// #ifdefDeclaration
499-
// | 'define' Identifier expressionStatement? #macroAssignDeclaration
500-
// | 'define' Identifier postixCall Identifier postixCall #macroAliasDeclaration
501-
// | 'define' Identifier structOrUnionSpecifier #macroStructureDeclaration
499+
// | 'define' Identifier defineMacro #defineDeclaration
502500
//// | macroKeywords (assignmentExpression)*
503501
//// ('#' macroKeywords)? identifierList? #macroDefineDeclaration
504502
// | '#'? Identifier #macroCastDeclaration
505-
// | macroKeywords assignmentExpression? #macroStatementDeclaration
503+
// | macroKeywords macroFunctionExpression? #macroStatementDeclaration
506504
// ;
507505
//
506+
//defineMacro
507+
// : expressionStatement? #macroAssignDeclaration
508+
// | postixCall Identifier postixCall #macroAliasDeclaration
509+
// | structOrUnionSpecifier #macroStructureDeclaration
510+
// ;
511+
//
512+
//
508513
//macroFunctionExpression
509514
// : Identifier
510515
// | Identifier '(' ( parameterTypeList| (macroType (',' macroType)*) ) ')'
@@ -516,7 +521,6 @@ macroStatement
516521
// | expressionStatement
517522
// ;
518523
//
519-
//
520524
//macroKeywords
521525
// : 'if' | 'undef' | 'else' | 'pragma' | 'endif' | 'ifdef' | 'ifndef' | 'elif' | 'define' | 'ifndef' | 'error'
522526
// ;

0 commit comments

Comments
 (0)