Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
dkandalov committed Aug 27, 2023
1 parent f10dde6 commit a7a2edb
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
4 changes: 1 addition & 3 deletions parser4k/src/main/kotlin/parser4k/associativity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,4 @@ fun <T> InOrder<T>.mapLeftAssoc(transform: (List<T>) -> T) = object : Parser<T>
}
}

private object RightRecursionMarker {
override fun toString() = "RightRecursionMarker"
}
private data object RightRecursionMarker
2 changes: 1 addition & 1 deletion parser4k/src/main/kotlin/parser4k/util-generated.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("UNCHECKED_CAST", "unused")
@file:Suppress("unused")

package parser4k

Expand Down
5 changes: 2 additions & 3 deletions parser4k/src/test/kotlin/parser4k/examples/expression-lang.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import parser4k.shouldEqual
import parser4k.skipWrapper
import parser4k.str
import parser4k.with
import java.util.Locale

private object ExpressionLang {
private val cache = OutputCache<Expr>()
Expand Down Expand Up @@ -121,8 +120,8 @@ private object ExpressionLang {
fun evaluate(s: String): Any = s.parseWith(expr).eval()

sealed class Expr {
object True : Expr()
object False : Expr()
data object True : Expr()
data object False : Expr()
data class IntLiteral(val value: Int) : Expr()
data class StringLiteral(val value: String) : Expr()
data class ArrayLiteral(val value: List<Expr>) : Expr()
Expand Down
4 changes: 2 additions & 2 deletions parser4k/src/test/kotlin/parser4k/output-cache-tests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class `Parsing log example for cached plus-minus-int grammar` {
}

@Test
fun `"123" parsing log`() {
fun `log when parsing '123'`() {
"123".parseWith(plusMinusGrammar.expr) shouldEqual IntLiteral(123)

logEvents.toDebugString() shouldEqual """
Expand Down Expand Up @@ -60,7 +60,7 @@ class `Cached parsers are called at most one time at each offset` {
}

@Test
fun `"123" parsing log`() {
fun `log when parsing '123'`() {
"123".parseWith(plusMinusGrammar.expr)
logEvents.toDebugString() shouldEqual """
"123" plus:0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ class PetStoreExample(
// perform some pre-validation; explicitly return failure if they fail
if (humanId in blacklist) return Failure(PetError.OwnerBlacklisted)
if (adoptions.any { it.pet.id == petId }) return Failure(PetError.PetNotForAdoption)
val pet = pets.find { it.id == petId } ?: return Failure(PetError.PetNotFound)

return pets
.find { it.id == petId }
.asResultOr { PetError.PetNotFound } // convert to failure if pet not found
.map { pet -> Adoption(humanId, pet) } // if pet found, convert to Adoption and return
.peek { adoption -> adoptions += adoption } // Perform a side-effect with the success value
val adoption = Adoption(humanId, pet)
adoptions += adoption

return Success(adoption)
}

fun brag(adoption: Adoption) {
Expand Down

0 comments on commit a7a2edb

Please sign in to comment.