strscans: fix the type checking logic; improve the documentation
This commit is contained in:
parent
9bc2638399
commit
06e68feadb
1 changed files with 8 additions and 8 deletions
|
|
@ -333,37 +333,37 @@ macro scanf*(input: string; pattern: static[string]; results: varargs[typed]): b
|
||||||
conds.add resLen.notZero
|
conds.add resLen.notZero
|
||||||
conds.add resLen
|
conds.add resLen
|
||||||
of 'w':
|
of 'w':
|
||||||
if i < results.len or getType(results[i]).typeKind != ntyString:
|
if i < results.len and getType(results[i]).typeKind == ntyString:
|
||||||
matchBind "parseIdent"
|
matchBind "parseIdent"
|
||||||
else:
|
else:
|
||||||
error("no string var given for $w")
|
error("no string var given for $w")
|
||||||
inc i
|
inc i
|
||||||
of 'b':
|
of 'b':
|
||||||
if i < results.len or getType(results[i]).typeKind != ntyInt:
|
if i < results.len and getType(results[i]).typeKind == ntyInt:
|
||||||
matchBind "parseBin"
|
matchBind "parseBin"
|
||||||
else:
|
else:
|
||||||
error("no int var given for $b")
|
error("no int var given for $b")
|
||||||
inc i
|
inc i
|
||||||
of 'o':
|
of 'o':
|
||||||
if i < results.len or getType(results[i]).typeKind != ntyInt:
|
if i < results.len and getType(results[i]).typeKind == ntyInt:
|
||||||
matchBind "parseOct"
|
matchBind "parseOct"
|
||||||
else:
|
else:
|
||||||
error("no int var given for $o")
|
error("no int var given for $o")
|
||||||
inc i
|
inc i
|
||||||
of '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"
|
matchBind "parseInt"
|
||||||
else:
|
else:
|
||||||
error("no int var given for $i")
|
error("no int var given for $i")
|
||||||
inc i
|
inc i
|
||||||
of 'h':
|
of 'h':
|
||||||
if i < results.len or getType(results[i]).typeKind != ntyInt:
|
if i < results.len and getType(results[i]).typeKind == ntyInt:
|
||||||
matchBind "parseHex"
|
matchBind "parseHex"
|
||||||
else:
|
else:
|
||||||
error("no int var given for $h")
|
error("no int var given for $h")
|
||||||
inc i
|
inc i
|
||||||
of 'f':
|
of 'f':
|
||||||
if i < results.len or getType(results[i]).typeKind != ntyFloat:
|
if i < results.len and getType(results[i]).typeKind == ntyFloat:
|
||||||
matchBind "parseFloat"
|
matchBind "parseFloat"
|
||||||
else:
|
else:
|
||||||
error("no float var given for $f")
|
error("no float var given for $f")
|
||||||
|
|
@ -378,7 +378,7 @@ macro scanf*(input: string; pattern: static[string]; results: varargs[typed]): b
|
||||||
else:
|
else:
|
||||||
error("invalid format string")
|
error("invalid format string")
|
||||||
of '*', '+':
|
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 min = ord(pattern[p] == '+')
|
||||||
var q=p+1
|
var q=p+1
|
||||||
var token = ""
|
var token = ""
|
||||||
|
|
@ -462,7 +462,7 @@ template success*(x: int): bool = x != 0
|
||||||
template nxt*(input: string; idx, step: int = 1) = inc(idx, step)
|
template nxt*(input: string; idx, step: int = 1) = inc(idx, step)
|
||||||
|
|
||||||
macro scanp*(input, idx: typed; pattern: varargs[untyped]): bool =
|
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]
|
type StmtTriple = tuple[init, cond, action: NimNode]
|
||||||
|
|
||||||
template interf(x): untyped = bindSym(x, brForceOpen)
|
template interf(x): untyped = bindSym(x, brForceOpen)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue