Giter Site home page Giter Site logo

cocci-syntax's People

Contributors

ahf avatar jajajasalu2 avatar mcgrof avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

cocci-syntax's Issues

Block comments /* ... */ do not highlight.

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);
}

Does not support `typedef` as a keyword.

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;

Multiple @ in a transformation line are confused as the start of a new metavariable declaration

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):
Current appearance

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:

Corrected appearance

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.