From 799a3f68fcec2949bdf751fbd5584d7e22668bc8 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Tue, 30 Jan 2024 19:14:51 +0800 Subject: [PATCH] feat(chapi-ast-c): add support for additional macro keyword in C.g4 #24 Add support for the macro keyword 'ifdef' in the 'conditionalDeclaration' rule of the C.g4 file in chapi-ast-c/src/main/antlr. This allows for more comprehensive parsing of C code. --- chapi-ast-c/src/main/antlr/C.g4 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/chapi-ast-c/src/main/antlr/C.g4 b/chapi-ast-c/src/main/antlr/C.g4 index 6524a71e..07317e8a 100644 --- a/chapi-ast-c/src/main/antlr/C.g4 +++ b/chapi-ast-c/src/main/antlr/C.g4 @@ -40,10 +40,14 @@ compilationUnit oneLineMacroDeclaration : '#' include (StringLiteral | ('<' includeIdentifier '>' )) #includeDeclaration | '#' 'define' expression* #defineDeclaration - | '#'( 'if' | 'undef' | 'else' | 'pragma' | 'endif' ) expression* #conditionalDeclaration + | '#' macroKeywords expression* #conditionalDeclaration | Identifier postixCall? compoundStatement? #macroCall ; +macroKeywords + : 'if' | 'undef' | 'else' | 'pragma' | 'endif' | 'ifdef' + ; + MultiLineMacro : '#' (~[\n]*? '\\' '\r'? '\n')+ ~ [\n]+ -> channel (HIDDEN) ;