I'm trying to define the syntax highlighting regular expression for a function definition for CodeMirror using the simple mode plugin. I found this example in the docs:

  {
   regex: /(function)(\s+)([a-z$][\w$]*)/,
   token: ["keyword", null, "variable-2"]
  }

which works fine for the syntax below

enter image description here

but in my case, I am looking for an expression that would manage to format foobar(arg1, arg2, ...) (without function). Simply rewriting the definition to

  {
   regex: /(\s+)([a-z$][\w$]*)/,
   token: [null, "variable-2"]
  }

does not seem to work and produces this syntax highlighting:

enter image description here

How can I obtain the syntax highlighting without the "function" keyword?

Update

As per @Wiktor Stribi┼╝ew's comment I tried:

{
  regex: /(\w+\s*\(|\G(?!^)\s*,)\s*([a-z$][\w$]*)/,
  token: ["variable-2", null]
}

I had to swap the token elements as otherwise the function name wouldn't have been coloured. The question is now, how do I get the first argument (of the function which is what I am trying to parse) to be ignored, so it will be coloured by one of the subsequent rules? In the example below, var1 should be coloured just like other standard variables such as xyz and abc.

enter image description here

0 Answers