Skip to content

Commit

Permalink
Use flatMap instead of positive-lookahead
Browse files Browse the repository at this point in the history
  • Loading branch information
kyri-petrou committed May 23, 2024
1 parent c86d2aa commit 2d24ffb
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ private[caliban] trait StringParsers {

def sourceCharacter(implicit ev: P[Any]): P[Unit] = CharIn("\u0009\u000A\u000D\u0020-\uFFFF")
def sourceCharacterWithoutLineTerminator(implicit ev: P[Any]): P[Unit] = CharIn("\u0009\u0020-\uFFFF")
def name(implicit ev: P[Any]): P[String] = !CharIn("0-9") ~~ CharsWhileIn("_0-9A-Za-z", 1).!
def name(implicit ev: P[Any]): P[String] =
CharsWhileIn("_0-9A-Za-z", 1).!.flatMap { s =>
// Less efficient in case of an error, but more efficient in case of success (happy path)
if (s.charAt(0) <= '9') ev.freshFailure()
else ev.freshSuccess(s)
}
def nameOnly(implicit ev: P[Any]): P[String] = Start ~ name ~ End

def hexDigit(implicit ev: P[Any]): P[Unit] = CharIn("0-9a-fA-F")
Expand Down

0 comments on commit 2d24ffb

Please sign in to comment.