<commit_before>package models.metaModel.mCore

import play.api.data.validation.ValidationError
import play.api.libs.functional.syntax._
import play.api.libs.json.Reads._
import play.api.libs.json._

import scala.annotation.tailrec
import scala.collection.immutable._

object MCoreReads {

  case class Dummy(name: String) extends ClassOrRef

  val empty = new {
    def mClass(name: String) = new MClass(name, false, Seq.empty, Seq.empty, Seq.empty, Seq.empty)

    def mRef(name: String) = new MReference(name, false, false, List.empty, List.empty, List.empty)
  }

  implicit val mObjectReads = new Reads[MObject] {
    override def reads(json: JsValue): JsResult[MObject] =
      json.validate(
        checkMClassReads.map(_.asInstanceOf[MObject]) orElse
          checkMReferenceReads.map(_.asInstanceOf[MObject]) orElse
          checkMEnumReads.map(_.asInstanceOf[MObject])
      )
  }

  def wireSuperTypes(newMap: => Map[String, MObject], old: Seq[MClass]): Seq[MClass] = {
    old.map(m => newMap.get(m.name).get.asInstanceOf[MClass])
  }
<commit_msg>enabled more precise errors when parsing json<commit_after>package models.metaModel.mCore

import play.api.data.validation.ValidationError
import play.api.libs.functional.syntax._
import play.api.libs.json.Reads._
import play.api.libs.json._

import scala.annotation.tailrec
import scala.collection.immutable._

object MCoreReads {

  case class Dummy(name: String) extends ClassOrRef

  val empty = new {
    def mClass(name: String) = new MClass(name, false, Seq.empty, Seq.empty, Seq.empty, Seq.empty)

    def mRef(name: String) = new MReference(name, false, false, List.empty, List.empty, List.empty)
  }

//  implicit val mObjectReads = new Reads[MObject] {
//    override def reads(json: JsValue): JsResult[MObject] =
//      json.validate(
//        checkMClassReads.map(_.asInstanceOf[MObject]) orElse
//          checkMReferenceReads.map(_.asInstanceOf[MObject]) orElse
//          checkMEnumReads.map(_.asInstanceOf[MObject])
//      )
//  }

  implicit val mObjectReads = new Reads[MObject] {
    override def reads(json: JsValue): JsResult[MObject] = (json \ "mType").toOption match {
      case Some(JsString(s)) if s == "mClass" => json.validate(mClassReads.map(_.asInstanceOf[MObject]))
      case Some(JsString(s)) if s == "mReference" => json.validate(mReferenceReads.map(_.asInstanceOf[MObject]))
      case Some(JsString(s)) if s == "mEnum" => json.validate(mEnumReads.map(_.asInstanceOf[MObject]))
      case _  => JsError("Missing or unknown mType at top level, only mClass, mReference and mEnum allowed")
    }
  }

  def wireSuperTypes(newMap: => Map[String, MObject], old: Seq[MClass]): Seq[MClass] = {
    old.map(m => newMap.get(m.name).get.asInstanceOf[MClass])
  }

{'fraction_non_alphanumeric': 0.1295825771324864, 'fraction_numerical': 0.0, 'mean_word_length': 4.029197080291971, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1455237', 'n_tokens_mistral': 958, 'n_tokens_neox': 935, 'n_words': 191}