-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
partially implemented string pattern functions (find,gmatch,gsub,match) #9
Comments
I added support for table.concat. There's a bug in your version (when sep is null in a javascript join, it is replaced with ", " not "" as in lua's table.concat), so it ended up a little different. I'm not quite ready to add partial support for the string functions. I should probably hammer out a real version at some point. |
no hurry, it wasn't meant as pull request, i just wanted to put it here so people running into them can find a workaround easier =) |
I've been busy on some functions to convert a pattern into a regular expression. Here is the code I have so far: rT = [];
rT["a"]="w";
rT["A"]="W";
rT["l"]="[a-z]";
rT["L"]="[^a-z]";
rT["u"]="[A-Z]";
rT["U"]="[^A-Z]";
rT["p"]="[\\.\\!\\?\\,\\;\\:\\'\\]";
rT["P"]="[^\\.\\!\\?\\,\\;\\:\\'\\]";
rT["s"]="[\\s\\f\\n\\t\\r\\v]";
rT["S"]="[\\s\\f\\n\\t\\r\\v]";
rT["w"]="[a-Z0-9]";
rT["W"]="[^a-Z0-9]";
rT["x"]="[a-fA-F0-9]";
rT["X"]="[^a-fA-F0-9]";
rT["z"]="\\0";
rT["Z"]="[^\\0]";
function toReg(match){
var pcmd = match[1];
if (rT[pcmd])
return "\\" + rT[pcmd];
else if (pcmd == "b"){
var a = match[2];
var b = match[3];
return "(" +a+ "[^" +a+b+ "]*" +b+ ")";
}
else
return "\\" + pcmd;
}
saveRegExp = /([\\\{\}\!])/g
luaPattern = /%b(.{2})|%(.)/g
function patToRegExp(pattern){
//Replace certain characters that could be interpreter wrongly by the JS RegExp engine
var regexp = pattern.replace(saveRegExp, "\\$1")
regexp = regexp.replace(luaPattern, toReg)
return regexp;
}
a = "The Game+yuo";
pattern = "([*%/%-+()<>=%[%]])";
regg = patToRegExp(pattern)
console.log(regg);
reg = new RegExp(regg, "g");
console.log(a.replace(reg, "-$1-")); There are still some bugs, but maybe you can use the idea as a starting point :) |
https://github.com/ghoulsblade/love-webplayer/blob/master/js/lua-parser-utils.js
include this file to add support for :
my implementation of them is only partial, it covers a lot of common usecases, but it isn't 100% compatible to native lua behavior.
The text was updated successfully, but these errors were encountered: