Skip to content

Commit

Permalink
Opens up Arcs code to more directories.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 366175605
  • Loading branch information
piotrswigon authored and arcs-c3po committed Apr 2, 2021
1 parent fd4a998 commit b8f6304
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions java/arcs/core/util/Parser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,19 @@ class ManyOfParser<T>(val parser: Parser<T>) : Parser<List<T>>() {
}
}

/**
* A parser providing a name for debugging purposes (traceback) but delegates parsing.
*/
class NamedParser<T>(name: String, val parser: Parser<T>) : Parser<T>() {

init {
this.name = name
}

override fun invoke(string: String, pos: SourcePosition) = parser.invoke(string, pos)
override fun leftTokens() = parser.leftTokens()
}

class ParserException(msg: String, cause: Exception) : Exception(msg, cause)

/** A parser which converts the return value of a parser into another value. */
Expand Down Expand Up @@ -587,6 +600,9 @@ fun <T> many(parser: Parser<T>) = ManyOfParser(parser)
/** Helper for [AnyOfParser]. */
fun <T> any(parsers: List<Parser<T>>) = AnyOfParser(parsers)

/** Helper for [NamedParser] */
fun <T> Parser<T>.named(name: String) = NamedParser(name, this)

/** Helper for [TransformParser]. */
fun <T, R> Parser<T>.map(f: (T) -> R) = TransformParser(this, f)

Expand Down

0 comments on commit b8f6304

Please sign in to comment.