[backport] run nimpretty on parsers
This commit is contained in:
parent
6c994b2498
commit
b17ed2ca9c
11 changed files with 207 additions and 193 deletions
|
|
@ -1945,7 +1945,8 @@ proc untilElementEnd(x: var XmlParser, result: XmlNode,
|
|||
adderr(expected(x, result))
|
||||
# this seems to do better match error corrections in browsers:
|
||||
while x.kind in {xmlElementEnd, xmlWhitespace}:
|
||||
if x.kind == xmlElementEnd and cmpIgnoreCase(x.elemName, result.tag) == 0:
|
||||
if x.kind == xmlElementEnd and cmpIgnoreCase(x.elemName,
|
||||
result.tag) == 0:
|
||||
break
|
||||
next(x)
|
||||
next(x)
|
||||
|
|
|
|||
|
|
@ -502,7 +502,8 @@ proc contains*(node: JsonNode, val: JsonNode): bool =
|
|||
assert(node.kind == JArray)
|
||||
find(node.elems, val) >= 0
|
||||
|
||||
proc existsKey*(node: JsonNode, key: string): bool {.deprecated: "use 'hasKey' instead".} =
|
||||
proc existsKey*(node: JsonNode, key: string): bool {.
|
||||
deprecated: "use 'hasKey' instead".} =
|
||||
node.hasKey(key)
|
||||
|
||||
proc `{}`*(node: JsonNode, keys: varargs[string]): JsonNode =
|
||||
|
|
@ -538,7 +539,8 @@ proc getOrDefault*(node: JsonNode, key: string): JsonNode =
|
|||
if not isNil(node) and node.kind == JObject:
|
||||
result = node.fields.getOrDefault(key)
|
||||
|
||||
template simpleGetOrDefault*{`{}`(node, [key])}(node: JsonNode, key: string): JsonNode = node.getOrDefault(key)
|
||||
template simpleGetOrDefault*{`{}`(node, [key])}(node: JsonNode,
|
||||
key: string): JsonNode = node.getOrDefault(key)
|
||||
|
||||
proc `{}=`*(node: JsonNode, keys: varargs[string], value: JsonNode) =
|
||||
## Traverses the node and tries to set the value at the given location
|
||||
|
|
@ -1331,7 +1333,8 @@ proc createConstructor(typeSym, jsonNode: NimNode): NimNode =
|
|||
(
|
||||
var map = `tableInit`[`tableKeyType`, `tableValueType`]();
|
||||
verifyJsonKind(`jsonNode`, {JObject}, astToStr(`jsonNode`));
|
||||
for `forLoopKey` in keys(`jsonNode`.fields): map[`forLoopKey`] = `constructorNode`;
|
||||
for `forLoopKey` in keys(`jsonNode`.fields): map[
|
||||
`forLoopKey`] = `constructorNode`;
|
||||
map
|
||||
)
|
||||
of "ref":
|
||||
|
|
@ -1374,7 +1377,8 @@ proc createConstructor(typeSym, jsonNode: NimNode): NimNode =
|
|||
(
|
||||
var list: `typeSym`;
|
||||
verifyJsonKind(`jsonNode`, {JArray}, astToStr(`jsonNode`));
|
||||
for `forLoopI` in 0 ..< `jsonNode`.len: list[`forLoopI`] =`constructorNode`;
|
||||
for `forLoopI` in 0 ..< `jsonNode`.len: list[
|
||||
`forLoopI`] = `constructorNode`;
|
||||
list
|
||||
)
|
||||
of "tuple":
|
||||
|
|
@ -1708,7 +1712,8 @@ when isMainModule:
|
|||
except IndexError: doAssert(true)
|
||||
|
||||
var parsed2 = parseFile("tests/testdata/jsontest2.json")
|
||||
doAssert(parsed2{"repository", "description"}.str=="IRC Library for Haskell", "Couldn't fetch via multiply nested key using {}")
|
||||
doAssert(parsed2{"repository", "description"}.str ==
|
||||
"IRC Library for Haskell", "Couldn't fetch via multiply nested key using {}")
|
||||
|
||||
doAssert escapeJsonUnquoted("\10Foo🎃barÄ") == "\\nFoo🎃barÄ"
|
||||
doAssert escapeJsonUnquoted("\0\7\20") == "\\u0000\\u0007\\u0014" # for #7887
|
||||
|
|
|
|||
|
|
@ -345,7 +345,8 @@ proc next*(p: var OptParser) {.rtl, extern: "npo$1".} =
|
|||
inc(i)
|
||||
while i < p.cmds[p.idx].len and p.cmds[p.idx][i] in {'\t', ' '}: inc(i)
|
||||
# if we're at the end, use the next command line option:
|
||||
if i >= p.cmds[p.idx].len and p.idx < p.cmds.len and p.allowWhitespaceAfterColon:
|
||||
if i >= p.cmds[p.idx].len and p.idx < p.cmds.len and
|
||||
p.allowWhitespaceAfterColon:
|
||||
inc p.idx
|
||||
i = 0
|
||||
if p.idx < p.cmds.len:
|
||||
|
|
@ -403,7 +404,8 @@ proc remainingArgs*(p: OptParser): seq[TaintedString] {.rtl, extern: "npo$1".} =
|
|||
result = @[]
|
||||
for i in p.idx..<p.cmds.len: result.add TaintedString(p.cmds[i])
|
||||
|
||||
iterator getopt*(p: var OptParser): tuple[kind: CmdLineKind, key, val: TaintedString] =
|
||||
iterator getopt*(p: var OptParser): tuple[kind: CmdLineKind, key,
|
||||
val: TaintedString] =
|
||||
## Convenience iterator for iterating over the given
|
||||
## `OptParser<#OptParser>`_.
|
||||
##
|
||||
|
|
@ -484,7 +486,8 @@ when declared(initOptParser):
|
|||
## if filename == "":
|
||||
## # no filename has been written, so we show the help
|
||||
## writeHelp()
|
||||
var p = initOptParser(cmdline, shortNoVal=shortNoVal, longNoVal=longNoVal)
|
||||
var p = initOptParser(cmdline, shortNoVal = shortNoVal,
|
||||
longNoVal = longNoVal)
|
||||
while true:
|
||||
next(p)
|
||||
if p.kind == cmdEnd: break
|
||||
|
|
|
|||
|
|
@ -264,7 +264,8 @@ proc getSymbol(c: var SqlLexer, tok: var Token) =
|
|||
while true:
|
||||
add(tok.literal, c.buf[pos])
|
||||
inc(pos)
|
||||
if c.buf[pos] notin {'a'..'z','A'..'Z','0'..'9','_','$', '\128'..'\255'}:
|
||||
if c.buf[pos] notin {'a'..'z', 'A'..'Z', '0'..'9', '_', '$',
|
||||
'\128'..'\255'}:
|
||||
break
|
||||
c.bufpos = pos
|
||||
tok.kind = tkIdentifier
|
||||
|
|
@ -714,7 +715,8 @@ proc identOrLiteral(p: var SqlParser): SqlNode =
|
|||
getTok(p) # we must consume a token here to prevent endless loops!
|
||||
|
||||
proc primary(p: var SqlParser): SqlNode =
|
||||
if (p.tok.kind == tkOperator and (p.tok.literal == "+" or p.tok.literal == "-")) or isKeyw(p, "not"):
|
||||
if (p.tok.kind == tkOperator and (p.tok.literal == "+" or p.tok.literal ==
|
||||
"-")) or isKeyw(p, "not"):
|
||||
result = newNode(nkPrefix)
|
||||
result.add(newNode(nkIdent, p.tok.literal))
|
||||
getTok(p)
|
||||
|
|
|
|||
|
|
@ -64,8 +64,8 @@ const
|
|||
proc toLower(c: char): char {.inline.} =
|
||||
result = if c in {'A'..'Z'}: chr(ord(c)-ord('A')+ord('a')) else: c
|
||||
|
||||
proc parseBin*[T: SomeInteger](s: string, number: var T, start = 0, maxLen = 0): int
|
||||
{.noSideEffect.} =
|
||||
proc parseBin*[T: SomeInteger](s: string, number: var T, start = 0,
|
||||
maxLen = 0): int {.noSideEffect.} =
|
||||
## Parses a binary number and stores its value in ``number``.
|
||||
##
|
||||
## Returns the number of the parsed characters or 0 in case of an error.
|
||||
|
|
@ -111,8 +111,8 @@ proc parseBin*[T: SomeInteger](s: string, number: var T, start = 0, maxLen = 0):
|
|||
number = output
|
||||
result = i - start
|
||||
|
||||
proc parseOct*[T: SomeInteger](s: string, number: var T, start = 0, maxLen = 0): int
|
||||
{.noSideEffect.} =
|
||||
proc parseOct*[T: SomeInteger](s: string, number: var T, start = 0,
|
||||
maxLen = 0): int {.noSideEffect.} =
|
||||
## Parses an octal number and stores its value in ``number``.
|
||||
##
|
||||
## Returns the number of the parsed characters or 0 in case of an error.
|
||||
|
|
@ -158,8 +158,8 @@ proc parseOct*[T: SomeInteger](s: string, number: var T, start = 0, maxLen = 0):
|
|||
number = output
|
||||
result = i - start
|
||||
|
||||
proc parseHex*[T: SomeInteger](s: string, number: var T, start = 0, maxLen = 0): int
|
||||
{.noSideEffect.} =
|
||||
proc parseHex*[T: SomeInteger](s: string, number: var T, start = 0,
|
||||
maxLen = 0): int {.noSideEffect.} =
|
||||
## Parses a hexadecimal number and stores its value in ``number``.
|
||||
##
|
||||
## Returns the number of the parsed characters or 0 in case of an error.
|
||||
|
|
|
|||
|
|
@ -711,8 +711,9 @@ proc rawGetTok(my: var XmlParser) =
|
|||
of '/':
|
||||
parseEndTag(my)
|
||||
of '!':
|
||||
if my.buf[pos+2] == '[' and my.buf[pos+3] == 'C' and my.buf[pos+4] == 'D' and
|
||||
my.buf[pos+5] == 'A' and my.buf[pos+6] == 'T' and my.buf[pos+7] == 'A' and
|
||||
if my.buf[pos+2] == '[' and my.buf[pos+3] == 'C' and
|
||||
my.buf[pos+4] == 'D' and my.buf[pos+5] == 'A' and
|
||||
my.buf[pos+6] == 'T' and my.buf[pos+7] == 'A' and
|
||||
my.buf[pos+8] == '[':
|
||||
parseCDATA(my)
|
||||
elif my.buf[pos+2] == '-' and my.buf[pos+3] == '-':
|
||||
|
|
@ -742,7 +743,8 @@ proc getTok(my: var XmlParser) =
|
|||
of xmlComment:
|
||||
if my.options.contains(reportComments): break
|
||||
of xmlWhitespace:
|
||||
if my.options.contains(reportWhitespace) or lastKind in {xmlCharData, xmlComment, xmlEntity}:
|
||||
if my.options.contains(reportWhitespace) or lastKind in {xmlCharData,
|
||||
xmlComment, xmlEntity}:
|
||||
break
|
||||
else: break
|
||||
|
||||
|
|
|
|||
|
|
@ -169,4 +169,5 @@ when isMainModule:
|
|||
|
||||
block bug1518:
|
||||
var err: seq[string] = @[]
|
||||
assert $parsexml(newStringStream"<tag>One & two</tag>", "temp.xml", err) == "<tag>One & two</tag>"
|
||||
assert $parsexml(newStringStream"<tag>One & two</tag>", "temp.xml",
|
||||
err) == "<tag>One & two</tag>"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue