Skip to content

Commit 419e8aa

Browse files
committed
Move define scoped class ParserUtil from regex/ParserUtil.hx to expr/ParserUtil.hx.
Add Util to bypass tinks macros.
1 parent 0b7aea4 commit 419e8aa

File tree

5 files changed

+63
-43
lines changed

5 files changed

+63
-43
lines changed

src/be/regex/ParserUtil.hx

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,8 @@
11
package be.regex;
22

3-
#if interp
4-
typedef ParserUtil = be.regex.std.ParserUtil;
3+
typedef ParserUtil =
4+
#if (interp || eval || macro)
5+
be.regex.std.ParserUtil
56
#else
6-
import uhx.sys.seri.Category;
7-
8-
#if (eval || macro)
9-
import be.regex.Define;
10-
import haxe.macro.Expr;
11-
import haxe.macro.Context;
12-
#end
13-
14-
import be.regex.RegexErrors;
15-
import uhx.sys.seri.Ranges;
16-
import be.regex.CodeUtil;
17-
import be.regex.RangeUtil;
18-
19-
class ParserUtil {
20-
21-
#if (eval || macro)
22-
private static var pythonStyle:Bool = Python; // \uHHHH or \UHHHHHHHH
23-
private static var perlStyle:Bool = Neko || Cpp || Php || Lua || Java; // \x{HHHH}
24-
private static var jsStyle:Bool = JavaScript || CSharp || Flash; // \uHHHH
25-
private static var onlyBMP:Bool = JavaScript || CSharp;
26-
#end
27-
28-
public macro static function pattern(s:String):ExprOf<String> {
29-
var pos = Context.currentPos();
30-
return macro @:pos(pos) $v{be.regex.std.ParserUtil.pattern(s, perlStyle, jsStyle, onlyBMP, pos)};
31-
}
32-
33-
public macro static function category(category:String):ExprOf<String> {
34-
var pos = Context.currentPos();
35-
return if (((JavaScript && category.length == 1) || !(NodeJS || (ES_ && ES_ > 5))) && (jsStyle || pythonStyle || Cpp)) {
36-
macro @:Disjunction $v{be.regex.std.ParserUtil.category(category, pythonStyle, perlStyle, jsStyle, onlyBMP, pos)};
37-
38-
} else {
39-
macro @:Atom $v{be.regex.std.ParserUtil.category(category, pythonStyle, perlStyle, jsStyle, onlyBMP, pos)};
40-
}
41-
}
42-
43-
}
44-
#end
7+
be.regex.expr.ParserUtil
8+
#end;

src/be/regex/expr/ParserUtil.hx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package be.regex.expr;
2+
3+
import uhx.sys.seri.Category;
4+
5+
#if (interp || eval || macro)
6+
import be.regex.Define;
7+
import haxe.macro.Expr;
8+
import haxe.macro.Context;
9+
#end
10+
11+
import be.regex.RegexErrors;
12+
import uhx.sys.seri.Ranges;
13+
import be.regex.CodeUtil;
14+
import be.regex.RangeUtil;
15+
16+
class ParserUtil {
17+
18+
#if (interp || eval || macro)
19+
private static var pythonStyle:Bool = Python; // \uHHHH or \UHHHHHHHH
20+
private static var perlStyle:Bool = Neko || Cpp || Php || Lua || Java; // \x{HHHH}
21+
private static var jsStyle:Bool = JavaScript || CSharp || Flash; // \uHHHH
22+
private static var onlyBMP:Bool = JavaScript || CSharp;
23+
#end
24+
25+
public macro static function pattern(s:String):ExprOf<String> {
26+
trace(s);
27+
var pos = Context.currentPos();
28+
return macro @:pos(pos) $v{be.regex.std.ParserUtil.pattern(s, perlStyle, jsStyle, onlyBMP, pos)};
29+
}
30+
31+
public macro static function category(category:String):ExprOf<String> {
32+
trace(category);
33+
var pos = Context.currentPos();
34+
return if (((JavaScript && category.length == 1) || !(NodeJS || (ES_ && ES_ > 5))) && (jsStyle || pythonStyle || Cpp)) {
35+
macro @:Disjunction $v{be.regex.std.ParserUtil.category(category, pythonStyle, perlStyle, jsStyle, onlyBMP, pos)};
36+
37+
} else {
38+
macro @:Atom $v{be.regex.std.ParserUtil.category(category, pythonStyle, perlStyle, jsStyle, onlyBMP, pos)};
39+
}
40+
}
41+
42+
}

src/be/regex/std/ParserUtil.hx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import be.regex.RegexErrors;
77
import uhx.sys.seri.Category;
88

99
typedef Pos =
10-
#if (macro || eval)
10+
#if (interp || eval || macro)
1111
haxe.macro.Expr.Position
1212
#else
1313
haxe.PosInfos
@@ -24,7 +24,7 @@ class ParserUtil {
2424
*/
2525

2626
private static function error(message:String, ?pos:Pos) {
27-
#if (macro || eval)
27+
#if (interp || eval || macro)
2828
haxe.macro.Context.error(message, pos);
2929
#else
3030
throw message;

test/be/regex/RegexSpec.hx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package be.regex;
22

3+
import be.regex.Util;
34
import be.Regex;
45
/**
56
Only the JavaScript implementation is
@@ -51,6 +52,8 @@ class RegexSpec {
5152
// a⁴ +
5253
trace( regexp.matched(0) );
5354

55+
trace( Util.bar() );
56+
5457
return asserts.done();
5558
}
5659

test/be/regex/Util.hx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package be.regex;
2+
3+
import be.Regex;
4+
5+
class Util {
6+
7+
public static macro function bar() {
8+
return macro $v{Regex.category('No')};
9+
}
10+
11+
}

0 commit comments

Comments
 (0)