Suppose there's code like this:
ab cd
ef gh
ij kl
mn
I want to highlight all words at line head: ab
ef
ij
(yes, we have indentations) mn
, how to write the regex:
?
I had a try at http://ace.c9.io/tool/mode_creator.html but /^\s*/
/\n/
was not working as expected. How actually do they work?
Ace concatenates all the regular expressions in rules in a group. So if you have a group like
[{token: .., regex: "regex1"}, {token: .., regex: /regex2/}, {defaultToken: ..}]
Resulting regular expression will be
/(regex1)(regex2)($)/
(see here) Every line in document is repeatedly matched to the resulting regex and for each match token with the type of corresponding rule is created. For unmatched text defaultToken is used.Since regular expressions are matched line by line
/\n/
in rules will not match anything.As for your first question I think
{token : "comment", regex : "^\\s*\\w+"}
should work.Here's my solution, I have to put
/^\s*/
beforeparameter
, and it works.Full code here: https://github.com/Cirru/ace/blob/master/lib/ace/mode/cirru_highlight_rules.js