I’m writing a new mode for the SAS language and it has a line comment structure that goes from * to ;. This comment style can’t span lines.
This regular expression correctly identifies all the comments in a block of code but I can’t figure out how to correctly return the comment style to the comment part
Here is the code I’m using to try and match the SAS code below.
if (stream.match(/(?:^|[;]\s*)(\*.*?)/)) {
alert(stream.current());
stream.skipTo(';');
return "comment";
}
Here is some example SAS code:
* this is a comment;
data a; * also a comment;
x*y; a third comment comment;
x**2;
* indented comment;
z * sqtr(y); / not a single line comment */
run;
@marijn,
Thanks for your note! I’m sure this is obvious to you, but I don’t see how I can align the stream with the last element of the array returned from stream.match(). I’ve tried various things but none have been successful.
Your help is greatly appreciated
var result;
if (result=stream.match(/(?:^|[;]\s*)(\*.*?);/,false)) {
console.log(result[result.length-1]);
//align stream with result[result.length-1]
stream.skipTo(';');
return 'comment';
}
I couldn’t get stream.match to work properly so I used the following code which works fine but you could show me how to properly implement stream.match I would appreciate it.
// Match all line comments.
var myString = stream.string;
var myRegexp = /(?:^\s*|[;]\s*)(\*.*?);/ig;
var match = myRegexp.exec(myString);
if (match!==null){
if (match.index===0 && (stream.column()!==(match.index+match[0].length-1)) ){
stream.backUp(stream.column());
stream.column();
stream.skipTo(';');
return 'comment';
}
// the ';' triggers the match so move one past it to start
// the comment block that is why match.index+1
else if (match.index+1 < stream.column() && stream.column()< match.index+match[0].length-1) {
stream.backUp(stream.column()-match.index-1);
stream.skipTo(';');
return 'comment';
}
}