User: Password:
|
|
Subscribe / Log in / New account

Regular Expressions Plus?

Regular Expressions Plus?

Posted Feb 1, 2009 1:52 UTC (Sun) by ldo (guest, #40946)
Parent article: Semantic patching with Coccinelle

Instead of a bunch of language-specific tools, how about a general tool that can do search/replace on syntactic constructs? Sort of the next step beyond regular expressions?

Is this a job for a packrat parser?


(Log in to post comments)

Regular Expressions Plus?

Posted Feb 2, 2009 0:30 UTC (Mon) by padator (guest, #56235) [Link]

I guess the next step beyond regular expressions are grammars, and
generic tools using grammars as parameters takes time to implement
and are not always useful.You have to know more than just the
syntactic structure of a programming language to make something interesting.
Emacs/Eclipse knows about the grammar of many programming languages.

Moreover, Coccinelle is not just a search/replace of syntactic constructs.
You have expression, function, and statement metavariables allowing
to match and move code and you can specify constraints about the
context of those entities.As val said:
"can make a particular change only in functions which are assigned to a function pointer in a particular type of array — say, the create member of struct inode_operations." You need a way to specify such constraint.
I don't really understand how a packrat parser would help for that ...

Re: Regular Expressions Plus?

Posted Feb 2, 2009 1:34 UTC (Mon) by ldo (guest, #40946) [Link]

padator wrote:

Moreover, Coccinelle is not just a search/replace of syntactic constructs. You have expression, function, and statement metavariables allowing to match and move code and you can specify constraints about the context of those entities.

Yes, but I’m pretty sure that those constraints are all, in principle, expressible using well-known techniques like two-level grammars and attribute grammars.

I’m not saying it’s a simple thing to do, but nevertheless it seems useful to have such prebuilt grammars for different languages, working with a common core of code, rather than writing different code for different languages.

Just a thought.


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds