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

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -