All Downloads are FREE. Search and download functionalities are using the official Maven repository.

izumi.idealingua.il.loader.ModelParserImpl.scala Maven / Gradle / Ivy

The newest version!
package izumi.idealingua.il.loader

import izumi.idealingua.il.parser.{IDLParser, IDLParserContext}
import izumi.idealingua.model.loader._
import fastparse._

class ModelParserImpl() extends ModelParser {
  def parseModels(files: Map[FSPath, String]): ParsedModels = ParsedModels {
    files.map {
      case (file, content) =>
        file -> new IDLParser(IDLParserContext(file)).parseModel(content)
    }.toSeq.map {
      case (p, Parsed.Success(value, _)) =>
        ModelParsingResult.Success(p, value)

      case (p, f: Parsed.Failure) =>
        ModelParsingResult.Failure(p, s"Failed to parse model $p: ${f.msg}")

    }
  }

  def parseDomains(files: Map[FSPath, String]): ParsedDomains = ParsedDomains {
    files.map {
      case (file, content) =>
        file -> new IDLParser(IDLParserContext(file)).parseDomain(content)
    }.toSeq.map {
      case (p, Parsed.Success(value, _)) =>
        DomainParsingResult.Success(p, value)

      case (p, f: Parsed.Failure) =>
        DomainParsingResult.Failure(p, s"Failed to parse domain $p: ${f.trace().msg}")
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy