diff --git a/benchmarks/src/main/scala/zio/parser/benchmarks/ParserBenchmark.scala b/benchmarks/src/main/scala/zio/parser/benchmarks/ParserBenchmark.scala index df101b6..28b333a 100644 --- a/benchmarks/src/main/scala/zio/parser/benchmarks/ParserBenchmark.scala +++ b/benchmarks/src/main/scala/zio/parser/benchmarks/ParserBenchmark.scala @@ -46,7 +46,7 @@ abstract class ParserBenchmark[T] { // } @Benchmark - def zioParserRecursive(): Either[zio.parser.ParseFailure[String], T] = { + def zioParserRecursive(): Either[zio.parser.StringParserError[String], T] = { import zio.parser._ zioSyntax.parseString(value, ParserImplementation.Recursive) } @@ -58,7 +58,7 @@ abstract class ParserBenchmark[T] { } @Benchmark - def zioParserOpStack(): Either[zio.parser.ParseFailure[String], T] = { + def zioParserOpStack(): Either[zio.parser.StringParserError[String], T] = { import zio.parser._ zioSyntax.parseString(value, ParserImplementation.StackSafe) } diff --git a/benchmarks/src/main/scala/zio/parser/benchmarks/lucene/LuceneQueryBenchmark.scala b/benchmarks/src/main/scala/zio/parser/benchmarks/lucene/LuceneQueryBenchmark.scala index 5e5a6dd..16d16b5 100644 --- a/benchmarks/src/main/scala/zio/parser/benchmarks/lucene/LuceneQueryBenchmark.scala +++ b/benchmarks/src/main/scala/zio/parser/benchmarks/lucene/LuceneQueryBenchmark.scala @@ -15,7 +15,7 @@ import org.openjdk.jmh.annotations.{ } import zio.Chunk import zio.parser.{ParserImplementation, Syntax} -import zio.parser.ParseFailure +import zio.parser.StringParserError import zio.parser.Parser.ParserError import zio.parser.internal.Debug @@ -51,11 +51,11 @@ class LuceneQueryBenchmark { catsParser.query.parseAll(testQuery) @Benchmark - def zioParse(): Either[ParseFailure[String], Query] = + def zioParse(): Either[StringParserError[String], Query] = zioParserQuery.parseString(testQuery) @Benchmark - def zioParseStrippedRecursive(): Either[ParseFailure[String], Query] = + def zioParseStrippedRecursive(): Either[StringParserError[String], Query] = zioParserStrippedQuery.parseString(testQuery, ParserImplementation.Recursive) @Benchmark @@ -63,7 +63,7 @@ class LuceneQueryBenchmark { zioParserStrippedQuery.parseChunk(testQueryChunk) @Benchmark - def zioParseStrippedOpStack(): Either[ParseFailure[String], Query] = + def zioParseStrippedOpStack(): Either[StringParserError[String], Query] = zioParserStrippedQuery.parseString(testQuery, ParserImplementation.StackSafe) // @Benchmark diff --git a/benchmarks/src/main/scala/zio/parser/benchmarks/micro/CharParserMicroBenchmarks.scala b/benchmarks/src/main/scala/zio/parser/benchmarks/micro/CharParserMicroBenchmarks.scala index 021142a..6a57e7a 100644 --- a/benchmarks/src/main/scala/zio/parser/benchmarks/micro/CharParserMicroBenchmarks.scala +++ b/benchmarks/src/main/scala/zio/parser/benchmarks/micro/CharParserMicroBenchmarks.scala @@ -13,7 +13,7 @@ import org.openjdk.jmh.annotations.{ Warmup } import zio.Chunk -import zio.parser.ParseFailure +import zio.parser.StringParserError import zio.parser.Parser.ParserError import zio.parser.{Regex, Syntax} @@ -69,23 +69,23 @@ class CharParserMicroBenchmarks { } @Benchmark - def skipAndTransform(): Either[ParseFailure[Nothing], String] = + def skipAndTransform(): Either[StringParserError[Nothing], String] = skipAndTransformSyntax.parseChars(hello) @Benchmark - def skipAndTransformOrElse(): Either[ParseFailure[String], String] = + def skipAndTransformOrElse(): Either[StringParserError[String], String] = skipAndTransformOrElseSyntax.parseChars(world) @Benchmark - def skipAndTransformRepeat(): Either[ParseFailure[String], Chunk[String]] = + def skipAndTransformRepeat(): Either[StringParserError[String], Chunk[String]] = skipAndTransformRepeatSyntax.parseChars(hellos) @Benchmark - def skipAndTransformZip(): Either[ParseFailure[String], String10] = + def skipAndTransformZip(): Either[StringParserError[String], String10] = skipAndTransformZipSyntax.parseChars(hellos) @Benchmark - def repeatWithSep0(): Either[ParseFailure[String], Chunk[String]] = + def repeatWithSep0(): Either[StringParserError[String], Chunk[String]] = repeatWithSep0Syntax.parseString(hellosSep) } diff --git a/zio-parser-caliban/src/main/scala/zio/parser/caliban/CalibanParser.scala b/zio-parser-caliban/src/main/scala/zio/parser/caliban/CalibanParser.scala index 06a9906..761dd6a 100644 --- a/zio-parser-caliban/src/main/scala/zio/parser/caliban/CalibanParser.scala +++ b/zio-parser-caliban/src/main/scala/zio/parser/caliban/CalibanParser.scala @@ -911,7 +911,7 @@ object CalibanDemo extends ZIOAppDefault { (id: "1000", int: 3, float: 3.14, bool: true, nope: null, enum: YES, list: [1,2,3]) """.trim - val parsed: ZIO[Any, Nothing, Either[ParseFailure[String], StringValue]] = + val parsed: ZIO[Any, Nothing, Either[StringParserError[String], StringValue]] = ZIO .succeed(CalibanParser.stringValue.parseString(query)) // val parsed = UIO(CalibanSyntax.stringValue.parse("\"\"\"hello\"\"\"")) diff --git a/zio-parser/shared/src/main/scala/zio/parser/Parser.scala b/zio-parser/shared/src/main/scala/zio/parser/Parser.scala index 896a7e7..f5b1456 100644 --- a/zio-parser/shared/src/main/scala/zio/parser/Parser.scala +++ b/zio-parser/shared/src/main/scala/zio/parser/Parser.scala @@ -272,38 +272,38 @@ sealed trait Parser[+Err, -In, +Result] extends VersionSpecificParser[Err, In, R // Execution /** Run this parser on the given 'input' string */ - final def parseString(input: String)(implicit ev: Char <:< In): Either[ParseFailure[Err], Result] = + final def parseString(input: String)(implicit ev: Char <:< In): Either[StringParserError[Err], Result] = parseString(input, self.defaultImplementation) /** Run this parser on the given 'input' string using a specific parser implementation */ final def parseString(input: String, parserImplementation: ParserImplementation)(implicit ev: Char <:< In - ): Either[ParseFailure[Err], Result] = + ): Either[StringParserError[Err], Result] = parserImplementation match { case ParserImplementation.StackSafe => val parser = new CharParserImpl[Err, Result]( self.compiledOpStack, input ) - parser.run().left.map(err => ParseFailure(input, err)) + parser.run().left.map(err => StringParserError(input, err)) case ParserImplementation.Recursive => val state = recursive.ParserState.fromString(input) val result = self.optimized.parseRec(state.asInstanceOf[ParserState[In]]) if (state.error != null) - Left(ParseFailure(input, state.error.asInstanceOf[ParserError[Err]])) + Left(StringParserError(input, state.error.asInstanceOf[ParserError[Err]])) else Right(result) } /** Run this parser on the given 'input' chunk of characters */ - final def parseChars(input: Chunk[Char])(implicit ev: Char <:< In): Either[ParseFailure[Err], Result] = + final def parseChars(input: Chunk[Char])(implicit ev: Char <:< In): Either[StringParserError[Err], Result] = parseChars(input, self.defaultImplementation) /** Run this parser on the given 'input' chunk of characters using a specific parser implementation */ final def parseChars(input: Chunk[Char], parserImplementation: ParserImplementation)(implicit ev: Char <:< In - ): Either[ParseFailure[Err], Result] = + ): Either[StringParserError[Err], Result] = parseString(new String(input.toArray), parserImplementation) /** Run this parser on the given 'input' chunk */ @@ -1440,7 +1440,7 @@ object Parser { } } -final case class ParseFailure[+Err](input: String, error: ParserError[Err]) { +final case class StringParserError[+Err](input: String, error: ParserError[Err]) { def pretty: String = { val sb = new StringBuilder diff --git a/zio-parser/shared/src/main/scala/zio/parser/Syntax.scala b/zio-parser/shared/src/main/scala/zio/parser/Syntax.scala index bf39830..13f094f 100644 --- a/zio-parser/shared/src/main/scala/zio/parser/Syntax.scala +++ b/zio-parser/shared/src/main/scala/zio/parser/Syntax.scala @@ -384,23 +384,23 @@ class Syntax[+Err, -In, +Out, Value] private ( ) /** Run this parser on the given 'input' string */ - final def parseString(input: String)(implicit ev: Char <:< In): Either[ParseFailure[Err], Value] = + final def parseString(input: String)(implicit ev: Char <:< In): Either[StringParserError[Err], Value] = asParser.parseString(input) /** Run this parser on the given 'input' string using a specific parser implementation */ final def parseString(input: String, parserImplementation: ParserImplementation)(implicit ev: Char <:< In - ): Either[ParseFailure[Err], Value] = + ): Either[StringParserError[Err], Value] = asParser.parseString(input, parserImplementation) /** Run this parser on the given 'input' chunk of characters */ - final def parseChars(input: Chunk[Char])(implicit ev: Char <:< In): Either[ParseFailure[Err], Value] = + final def parseChars(input: Chunk[Char])(implicit ev: Char <:< In): Either[StringParserError[Err], Value] = asParser.parseChars(input) /** Run this parser on the given 'input' chunk of characters using a specific parser implementation */ final def parseChars(input: Chunk[Char], parserImplementation: ParserImplementation)(implicit ev: Char <:< In - ): Either[ParseFailure[Err], Value] = asParser.parseChars(input, parserImplementation) + ): Either[StringParserError[Err], Value] = asParser.parseChars(input, parserImplementation) /** Run this parser on the given 'input' chunk */ final def parseChunk[In0 <: In](input: Chunk[In0])(implicit diff --git a/zio-parser/shared/src/test/scala/zio/parser/ParseFailureSpec.scala b/zio-parser/shared/src/test/scala/zio/parser/StringParserErrorSpec.scala similarity index 97% rename from zio-parser/shared/src/test/scala/zio/parser/ParseFailureSpec.scala rename to zio-parser/shared/src/test/scala/zio/parser/StringParserErrorSpec.scala index a9ec193..bb91ac2 100644 --- a/zio-parser/shared/src/test/scala/zio/parser/ParseFailureSpec.scala +++ b/zio-parser/shared/src/test/scala/zio/parser/StringParserErrorSpec.scala @@ -3,9 +3,9 @@ package zio.parser import zio.test.Assertion._ import zio.test._ -object ParseFailureSpec extends ZIOSpecDefault { +object StringParserErrorSpec extends ZIOSpecDefault { override def spec = - suite("ParseFailure")( + suite("StringParserError")( failureTest( "should pretty print a Failure error", Syntax.char('y'),