scala - How to match exactly 'n' given characters with FastParse -
the fastparse parser-combinator scala library gives .rep(n)
'repeat' method allow create new parser attempts parse givenparser n
or more times. what's canonical way if want exactly n
matches?
in case, want parse 40-character git commit id - if longer 40 characters, that's not commit id, , shouldn't match.
the closest example i've found in docs far is:
val unicodeescape = p( "u" ~ hexdigit ~ hexdigit ~ hexdigit ~ hexdigit )
...which matches 4 characters simple repetition (verbose 40-character commit id).
these parser-combinators, not regex, answer \p{xdigit}{40}
.
since issue closed commit, rep supports max keyword argument. supports keyword argument.
hexdigit.rep(exactly = 40)
Comments
Post a Comment