Skip to content

Commit

Permalink
[c] Fix for #3601 -- fix parsing of all preprocessor directives (#3608)
Browse files Browse the repository at this point in the history
* Fix for #3601

* Add test of preprocessor directives.
  • Loading branch information
kaby76 authored Jul 15, 2023
1 parent bca917e commit 3f44239
Show file tree
Hide file tree
Showing 2 changed files with 1,251 additions and 31 deletions.
39 changes: 8 additions & 31 deletions c/C.g4
Original file line number Diff line number Diff line change
Expand Up @@ -847,15 +847,10 @@ SChar
| '\\\r\n' // Added line
;

ComplexDefine
: '#' Whitespace? 'define' ~[#\r\n]*
-> skip
;
MultiLineMacro:
'#' (~[\n]*? '\\' '\r'? '\n')+ ~ [\n]+ -> channel (HIDDEN);

IncludeDirective
: '#' Whitespace? 'include' Whitespace? ('"' ~[\r\n]* '"' | '<' ~[\r\n]* '>' ) Whitespace? Newline
-> skip
;
Directive: '#' ~ [\n]* -> channel (HIDDEN);

// ignore the following asm blocks:
/*
Expand All @@ -866,44 +861,26 @@ IncludeDirective
*/
AsmBlock
: 'asm' ~'{'* '{' ~'}'* '}'
-> skip
;

// ignore the lines generated by c preprocessor
// sample line : '#line 1 "/home/dm/files/dk1.h" 1'
LineAfterPreprocessing
: '#line' Whitespace* ~[\r\n]*
-> skip
;

LineDirective
: '#' Whitespace? DecimalConstant Whitespace? StringLiteral ~[\r\n]*
-> skip
;

PragmaDirective
: '#' Whitespace? 'pragma' Whitespace ~[\r\n]*
-> skip
-> channel(HIDDEN)
;

Whitespace
: [ \t]+
-> skip
: [ \t]+ -> channel(HIDDEN)
;

Newline
: ( '\r' '\n'?
| '\n'
)
-> skip
-> channel(HIDDEN)
;

BlockComment
: '/*' .*? '*/'
-> skip
-> channel(HIDDEN)
;

LineComment
: '//' ~[\r\n]*
-> skip
-> channel(HIDDEN)
;
Loading

0 comments on commit 3f44239

Please sign in to comment.