<commit_before>package tools.haxelib;

import tools.haxelib.Config;

using Lambda;

enum Token {
  PROPERTY(name:String,value:String,info:Info);
  SECTION(name:String,attrs:String,info:Info);
  UNKNOWN(info:Info);
}


private
class Fields {
  static var fldMap:Hash<{keyName:String,required:Bool}>;
  
  static public
  function init() {
    if (fldMap != null) return;
    fldMap = new Hash();
    fldMap.set("name",{keyName:"name",required:true});
    fldMap.set("author-email",{keyName:"authorEmail",required:true});
    fldMap.set("version",{keyName:"version",required:true});
    fldMap.set("project-url",{keyName:"projectUrl",required:true});
    fldMap.set("description",{keyName:"description",required:true});
    fldMap.set("tags",{keyName:"tags",required:true});
    fldMap.set("license",{keyName:"license",required:true});
    
    fldMap.set("haxe-source-dirs",{keyName:"sourceDirs",required:false});
    fldMap.set("main-is",{keyName:"mainIs",required:false});
    fldMap.set("source-repository",{keyName:"sourceRepo",required:false});
    fldMap.set("haxelib-version",{keyName:"haxelibVersion",required:false});
  }

  static public
  function key(name:String) {
    return fldMap.exists(name) ? fldMap.get(name).keyName : name;
  }

  static public
  function required():List<String> {

    return fldMap
      .filter(function(val) { return val.required == true ;})
      .map(function(val) { return val.keyName; });
  }

}


typedef Property = String;

class Habal {
  public var file:String;
  var properties:Hash<Property>;
  var curSection:String;
  public var hbl:Dynamic;
  
  
  public
  function new(f:String) {
    file = f;
    hbl = {};
    properties = new Hash();
    curSection = "global";
    Reflect.setField(hbl,curSection,{});    
  }

  public
  function setSection(name,attrs,info) {
    if (info.indent == 0) {
      
      for (f in properties.keys()) {
        var fld = Fields.key(f);
        var val = parseProperty(fld,properties.get(f));
        Reflect.setField(Reflect.field(hbl,curSection),fld,val);
        //        trace("setting field "+fld+" in "+curSection+" to "+val);
      }
      
      properties = new Hash();
      var newSection = {};
      curSection = Fields.key(name);
      Reflect.setField(newSection,"attrs",spaceSeparated(attrs));
      //trace("processing section "+curSection);
      Reflect.setField(hbl,curSection,newSection);
    } else {
      trace("indent = "+info.indent+" and trying to setSection()");
    }
  }
  
  public
  function setProperty(name,values,info) {
    if (info.indent == 0)
      curSection = "global";

    properties.set(name,values);
  }

  public
  function spaceSeparated(s) {
    return Lambda.map(s.split(" "),function(el) { return StringTools.trim(el); }).array();
  }

  function parseLicense(val:String) {
    return  StringTools.trim(val).toUpperCase();
  }
  
  function parseProperty(fld:String,val:Dynamic):Dynamic {
    var ret:Dynamic;
    
    switch(fld) {
    case "sourceDirs":
      ret = spaceSeparated(val);<commit_msg>some reformattingc<commit_after>package tools.haxelib;

import tools.haxelib.Config;

using Lambda;

enum Token {
  PROPERTY(name:String,value:String,info:Info);
  SECTION(name:String,attrs:String,info:Info);
  UNKNOWN(info:Info);
}


private
class Fields {
  static var fldMap:Hash<{keyName:String,required:Bool}>;
  
  static public
  function init() {
    if (fldMap != null) return;
    fldMap = new Hash();
    fldMap.set("name",{keyName:"name",required:true});
    fldMap.set("author-email",{keyName:"authorEmail",required:true});
    fldMap.set("version",{keyName:"version",required:true});
    fldMap.set("project-url",{keyName:"projectUrl",required:true});
    fldMap.set("description",{keyName:"description",required:true});
    fldMap.set("tags",{keyName:"tags",required:true});
    fldMap.set("license",{keyName:"license",required:true});
    
    fldMap.set("haxe-source-dirs",{keyName:"sourceDirs",required:false});
    fldMap.set("main-is",{keyName:"mainIs",required:false});
    fldMap.set("source-repository",{keyName:"sourceRepo",required:false});
    fldMap.set("haxelib-version",{keyName:"haxelibVersion",required:false});
  }

  static public
  function key(name:String) {
    return fldMap.exists(name) ? fldMap.get(name).keyName : name;
  }

  static public
  function required():List<String> {

    return fldMap
      .filter(function(val) { return val.required == true ;})
      .map(function(val) { return val.keyName; });
  }

}


typedef Property = String;

class Habal {
  public var file:String;
  var properties:Hash<Property>;
  var curSection:String;
  public var hbl:Dynamic;
  
  
  public
  function new(f:String) {
    file = f;
    hbl = {};
    properties = new Hash();
    curSection = "global";
    Reflect.setField(hbl,curSection,{});    
  }

  public
  function setSection(name,attrs,info) {
    if (info.indent == 0) {
      
      for (f in properties.keys()) {
        var fld = Fields.key(f);
        var val = parseProperty(fld,properties.get(f));
        Reflect.setField(Reflect.field(hbl,curSection),fld,val);
        //        trace("setting field "+fld+" in "+curSection+" to "+val);
      }
      
      properties = new Hash();
      var newSection = {};
      curSection = Fields.key(name);
      Reflect.setField(newSection,"attrs",spaceSeparated(attrs));
      //trace("processing section "+curSection);
      Reflect.setField(hbl,curSection,newSection);
    } else {
      trace("indent = "+info.indent+" and trying to setSection()");
    }
  }
  
  public
  function setProperty(name,values,info) {
    if (info.indent == 0)
      curSection = "global";

    properties.set(name,values);
  }

  public function
  spaceSeparated(s) {
    return Lambda.map(s.split(" "),function(el) { return StringTools.trim(el); }).array();
  }

  function
  parseLicense(val:String) {
    return val.toUpperCase();
  }
  
  function
  parseProperty(fld:String,val:Dynamic):Dynamic {
    var ret:Dynamic;
    
    switch(fld) {
    case "sourceDirs":
      ret = spaceSeparated(val);
{'fraction_non_alphanumeric': 0.15974282888229477, 'fraction_numerical': 0.0006594131223211342, 'mean_word_length': 3.807448494453249, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, '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': '4009084', 'n_tokens_mistral': 2066, 'n_tokens_neox': 2018, 'n_words': 322}