strscans: fix the type checking logic; improve the documentation

This commit is contained in:
Araq
2018-01-06 17:27:19 +01:00
parent 9bc2638399
commit 06e68feadb

View File

@@ -333,37 +333,37 @@ macro scanf*(input: string; pattern: static[string]; results: varargs[typed]): b
conds.add resLen.notZero
conds.add resLen
of 'w':
if i < results.len or getType(results[i]).typeKind != ntyString:
if i < results.len and getType(results[i]).typeKind == ntyString:
matchBind "parseIdent"
else:
error("no string var given for $w")
inc i
of 'b':
if i < results.len or getType(results[i]).typeKind != ntyInt:
if i < results.len and getType(results[i]).typeKind == ntyInt:
matchBind "parseBin"
else:
error("no int var given for $b")
inc i
of 'o':
if i < results.len or getType(results[i]).typeKind != ntyInt:
if i < results.len and getType(results[i]).typeKind == ntyInt:
matchBind "parseOct"
else:
error("no int var given for $o")
inc i
of 'i':
if i < results.len or getType(results[i]).typeKind != ntyInt:
if i < results.len and getType(results[i]).typeKind == ntyInt:
matchBind "parseInt"
else:
error("no int var given for $i")
inc i
of 'h':
if i < results.len or getType(results[i]).typeKind != ntyInt:
if i < results.len and getType(results[i]).typeKind == ntyInt:
matchBind "parseHex"
else:
error("no int var given for $h")
inc i
of 'f':
if i < results.len or getType(results[i]).typeKind != ntyFloat:
if i < results.len and getType(results[i]).typeKind == ntyFloat:
matchBind "parseFloat"
else:
error("no float var given for $f")
@@ -378,7 +378,7 @@ macro scanf*(input: string; pattern: static[string]; results: varargs[typed]): b
else:
error("invalid format string")
of '*', '+':
if i < results.len or getType(results[i]).typeKind != ntyString:
if i < results.len and getType(results[i]).typeKind == ntyString:
var min = ord(pattern[p] == '+')
var q=p+1
var token = ""
@@ -462,7 +462,7 @@ template success*(x: int): bool = x != 0
template nxt*(input: string; idx, step: int = 1) = inc(idx, step)
macro scanp*(input, idx: typed; pattern: varargs[untyped]): bool =
## See top level documentation of his module of how ``scanp`` works.
## ``scanp`` is currently undocumented.
type StmtTriple = tuple[init, cond, action: NimNode]
template interf(x): untyped = bindSym(x, brForceOpen)