<commit_before>package python;


import haxe.macro.Expr;

import haxe.macro.Context;
#if macro
import haxe.macro.ExprTools;
#end
#if !macro

import python.lib.Types.PyIterator;
#end


class Macros {

	@:noUsing macro public static function importModule (module:String):haxe.macro.Expr {
		return macro untyped __python__($v{"import " + module});
	}

	@:noUsing macro public static function importAs (module:String, className : String):haxe.macro.Expr 
    {
        
        var n = className.split(".").join("_");

        var e = "import " + module + " as " + n;
        var e1 = "_hx_c."+n+" = "+n;


	    return macro{
            untyped __python__($v{e});
            untyped __python__($v{e1});
        }
    }

    
    @:noUsing macro public static function pyFor <T>(v:Expr, it:Expr, b:Expr):haxe.macro.Expr 
    {
        var id = switch (v.expr) {
            case EConst(CIdent(x)):x;
            case _ : Context.error("unexpected " + ExprTools.toString(v) + ": const ident expected", v.pos);
        }
        


        var res = macro @:pos(it.pos) {
            var $id = $it.getNativeIterator().__next__();
            $it;
            $b;
        }
        return macro (untyped __python_for__)($res);
    }

    @:noUsing macro public static function importFromAs (from:String, module:String, className : String):haxe.macro.Expr {
        
        var n = className.split(".").join("_");

        var e = "from " + from + " import " + module + " as " + n;
        var e1 = "_hx_c."+n+" = " + n;
	    return macro {
            untyped __python__($v{e});
            untyped __python__($v{e1});
        }
    }

    #if !macro macro #end public static function callNamed (e:Expr, args:Expr):haxe.macro.Expr {
        var fArgs = switch (Context.typeof(e)) {
            case TFun(args, ret): args;
            case _ : haxe.macro.Context.error("e must be of type function", e.pos);
        }
        switch (args.expr) {
            case EObjectDecl(fields):
                for (f in fields) {
                    var found = false;
                    for (a in fArgs) {
                        found = a.name == f.field;
                        if (found) break;
                    }
                    if (!found) {
                        haxe.macro.Context.error("field " + f.field + " is not a valid argument (valid names " + [for (a in fArgs) a.name].join(",") + ")", args.pos);   
                    }
                }
                // TODO check at least if fields are valid (maybe if types match);
            case _ : haxe.macro.Context.error("args must be an ObjectDeclaration like { name : 1 }", args.pos);
        }
        return macro @:pos(e.pos) untyped __named__($e, $args);
    }


}<commit_msg>minor cleanup<commit_after>package python;

#if macro
import haxe.macro.Expr;

import haxe.macro.Context;

import haxe.macro.ExprTools;
#end
#if !macro

import python.lib.Types.PyIterator;
#end


class Macros {

	@:noUsing macro public static function importModule (module:String):haxe.macro.Expr {
		return macro untyped __python__($v{"import " + module});
	}

	@:noUsing macro public static function importAs (module:String, className : String):haxe.macro.Expr
    {

        var n = className.split(".").join("_");

        var e = "import " + module + " as " + n;
        var e1 = "_hx_c."+n+" = "+n;


	    return macro{
            untyped __python__($v{e});
            untyped __python__($v{e1});
        }
    }


    @:noUsing macro public static function pyFor <T>(v:Expr, it:Expr, b:Expr):haxe.macro.Expr
    {
        var id = switch (v.expr) {
            case EConst(CIdent(x)):x;
            case _ : Context.error("unexpected " + ExprTools.toString(v) + ": const ident expected", v.pos);
        }



        var res = macro @:pos(it.pos) {
            var $id = $it.getNativeIterator().__next__();
            $it;
            $b;
        }
        return macro (untyped __python_for__)($res);
    }

    @:noUsing macro public static function importFromAs (from:String, module:String, className : String):haxe.macro.Expr {

        var n = className.split(".").join("_");

        var e = "from " + from + " import " + module + " as " + n;
        var e1 = "_hx_c."+n+" = " + n;
	    return macro {
            untyped __python__($v{e});
            untyped __python__($v{e1});
        }
    }

    #if !macro macro #end public static function callNamed (e:Expr, args:Expr):haxe.macro.Expr {
        var fArgs = switch (Context.typeof(e)) {
            case TFun(args, ret): args;
            case _ : haxe.macro.Context.error("e must be of type function", e.pos);
        }
        switch (args.expr) {
            case EObjectDecl(fields):
                for (f in fields) {
                    var found = false;
                    for (a in fArgs) {
                        found = a.name == f.field;
                        if (found) break;
                    }
                    if (!found) {
                        haxe.macro.Context.error("field " + f.field + " is not a valid argument (valid names " + [for (a in fArgs) a.name].join(",") + ")", args.pos);
                    }
                }
                // TODO check at least if fields are valid (maybe if types match);
            case _ : haxe.macro.Context.error("args must be an ObjectDeclaration like { name : 1 }", args.pos);
        }
        return macro @:pos(e.pos) untyped __named__($e, $args);
    }


}
{'fraction_non_alphanumeric': 0.1361218125114658, 'fraction_numerical': 0.00183452577508714, 'mean_word_length': 1.8088614116434827, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1961285', 'n_tokens_mistral': 1770, 'n_tokens_neox': 1670, 'n_words': 433}