Skip to content

Commit

Permalink
improved symbol naming
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mie6 committed Apr 28, 2024
1 parent aacee69 commit b526deb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
6 changes: 5 additions & 1 deletion parsley/shared/src/main/scala/parsley/combinator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ private [parsley] trait combinator {
* @group multi
* @see [[parsley.Parsley.<|> `<|>`]]
*/
final def choice[A](ps: Parsley[A]*): Parsley[A] = ps.reduceRightOption(_ |: _).getOrElse(empty(0)).uo("choice")
final def choice[A](ps: Parsley[A]*): Parsley[A] = ps match {
case ps if ps.isEmpty => empty
case Seq(p) => p
case ps => ps.reduceRight(_ |: _).uo("choice")
}

// This combinator is still used in internal testing, but is a trap for new users
// it will not be exposed in the API again.
Expand Down
4 changes: 2 additions & 2 deletions parsley/shared/src/main/scala/parsley/syntax/character.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ object character {
*
* @see [[parsley.character.string `character.string`]]
*/
@inline implicit def stringLift(str: String): Parsley[String] = string(str)
@inline implicit def stringLift(str: String): Parsley[String] = string(str).uo(s""""$str"""")
/** Converts a character literal into a parser that reads that character.
*
* Allows for the implicit application of the `char` combinator to a
* character literal.
*
* @see [[parsley.character.char `character.char`]]
*/
@inline implicit def charLift(c: Char): Parsley[Char] = char(c)
@inline implicit def charLift(c: Char): Parsley[Char] = char(c).uo(s"\'$c\'")
// $COVERAGE-ON$
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ private [token] class ConcreteSymbol(nameDesc: NameDesc, symbolDesc: SymbolDesc,
override def apply(name: String): Parsley[Unit] = {
require(name.nonEmpty, "Symbols may not be empty strings")
lazy val symbolLabel = err.labelSymbol.getOrElse(name, NotConfigured).orElse(err.defaultSymbolPunctuation.config(name))
if (symbolDesc.hardKeywords(name)) softKeyword(name)
else if (symbolDesc.hardOperators(name)) softOperator(name)
else symbolLabel(atomic(string(name)).void)
if (symbolDesc.hardKeywords(name)) softKeyword(name).uo(s"symbol($name)")
else if (symbolDesc.hardOperators(name)) softOperator(name).uo(s"symbol($name)")
else symbolLabel(atomic(string(name).ut()).ut().void.uo(s"symbol($name)"))
}

override def apply(name: Char): Parsley[Unit] = err.labelSymbol.getOrElse(name.toString, NotConfigured)(char(name).void)
override def apply(name: Char): Parsley[Unit] = err.labelSymbol.getOrElse(name.toString, NotConfigured)(char(name).ut().void.uo(s"symbol($name)"))

override def softKeyword(name: String): Parsley[Unit] = {
require(name.nonEmpty, "Keywords may not be empty strings")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ abstract class Symbol private[symbol] {
*/
final val implicits: ImplicitSymbol = new ImplicitSymbol {
/** @inheritdoc */
implicit def implicitSymbol(s: String): Parsley[Unit] = apply(s)
implicit def implicitSymbol(s: String): Parsley[Unit] = apply(s).uo(s""""$s"""")
}

// $COVERAGE-OFF$
Expand Down

0 comments on commit b526deb

Please sign in to comment.