On Mon, Feb 7, 2011 at 12:17, SF Markus Elfring
<[email protected]> wrote:

> I have got the impression that there is a need to clarify the use of the
> choice operator a bit more because there are three (programming) languages
> involved at least which use the vertical line character (|) in a similar
> way.
> 1. Objective Caml
>   - pattern-matching feature in the core
>   - Str module: "Alternative"

Everything here is to the best of my knowledge:

The only way you can get access to Ocaml from Coccinelle is to use the
Ocaml-scripting feature of SmPL. That is, if you can't come up with a
solution in SmPL alone, you can write a (turing complete) program in
Ocaml to help guide SmPL in its transformations. The other option is
to use Python scripting for the same transformations, for which there
is also support.

The new disjunctive identifier feature is orthogonal to this. I hope
this clarifies its use in that respect.

> 2. SmPL: disjunction / OR
>   Can this technique also be applied for the source code filtering of string
> literal assignments?

No. If you take a look at the altered grammar,

https://github.com/coccinelle/coccinelle/commit/d3f655c619238baba11f20bc9f55769e66d3e428#diff-28

you can see that it has no reference inside string literal constants,
so it can't affect them. In fact, it looks like a string is a constant
element in the grammar of Coccinelle. Thus, we can change a string
"aaa" to a string "bbb", but there is no way to "look inside the
literal" and make transformations there from SmPL alone.

If you want to change string literals do the following: You have to
use the Ocaml/Python scripting feature to grab strings you are
interested in and then write a program in Ocaml or Python which makes
the necessary adjustments of your choice. Unless you desire to use
SmPL to constrain which functions to alter, it may be simpler and
easier to hook into the syntax-highlighter of an editor like Emacs and
then alter the code there.

I am very happy with the flyspell-prog-mode of Emacs for instance,

http://www.gnu.org/software/emacs/manual/html_node/emacs/Spelling.html

which use the syntax highlighter to find string literals and comments
and run a spelling check on those. It is definitely possible to do the
same for other kinds of substitutions.

As for comments, Coccinelle leaves them alone. You need to find
another tool to handle these.

>   How is it supported to patch special places including whitespace
> characters?

Luckily identifiers in C are not allowed to have whitespace in them,
so the ability to define disjunctive identifiers do not run into this
kind of trouble.

I can at best only guess at how spatch implements disjunctive
identifiers, but it looks to me as if you can use a variant of a
distributive law to expand a rule containing disj_ident's into a set
of rules which do not. Naturally, the danger here is rule explosion
and rule dependency, but I hardly think that is a problem to handle.

> 3. Regex
>   I am used to the term "alternation" here.

This is yet another use of the name. It is orthogonal to the other
uses and should be discriminated as such. There is no direct
resemblance between the alteration operator of regular expression and
the disjunctive identifier introduced in Coccinelle. If you squint
your eyes enough however, they are both similar in a sense to a
"Logical Disjunction" from first order logic, which may confuse. In
fact the disjunctive alteration permeates a lot of computing in subtly
different ways wearing different disguises.


-- 
J.
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to