lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


hi from noob here :o)

I'm in Lua exploration, and I want to use its pattern matching.
Basically I read strings form a file and use that has pattern to scan program code...

so here my suggestion  ...

Can we have a  "%m"  symbol  representing lua  "magic" characters set ?
basically   this   "^$()%.[]*+-?"

so it will be more nice to scan my source file and put exception characters in it.
and  it will help writing more nice pattern when using in complex pattern

here a working example

s = "bla = bla(a[1]);"
for ss in s:gmatch("(%m)") do
   print(ss)
end



I hacked   lstrlib.c source file and changed 2 functions.

int ismagic(int c){
   return( strchr("^$()%.[]*+-?", c) ? 1 : 0 );
}

static int match_class (int c, int cl) {
  int res;
  switch (tolower(cl)) {
    case 'a' : res = isalpha(c); break;
    case 'c' : res = iscntrl(c); break;
    case 'd' : res = isdigit(c); break;
    case 'g' : res = isgraph(c); break;
    case 'l' : res = islower(c); break;
    case 'p' : res = ispunct(c); break;
    case 's' : res = isspace(c); break;
    case 'u' : res = isupper(c); break;
    case 'w' : res = isalnum(c); break;
    case 'x' : res = isxdigit(c); break;
    case 'm' : res = ismagic(c); break;
    case 'z' : res = (c == 0); break;  /* deprecated option */
    default: return (cl == c);
  }
  return (islower(cl) ? res : !res);
}