diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/parseutils.nim | 4 | ||||
-rw-r--r-- | lib/pure/strscans.nim | 7 |
2 files changed, 11 insertions, 0 deletions
diff --git a/lib/pure/parseutils.nim b/lib/pure/parseutils.nim index 29159816d..ccfac2a7e 100644 --- a/lib/pure/parseutils.nim +++ b/lib/pure/parseutils.nim @@ -241,6 +241,10 @@ proc parseIdent*(s: string, start = 0): string = while i < s.len and s[i] in IdentChars: inc(i) result = substr(s, start, i-1) +proc parseChar*(s: string, ident: var char, start = 0): int = + ident = s[start] + result = 1 + proc skipWhitespace*(s: string, start = 0): int {.inline.} = ## Skips the whitespace starting at ``s[start]``. Returns the number of ## skipped characters. diff --git a/lib/pure/strscans.nim b/lib/pure/strscans.nim index f7032f428..347dbc2ef 100644 --- a/lib/pure/strscans.nim +++ b/lib/pure/strscans.nim @@ -37,6 +37,7 @@ substrings starting with ``$``. These constructions are available: ``$h`` Matches a hex integer. This uses ``parseutils.parseHex``. ``$f`` Matches a floating pointer number. Uses ``parseFloat``. ``$w`` Matches an ASCII identifier: ``[A-Za-z_][A-Za-z_0-9]*``. +``$c`` Matches a single ASCII character. ``$s`` Skips optional whitespace. ``$$`` Matches a single dollar sign. ``$.`` Matches if the end of the input string has been reached. @@ -345,6 +346,12 @@ macro scanf*(input: string; pattern: static[string]; results: varargs[typed]): b else: matchError inc i + of 'c': + if i < results.len and getType(results[i]).typeKind == ntyChar: + matchBind "parseChar" + else: + matchError + inc i of 'b': if i < results.len and getType(results[i]).typeKind == ntyInt: matchBind "parseBin" |