Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JonathonReinhart opened this issue Dec 10, 2022 · 2 comments

Comments

@JonathonReinhart
Copy link

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.

@JonathonReinhart
Copy link
Author

BTW as to what GitHub uses, I followed this trail:

It looks like their definition does indeed anchor the metavariables @ at the beginning of the line:

	# Metavariables for transformations
	metavariables:
		name:  "meta.diff.header.metavariables.smpl"
		begin: "^(@).*(@)\\s*$"
		end:   "^(@@)"

Also worth noting that they do allow an @ in the rule name, where you exclude @.

@ahf
Copy link
Owner

ahf commented Dec 10, 2022

Nice catch, I agree we should get this fixed. Would you be up for creating a pull request with your suggested change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants