Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opens up Arcs code to more directories. #7068

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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