<commit_before>
const ohm = require('ohm-js');
const fs = require('fs');
const grammar = ohm.grammar();

class Program {
  constructor(e) {
    this.body = e;
  }
}

class Block {
  constuctor(body) {
    this.body = body;
  }
}

class Statement {
}

// class IfStatement extends Statement {
//   constructor(condition, body, elseIfStmt, elseStmt) {
//     this.condition = condition;
//     this.body = body;
//     this.elseIf = elseIfStmt;
//     this.else = elseStmt;
//   }
//   if()
//   return "if " + "{" + this.condition + "}" + " else " + "{" + this.body + "}";
// }

class ForStatement extends Statement {
  constructor(identifier, structure, body) {
    this.for = identifier;
    this.in = structure;
    this.body = body;
  }
    return "for " + this.for + " in " + this.in + "{" + this.body + "}";
}

class WhileStatement extends Statement {
  constructor(condition, body) {
    this.condition = condition;
    this.body = body;
  }
  return "while " + this.condition + "{" + this.body + "}";
}

class MatchStatement extends Statement {
  constructor(e1, e2) {
    this.e1 = e1;
    this.e2 = e2;
  }
  return "match " + this.e1 + " with " + this.e2;
}

class ReturnStatement extends Statement {
  constructor(body) {
    this.body = body;
  }
  return "return " + this.body;
}

// class SimpleVariableDeclaration extends Statement {
//   constructor(id, type, value){
//     this.id = id;
//     this.type = type;
//     this.value = value;
//   }
//   return
// }
//
// class ArrayVariableDeclaration extends Statement {
//   constructor(id, type, value){
//     this.id = id;
//     this.type = type;
//     this.value = value;
//   }
//   return
// }

class Expression {
}

class BinaryExpression extends Expression {
  constructor(e1, op, e2) {
    super();
    this.left = e1;
    this.op = op;
    this.right = e2;
  }
}

class UnaryExpression extends Expression {
  constructor(op, e) {
    super();
    this.op = op;
    this.operand = e;
  }
}

class IdExpression extends Expression {
  constructor(idValue) {
    super();
    this.value = idValue;
  }
}

class Literal {
}

class FloatLiteral extends Literal {
  constructor(float) {
    super();
    this.value = float;
  }
}

class BooleanLiteral extends Literal {
  constructor(bool) {
    super();
    this.value = bool;
  }
}

class StringLiteral extends Literal {
  constructor(string) {
    super();
    this.value = string;
  }
}



const semantics = grammar.createSemantics().addOperation('ast', {

  Program(body) {
    return new Program(body.ast);
  },
  Block(stmt, _) {
    return new Block(stmt.ast());
  },

//   Stmt_if() {
//     return new IfStatement();
//   },
//   Stmt_for() {
//     return new ForStatement();
//   },
//   Stmt_while() {
//     return new WhileStatement();
//   },
//   Stmt_match() {
//     return new MatchStatement();
//   },
//   Stmt_return() {
//     return new ReturnStatement();
//   },
//   Stmt_varDecl() {
//     return new VariableDeclaration(id.sourceString);
//   },
//   Stmt_arrayDecl() {
//     return new VariableDeclaration(id.sourceString);
//   },

  If_stmt(condition, body, elseIfStmt, elseStmt) {
    return new IfStatement("if", condition.ast(), "{", body.ast(), "}", elseIfStmt.ast(),
      elseStmt.ast());
  },

  // Not sure if this is correct
  For_stmt(identifier, structure, body) {
    return new ForStatement("for ", identifier.ast(), " in ", structure.ast(), "{",
      body.ast(), "}");
  },

  Exp_binary(e1, op, e2) {
    return new BinaryExpression(e1.ast(), "or", e2.ast());
  },
  Exp_binary(e1, op, e2) {
    return new BinaryExpression(e1.ast(), "and", e2.ast());
  },
  Exp1_binary(e1, op, e2) {
    return new BinaryExpression(e1.ast(), op.sourceString, e2.ast());
  },
  Exp2_binary(e1, op, e2) {
    return new BinaryExpression(e1.ast(), op.sourceString, e2.ast());
  },
  Exp3_binary(e1, op, e2) {<commit_msg>fixed semantics for if and for statement<commit_after>
const ohm = require('ohm-js');
const fs = require('fs');
const grammar = ohm.grammar();

class Program {
  constructor(e) {
    this.body = e;
  }
}

class Block {
  constuctor(body) {
    this.body = body;
  }
}

class Statement {
}

// class IfStatement extends Statement {
//   constructor(condition, body, elseIfStmt, elseStmt) {
//     this.condition = condition;
//     this.body = body;
//     this.elseIf = elseIfStmt;
//     this.else = elseStmt;
//   }
//   if()
//   return "if " + "{" + this.condition + "}" + " else " + "{" + this.body + "}";
// }

class ForStatement extends Statement {
  constructor(identifier, structure, body) {
    this.for = identifier;
    this.in = structure;
    this.body = body;
  }
    return "for " + this.for + " in " + this.in + "{" + this.body + "}";
}

class WhileStatement extends Statement {
  constructor(condition, body) {
    this.condition = condition;
    this.body = body;
  }
  return "while " + this.condition + "{" + this.body + "}";
}

class MatchStatement extends Statement {
  constructor(e1, e2) {
    this.e1 = e1;
    this.e2 = e2;
  }
  return "match " + this.e1 + " with " + this.e2;
}

class ReturnStatement extends Statement {
  constructor(body) {
    this.body = body;
  }
  return "return " + this.body;
}

// class SimpleVariableDeclaration extends Statement {
//   constructor(id, type, value){
//     this.id = id;
//     this.type = type;
//     this.value = value;
//   }
//   return
// }
//
// class ArrayVariableDeclaration extends Statement {
//   constructor(id, type, value){
//     this.id = id;
//     this.type = type;
//     this.value = value;
//   }
//   return
// }

class Expression {
}

class BinaryExpression extends Expression {
  constructor(e1, op, e2) {
    super();
    this.left = e1;
    this.op = op;
    this.right = e2;
  }
}

class UnaryExpression extends Expression {
  constructor(op, e) {
    super();
    this.op = op;
    this.operand = e;
  }
}

class IdExpression extends Expression {
  constructor(idValue) {
    super();
    this.value = idValue;
  }
}

class Literal {
}

class FloatLiteral extends Literal {
  constructor(float) {
    super();
    this.value = float;
  }
}

class BooleanLiteral extends Literal {
  constructor(bool) {
    super();
    this.value = bool;
  }
}

class StringLiteral extends Literal {
  constructor(string) {
    super();
    this.value = string;
  }
}



const semantics = grammar.createSemantics().addOperation('ast', {

  Program(body) {
    return new Program(body.ast);
  },
  Block(stmt, _) {
    return new Block(stmt.ast());
  },

//   Stmt_if() {
//     return new IfStatement();
//   },
//   Stmt_for() {
//     return new ForStatement();
//   },
//   Stmt_while() {
//     return new WhileStatement();
//   },
//   Stmt_match() {
//     return new MatchStatement();
//   },
//   Stmt_return() {
//     return new ReturnStatement();
//   },
//   Stmt_varDecl() {
//     return new VariableDeclaration(id.sourceString);
//   },
//   Stmt_arrayDecl() {
//     return new VariableDeclaration(id.sourceString);
//   },

  If_stmt(condition, body, elseIfStmt, elseStmt) {
    return new IfStatement(condition.ast(), body.ast(), elseIfStmt.ast(), elseStmt.ast());
  },

  // Not sure if this is correct
  For_stmt(identifier, structure, body) {
    return new ForStatement(identifier.ast(), structure.ast(), body.ast());
  },

  Exp_binary(e1, op, e2) {
    return new BinaryExpression(e1.ast(), "or", e2.ast());
  },
  Exp_binary(e1, op, e2) {
    return new BinaryExpression(e1.ast(), "and", e2.ast());
  },
  Exp1_binary(e1, op, e2) {
    return new BinaryExpression(e1.ast(), op.sourceString, e2.ast());
  },
  Exp2_binary(e1, op, e2) {
    return new BinaryExpression(e1.ast(), op.sourceString, e2.ast());
  },
  Exp3_binary(e1, op, e2) {
{'fraction_non_alphanumeric': 0.16668825281699262, 'fraction_numerical': 0.008548115529076545, 'mean_word_length': 2.675392670157068, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1588894', 'n_tokens_mistral': 2661, 'n_tokens_neox': 2638, 'n_words': 587}