<commit_before>let Log = require("log.js");
let Debug = require("debug.js");

let Ast = {};
exports = Ast;

// Logistics

function walk_array(array, cb) {
  for (let i = 0; i < array.length; ++i) {
    Debug.log(array[i].type);
    let current = array[i].walk(cb);
    if (current) {
      array[i] = current;
    }
  }
}

function walk_enter(obj, walker) {
  Debug.log("Entering "+obj.type);
  if (walker && walker.enter) {
    walker.enter(obj);
  }
}
function walk_exit(obj, walker) {
  if (walker && walker.exit) {
    return walker.exit(obj);
  }
  return null;
}


/**
 * @param {number} line
 * @param {number} column
 * @constructor
 */
Ast.Position = function(line, column) {
  this.line = line;
  this.column = column;
};
Ast.Position.prototype = {
  toString: function() {
    return ""+this.line+":"+this.column;
  }
};
Ast.SourceLocation = function(fileName, start, end) {
  this.source = fileName;
  this.start  = start;
  this.end    = end;
};
Ast.SourceLocation.prototype = {
  toString: function() {
    return this.source+" ["+this.start+"-"+this.end+"]";
  }
};
Ast.Directive = function(lines, range, type, string, key, code, name) {
  this.type  = type;
  this.value = string;
  this.key = key;
  this.code = code;
  this.name = name;
  this.lines = lines;
};

Ast.Node = function(loc, range, comments) {
  this.loc = loc;
  this.range = range;
  this.comments = comments;
};
Ast.Node.prototype = {
  toJS: function() {
    Debug.log(""+this.type+".toJS() not implemented yet");
  },
  walk: function() {
    Debug.log(""+this.type+".walk() not implemented yet");
  }
};

Ast.Program = function(loc, range, comments, elements, directives) {
  Ast.Node.call(this, loc, range, comments);
  this.elements = elements; // SpiderMonkey-style
  this.body = elements; // esprima-style
  this.directives = directives;
};
Ast.Program.prototype = new Ast.Node();<commit_msg>[Cleanup] ast.js: Ast.Directive now doesn't contain line numbers<commit_after>let Log = require("log.js");
let Debug = require("debug.js");

let Ast = {};
exports = Ast;

// Logistics

function walk_array(array, cb) {
  for (let i = 0; i < array.length; ++i) {
    Debug.log(array[i].type);
    let current = array[i].walk(cb);
    if (current) {
      array[i] = current;
    }
  }
}

function walk_enter(obj, walker) {
  Debug.log("Entering "+obj.type);
  if (walker && walker.enter) {
    walker.enter(obj);
  }
}
function walk_exit(obj, walker) {
  if (walker && walker.exit) {
    return walker.exit(obj);
  }
  return null;
}


/**
 * @param {number} line
 * @param {number} column
 * @constructor
 */
Ast.Position = function(line, column) {
  this.line = line;
  this.column = column;
};
Ast.Position.prototype = {
  toString: function() {
    return ""+this.line+":"+this.column;
  }
};
Ast.SourceLocation = function(fileName, start, end) {
  this.source = fileName;
  this.start  = start;
  this.end    = end;
};
Ast.SourceLocation.prototype = {
  toString: function() {
    return this.source+" ["+this.start+"-"+this.end+"]";
  }
};
Ast.Directive = function(range, type, string, key, code, name) {
  this.type  = type;
  this.value = string;
  this.key = key;
  this.code = code;
  this.name = name;
};

Ast.Node = function(loc, range, comments) {
  this.loc = loc;
  this.range = range;
  this.comments = comments;
};
Ast.Node.prototype = {
  toJS: function() {
    Debug.log(""+this.type+".toJS() not implemented yet");
  },
  walk: function() {
    Debug.log(""+this.type+".walk() not implemented yet");
  }
};

Ast.Program = function(loc, range, comments, elements, directives) {
  Ast.Node.call(this, loc, range, comments);
  this.elements = elements; // SpiderMonkey-style
  this.body = elements; // esprima-style
  this.directives = directives;
};
Ast.Program.prototype = new Ast.Node();
{'fraction_non_alphanumeric': 0.17845828933474128, 'fraction_numerical': 0.0005279831045406547, 'mean_word_length': 3.4212368728121354, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, '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': '6669549', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1334, 'n_words': 297}