newbie: how to highlight function names ?

All questions regarding lexer highlighting schemes are discussed here...
Locked
runsun
Posts: 15
Joined: 16.12.2015 01:43

newbie: how to highlight function names ?

Post by runsun »

How do I set up lexer to highlight function name? The code looks like:

Code: Select all

function asc(c, n = 0) = 
(     // some text
      c == chr(n) ? n : asc(c, n + 1)
);
I want to highlight the word "asc".
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

Need
-create parser
-set its regex to "any word after word _function_"-- see regex syntax about "lookahead assertion"
-parser made. then set its style
runsun
Posts: 15
Joined: 16.12.2015 01:43

Post by runsun »

I did try that approach. The parser that I used:

Code: Select all

(?<=function )\w+(?= ?\()
It's been tested in https://regex101.com nicely but doesn't seem to work in synwrite.

The detailed steps I tried:

1) Create a new lexer
2) Copy and paste the example code to the example code box
3) Create a parser named "p_func" with the above regex
4) Create a style named "s_func" and set background
5) Link s_func to p_func

Nothing happened. The following didn't match anything either:

Code: Select all

(?<=function )\w+
function \w+
(?<=function ).*
The following two match something:

Code: Select all

function .*  ==> "function asc(c, n = 0) = "
function .*(?=\()  ==> "function asc"
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

It works
(?<=function\s+)\w+

I test on new lexer
runsun
Posts: 15
Joined: 16.12.2015 01:43

Post by runsun »

Thx a lot, Alexey. I missed the \s.

Btw, thx for your effort on this wonderful editor. Being using Notepad++ for years, only recently I found that SynWrite is much more powerful in the lexer feature. Will spend more time trying out other features. Thx.
Locked