Julia Lawall <julia <at> diku.dk> writes:
> I ended up with the following regular expression:
>
> (letter | '$') (letter | digit | '$' | '~') *
> ("::" (letter | '$' | '~') (letter | digit | '$' | '~') *
> ('<' (letter | '$' | '~') (letter | digit | '$' | '~') * '>') ?) *
>
> This only allows the < and > at specific places.
I'm not sure that is quite right though. For a start, <...> parts are only
allowed inside of qualifying prefixes, whereas it seems to me that your regular
expression allows them everywhere except in the first prefix, and in addition,
'~' is only allowed as the first character of the actual name (just after the
last "::").
Thinking about it (sorry that I am only just starting that now!) the expressions
inside of the <...> are of course potentially much more complex. In fact they
are comma plus whitespace separated lists of types, which can recursively
include other types with <...> in them. That of course is no longer run of the
mill, and not handling that in the regex would not be a problem for most people.
Here is my next shot (not sure what sort of line continuation is needed, and ' '
should actually be generic whitespace):
let basetype = (letter | '$') (letter | digit | '$') *
('<' (letter | digit | '$' | ' ' | ',') * '>') ?)
let typelike = basetype ("::" basetype) *
let varlike = (typelike "::") ? (letter | '$' |'~') (letter | digit | '$') *
typelike describes C++ types, and varlike C++ variables.
I will give that a bit of testing when I have time (probably in the new year).
Regards,
Michael
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)