Rehx.hx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package lua.lib.lpeg;
  2. import lua.lib.lpeg.Pattern;
  3. import lua.lib.lpeg.Pattern.*;
  4. import lua.lib.lpeg.Re;
  5. import lua.lib.lpeg.Re.S;
  6. class Rehx {
  7. public static function compile(str : String, ?def : Dynamic) : Pattern {
  8. return null;
  9. }
  10. public static function match(subject : String, pattern : Pattern, ?index : Int) : String {
  11. return Re.match(subject, pattern, index);
  12. }
  13. public static function find(subject : String, pattern : Pattern, ?index : Int) : Int {
  14. return Re.find(subject, pattern, index);
  15. }
  16. public static function gsub(subject : String, pattern : Pattern, replace : String) : String {
  17. return Re.gsub(subject, pattern, replace);
  18. }
  19. public static function updatelocale() : Void {
  20. return Re.updatelocale();
  21. }
  22. var exp = P([
  23. "__name__" => "Exp",
  24. "Exp" => S + ( V("Grammar") | Cf(V("Seq") + ("/" + S + V("Seq")) * 0, mt.__add) ),
  25. "Seq" => Cf(Cc(P("")) * V("Prefix")^0 , mt.__mul) * (seq_follow.length + patt_error),
  26. "Prefix" => "&" * S * V("Prefix") / mt.__len
  27. + "!" * S * V("Prefix") / mt.__unm
  28. + V("Suffix"),
  29. "Suffix" => Cf(V("Primary") * S *
  30. ( ( P("+") * Cc(1, mt.__pow)
  31. + P("*") * Cc(0, mt.__pow)
  32. + P("?") * Cc(-1, mt.__pow)
  33. + "^" * ( Cg(num * m.Cc(mult))
  34. + Cg(C(S("+-") * R("09")^1) * Cc(mt.__pow))
  35. )
  36. + "->" * S * ( Cg((String + num) * Cc(mt.__div))
  37. + P("{}") * Cc(nil, Ct)
  38. + Cg(Def / getdef * Cc(mt.__div))
  39. )
  40. + "=>" * S * Cg(Def / getdef * Cc(Cmt))
  41. ) * S
  42. )^0, function (a,b,f) return f(a,b) ),
  43. "Primary" => "(" * V("Exp") * ")"
  44. + String / P
  45. + Class
  46. + defined
  47. + "{:" * (name * ":" + Cc(null)) * V("Exp") * ":}" /
  48. function (n, p) return Cg(p, n)
  49. + "=" * name / function (n) return Cmt(Cb(n), equalcap)
  50. + P("{}") / Cp
  51. + "{~" * m.V("Exp") * "~}" / Cs
  52. + "{|" * m.V("Exp") * "|}" / Ct
  53. + "{" * m.V("Exp") * "}" / C
  54. + P(".") * Cc(any)
  55. + (name * -arrow + "<" * name * ">") * Cb("G") / NT,
  56. "Definition" => name * arrow * V("Exp"),
  57. "Grammar" => Cg(Cc(true), "G") *
  58. Cf(V("Definition") / firstdef * Cg(V("Definition"))^0,
  59. adddef) / P
  60. ]);
  61. }