Skip to content

Commit

Permalink
Rename the error
Browse files Browse the repository at this point in the history
  • Loading branch information
johnspade committed Apr 1, 2024
1 parent 562d60a commit 60da20e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -51,19 +51,19 @@ 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
def zioParseStrippedRecursiveChunk(): Either[ParserError[String], Query] =
zioParserStrippedQuery.parseChunk(testQueryChunk)

@Benchmark
def zioParseStrippedOpStack(): Either[ParseFailure[String], Query] =
def zioParseStrippedOpStack(): Either[StringParserError[String], Query] =
zioParserStrippedQuery.parseString(testQuery, ParserImplementation.StackSafe)

// @Benchmark
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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\"\"\""))
Expand Down
14 changes: 7 additions & 7 deletions zio-parser/shared/src/main/scala/zio/parser/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions zio-parser/shared/src/main/scala/zio/parser/Syntax.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down

0 comments on commit 60da20e

Please sign in to comment.