Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
87 lines (68 sloc) 1.78 KB
% Overrides to preserve comments in C++\% Jim Cordy, March 2001
% Note that these overrides are an approximation -
% only the most common placements of C++ comments are allowed.
% Properly handling arbitrarily placed comments requires
% a robust grammar of somewhat greater sophistication.
% Can have comments as statements
redefine statement
...
| [comment_NL]
end redefine
% Can have comments as declarations
redefine declaration
...
| [comment_NL]
end redefine
redefine member_declaration
...
| [comment_NL]
end redefine
% Can have comments before initial values ...
redefine initializer
[repeat comment_NL] ...
end redefine
% ... or before =initializers
redefine initialization
[repeat comment_NL] ...
end redefine
% Can have comments before formal parameters ...
redefine argument_declaration
[repeat comment_NL] ...
end redefine
% ... or after formal parameters ...
redefine argument_declaration
... [repeat comment_NL]
end redefine
% ... or after a parameter list
redefine argument_declaration_list
... [repeat comment_NL]
end redefine
% Can have comments after an if condition or switch selector
redefine if_statement
'if ( [expression] ) [repeat comment_NL]
[statement] [opt else_statement]
end redefine
redefine switch_statement
'switch ( [expression] ) [repeat comment_NL]
[statement]
end redefine
% Can have comments on a block
redefine compound_statement
[repeat comment_NL] ...
end redefine
% Can have comments on a preprocessor statement
redefine preprocessor
[EX] '#endif [opt comment_NL] [NL]
| ...
end redefine
redefine preprocessor
... [opt comment_NL]
end redefine
% Can have comments before an expression
redefine expression
[repeat comment_NL] ...
end redefine
% Need newlines after comments
define comment_NL
[comment] [NL]
end define