Get row onMatch

67 views
Skip to first unread message

arun...@googlemail.com

unread,
Jul 22, 2021, 7:56:53 AMJul 22
to Ajax.org Cloud9 Editor (Ace)
Hello, 

After adding a rule can i get row where token have match?

no_regex: [
{
token : "support.function",
regex : "(myFunc)\\b",
next : "function_arguments",
                        onMatch: function(val, state, stack) {
                              //Is is possible to get row number where token exists??
                        }
},
]

Harutyun Amirjanyan

unread,
Jul 22, 2021, 8:37:33 AMJul 22
to ace-d...@googlegroups.com
No, because if the output of onmatch was different based on the row, the tokenizer would have to re-highlight the whole document after inserting a new line.
Why do you need to get the row number? there  may be some other workaround.

arun...@googlemail.com

unread,
Jul 22, 2021, 8:44:15 AMJul 22
to Ajax.org Cloud9 Editor (Ace)
Thanks for quick reply...

I need to store rows all rows where function is called. Example => foo1(arg1, arg2) or foo2(arg1)
Later when i write foo1 then i can check in which row was it declare.. and form there i can get some hints.. like arguments

arun...@googlemail.com

unread,
Jul 22, 2021, 8:50:56 AMJul 22
to Ajax.org Cloud9 Editor (Ace)
I was trying something like below. But it's not working... (Line number is away wrong)


editor.on("input", function(event, editor){
     Javascript_Rule_Current_Line = editor.session.bgTokenizer.currentLine;
});

//and in rule file
var Javascript_Stored_Tokens = {};

start: [
{
regex : "([\\n]*?)",
next : "no_regex",
onMatch: function(val, state, stack) {
Javascript_Rule_Current_Line++;
return "invisible.space";
}
}
],
no_regex: [
{
token : "support.function",
regex : "(prompt|confirm|setTimeout|clearTimeout|setInterval|clearInterval)\\b",
next : "function_arguments",
onMatch: function(val, state, stack) {
Javascript_Stored_Tokens[Javascript_Rule_Current_Line] = "KEYWORD"
return "support.function";
},
}
]


Harutyun Amirjanyan

unread,
Jul 22, 2021, 8:59:56 AMJul 22
to ace-d...@googlegroups.com
looks like onMatch actually get's a line parameter https://github.com/ajaxorg/ace/blob/v1.4.10/lib/ace/tokenizer.js#L279 though it is not a public api

But it is better to do this kind of processing in a separate pass, keeping completer and highlighting logic separate

arun...@googlemail.com

unread,
Jul 22, 2021, 9:02:49 AMJul 22
to Ajax.org Cloud9 Editor (Ace)
I tried 4th parameter but it is holding value (same as 1st parameter)

arun...@googlemail.com

unread,
Jul 22, 2021, 9:07:47 AMJul 22
to Ajax.org Cloud9 Editor (Ace)
{
token : "support.function",
regex : "(prompt|confirm|setTimeout|clearTimeout|setInterval|clearInterval)\\b",
next : "function_arguments",
onMatch: function(val, state, stack, line) {
console.log( val + " - " +  line); < They are same (token value)
return "support.function";
},
}

arun...@googlemail.com

unread,
Jul 22, 2021, 10:43:02 AMJul 22
to Ajax.org Cloud9 Editor (Ace)

Hello Amirj...

Can you please check and help me with this...
Am using 4.12 version (src-min-noconflict).

Am adding rules as below...

var rules = session.$mode.$highlightRules.getRules();
rules[key].unshift(MyRules);

// force recreation of tokenizer
session.$mode.$tokenizer = null;
session.bgTokenizer.setTokenizer(session.$mode.getTokenizer());
// force re-highlight whole document
session.bgTokenizer.start(0);

On Thursday, 22 July 2021 at 14:59:56 UTC+2 amirj...@gmail.com wrote:

arun...@googlemail.com

unread,
Jul 22, 2021, 3:55:06 PMJul 22
to Ajax.org Cloud9 Editor (Ace)
Hello,

I change the source code at mentioned line and it work :-)

appreciate your help.. thanks

On Thursday, 22 July 2021 at 14:59:56 UTC+2 amirj...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages