ahf / cocci-syntax Goto Github PK
View Code? Open in Web Editor NEWVim plug-in for Coccinelle.
Home Page: http://coccinelle.lip6.fr
Vim plug-in for Coccinelle.
Home Page: http://coccinelle.lip6.fr
Hello, thank you for writing this plugin!
It looks like the syntax highlight doesn't support /* ... */ as a comment. They can be used to comment cocci blocks.
Here's a big cocci block I'm working on to refactor xnec2c . The rest of the vim highlight works quite well except for the commented @ add_copy @
section:
// Match the variable definition:
@ struct_name @
typedef cm_t, cmag_t, crnt_t, ct1m_t, ct2m_t, data_t, dataj_t, fpat_t,
ggrid_t, gnd_t, gwav_t, impedance_data_t, incom_t, matpar_t, near_field_t,
netcx_t, save_t, segj_t, smat_t, zload_t, vsorc_t;
type T = {cm_t, cmag_t, crnt_t, ct1m_t, ct2m_t, data_t, dataj_t, fpat_t,
ggrid_t, gnd_t, gwav_t, impedance_data_t, incom_t, matpar_t, near_field_t,
netcx_t, save_t, segj_t, smat_t, zload_t, vsorc_t};
identifier I;
@@
T I;
/*
// Add the 2nd copy
@ add_copy @
identifier struct_name.I;
type struct_name.T;
fresh identifier P = "prev_"##I;
@@
void diff_structures()
{
}
*/
// Add the compare_T() function call and compare_T function definition for each typedef:
@ r2 @
identifier struct_name.I;
type struct_name.T;
fresh identifier compare_FN = "compare_"##I;
fresh identifier print_FN = "print_"##I;
fresh identifier P = "prev_"##I;
@@
void diff_structures()
{
(
++T P;
)
(
++FN(&I, &P);
+
)
}
++void compare_FN(T *a, T *b){}
++void print_FN(T *a){}
// Match scalar types:
@ scalars @
type struct_name.T;
type scalar_T = {char, int, double, double complex};
identifier F;
@@
typedef struct
{
...
scalar_T F;
...
} T;
// Match ptrs:
@ ptrs @
type ptr_T;
identifier F;
type struct_name.T;
@@
typedef struct
{
...
ptr_T *F;
...
} T;
// Add the comparisons for scalars:
@ r3 @
identifier r2.compare_FN;
identifier struct_name.I;
identifier scalars.F;
@@
void compare_FN(...)
{
...
++ if (a->F != b->F) NOMATCH(a, b, I, F);
}
// Add the comparisons for ptrs:
@ r4 @
identifier r2.compare_FN;
identifier struct_name.I;
identifier ptrs.F;
@@
void compare_FN()
{
++ if (mem_bcmp(a->F, b->F)) NOMATCH(a, b, I, F);
}
ie:
typedef cm_t, cmag_t, crnt_t, ct1m_t, ct2m_t, data_t, dataj_t, fpat_t,
ggrid_t, gnd_t, gwav_t, impedance_data_t, incom_t, matpar_t, near_field_t,
netcx_t, save_t, segj_t, smat_t, zload_t, vsorc_t;
Sorry for the confusing title, I'm trying to use the terminology from the grammar.
An example:
// a metavariable declaration (or just rule)
@ rule @
expression x, y
position p1, p2
@@
// transformation section
// note there are two @ in this line
foo(x@p1, y@p2)
// another metavariable declaration
// cocci.vim doesn't recognize this as a CocciGroup region
@@
expression foo
@@
(Note that when writing this issue, I marked this code fence as cocci
, and whatever syntax highlighter GitHub uses seemed to highlight this correctly.)
As you can see in this image, cocci.vim
thinks that the two @
are part of a metavariable declaration (rule):
However, if we require that the metavariable declaration (rule) @
start at the beginning of the line...
diff --git a/syntax/cocci.vim b/syntax/cocci.vim
index 9bf7a98..b5bc2d9 100644
--- a/syntax/cocci.vim
+++ b/syntax/cocci.vim
@@ -14,7 +14,7 @@ syn keyword CocciKeywords statement function local list fresh position ide
syn keyword CocciKeywords declaration declarer attribute symbol format assignment contained
syn keyword CocciKeywords operator global field initializer initialiser iterator name contained
-syn region CocciGroup matchgroup=CocciGroupDelim start="@[^@]*@" end="@@" contains=CocciKeywords
+syn region CocciGroup matchgroup=CocciGroupDelim start="^@[^@]*@" end="^@@" contains=CocciKeywords
syn match CocciLineRemoved "^-.*"
syn match CocciLineAdded "^+.*"
...then everything looks fine:
It's not clear to me from looking at the grammar if the @
has to start at the beginning of a line (I've never been good wtih BNF). However, every Coccinelle example I've ever seen is as such.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.