Dialect policies do not work very well in cccc.g
With the fixes below Pro*C and MFC are better handled
Now we have 4 dialect options
ignore : skip a word
start_skipping ...stop_skipping : skip a block, a
keyword on 1st line a keyword on last line
skip_line : skip
line containing a keyword
skip_stmt : skip
statement (until ';') begin with a keyword
for example if this is added to your.opt file:
;;Pro*C embedded SQL
;; looks like
;; EXEC SQL UPDATE ARM43_OD_PRODUIT_SERV
;; SET ARM43ID_TPS_FIN = NULL WHERE
ARM43ID_TPS_FIN = 0;
CCCC_FileExt@.pc@c++.ansi@
CCCC_Dialect@c++.pc@EXEC@skip_stmt@
;;MFC
CCCC_Dialect@c++.mfc@ON_WM_PAINT@skip_line@
CCCC_Dialect@c++.mfc@DECLARE_MESSAGE_MAP@skip_l
ine@
CCCC_Dialect@c++.mfc@DECLARE_DISPATCH_MAP@skip_
line@
CCCC_Dialect@c++.stl@__STL_BEGIN_NAMESPACE@ignor
e@
CCCC_Dialect@c++.stl@__STL_END_NAMESPACE@ignore
@
CCCC_Dialect@c++.mfc@BEGIN_EVENT_MAP@start_skippi
ng@
CCCC_Dialect@c++.mfc@END_EVENT_MAP@stop_skipping
@
Pro*C and some MFC constructs are handled.
first fix :about line ~74
#token UNIX_NL "\n" << endOfLine(*this);
>>
/* augment dialect policies -- M.H added */
#lexclass SKIP_STMT
#token SKCOLON ";" << skip();mode(START); >>
#token SKANYTHING "~[; \t\n]" << skip();more();>>
#token SKNL "\n" << skip();endOfLine(*this);>>
#token SKBLANK "[ \t]+" << skip(); >>
#lexclass START
#lexclass SKIP_BLOCK
#token SK_ANY "[a-zA-Z0-9_]*"
<<
std::string treatment =
CCCC_Options::dialectKeywordPolicy
(parse_language,lextext());
if ( treatment != "stop_skipping" ) {
skip();
}
else {
mode(COMMENT_LINE);skip();
}
>>
#lexclass START
second fix at about line ~342
/* identifiers */
#token IDENTIFIER "[A-Za-z_][A-Za-z_0-9]*"
<<
// Check whether there are any dialect-
specific rules
// about the current token.
std::string treatment =
CCCC_Options::dialectKeywordPolicy
(parse_language,lextext());
std::string toktext=lextext();
if( treatment == "ignore" )
{
skip();
//std::cout << toktext << std::endl <<" :
ignore" << std::endl;
}
// Ultimately, the next two cases will need to
be handled
// using a #lexclass or something similar, for
the moment
// we just try to skip the tokens themselves.
else if ( treatment == "start_skipping" )
{
mode(SKIP_BLOCK);skip();
}
else if ( treatment == "stop_skipping" )
{
skip(); mode(COMMENT_LINE);//gobble end
of line M.H.
}
else if ( treatment == "skip_line" )//M.H added
{
mode(COMMENT_LINE);skip();
//std::cout << "skip_line" << std::endl;
}
else if ( treatment == "skip_stmt" )//M.H added
{
mode(SKIP_STMT);skip();
//std::cout << "skip_stmt" << std::endl;
}
>>
last fix at about line 440 in class CParser
public:
void init(const string& filename, const string& language)
{
pu=ParseUtility::currentInstance();
ps=ParseStore::currentInstance();
parse_language=language;
ANTLRParser::init();
//parse_language=language;//move above
M.H.1st otherwise time init not to language
}
Enjoy.
M.H.