minor style changes
This commit is contained in:
parent
b2f9447896
commit
38bdf1cd7f
11 changed files with 60 additions and 56 deletions
|
|
@ -110,7 +110,7 @@ proc differs(conf: ConfigRef; info: TLineInfo; newName: string): string =
|
||||||
#inc first, skipIgnoreCase(line, "proc ", first)
|
#inc first, skipIgnoreCase(line, "proc ", first)
|
||||||
while first > 0 and line[first-1] in Letters: dec first
|
while first > 0 and line[first-1] in Letters: dec first
|
||||||
if first < 0: return
|
if first < 0: return
|
||||||
if line[first] == '`': inc first
|
if first+1 < line.len and line[first] == '`': inc first
|
||||||
|
|
||||||
let last = first+identLen(line, first)-1
|
let last = first+identLen(line, first)-1
|
||||||
result = differ(line, first, last, newName)
|
result = differ(line, first, last, newName)
|
||||||
|
|
|
||||||
2
koch.nim
2
koch.nim
|
|
@ -287,7 +287,7 @@ proc boot(args: string) =
|
||||||
# default to use the 'c' command:
|
# default to use the 'c' command:
|
||||||
let useCpp = getEnv("NIM_COMPILE_TO_CPP", "false") == "true"
|
let useCpp = getEnv("NIM_COMPILE_TO_CPP", "false") == "true"
|
||||||
let smartNimcache = (if "release" in args or "danger" in args: "nimcache/r_" else: "nimcache/d_") &
|
let smartNimcache = (if "release" in args or "danger" in args: "nimcache/r_" else: "nimcache/d_") &
|
||||||
hostOs & "_" & hostCpu
|
hostOS & "_" & hostCPU
|
||||||
|
|
||||||
let nimStart = findStartNim()
|
let nimStart = findStartNim()
|
||||||
for i in 0..2:
|
for i in 0..2:
|
||||||
|
|
|
||||||
|
|
@ -1741,7 +1741,7 @@ iterator mvalues*[A, B](t: var OrderedTable[A, B]): var B =
|
||||||
# --------------------------- OrderedTableRef -------------------------------
|
# --------------------------- OrderedTableRef -------------------------------
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
proc newOrderedTable*[A, B](initialsize = defaultInitialSize): <//>OrderedTableRef[A, B] =
|
proc newOrderedTable*[A, B](initialSize = defaultInitialSize): <//>OrderedTableRef[A, B] =
|
||||||
## Creates a new ordered ref hash table that is empty.
|
## Creates a new ordered ref hash table that is empty.
|
||||||
##
|
##
|
||||||
## ``initialSize`` must be a power of two (default: 64).
|
## ``initialSize`` must be a power of two (default: 64).
|
||||||
|
|
@ -2502,7 +2502,7 @@ iterator mvalues*[A](t: var CountTable[A]): var int =
|
||||||
|
|
||||||
proc inc*[A](t: CountTableRef[A], key: A, val = 1)
|
proc inc*[A](t: CountTableRef[A], key: A, val = 1)
|
||||||
|
|
||||||
proc newCountTable*[A](initialsize = defaultInitialSize): <//>CountTableRef[A] =
|
proc newCountTable*[A](initialSize = defaultInitialSize): <//>CountTableRef[A] =
|
||||||
## Creates a new ref count table that is empty.
|
## Creates a new ref count table that is empty.
|
||||||
##
|
##
|
||||||
## ``initialSize`` must be a power of two (default: 64).
|
## ``initialSize`` must be a power of two (default: 64).
|
||||||
|
|
|
||||||
|
|
@ -562,7 +562,7 @@ proc writeConfig*(dict: Config, filename: string) =
|
||||||
|
|
||||||
proc getSectionValue*(dict: Config, section, key: string): string =
|
proc getSectionValue*(dict: Config, section, key: string): string =
|
||||||
## Gets the Key value of the specified Section.
|
## Gets the Key value of the specified Section.
|
||||||
if dict.haskey(section):
|
if dict.hasKey(section):
|
||||||
if dict[section].hasKey(key):
|
if dict[section].hasKey(key):
|
||||||
result = dict[section][key]
|
result = dict[section][key]
|
||||||
else:
|
else:
|
||||||
|
|
@ -584,9 +584,9 @@ proc delSection*(dict: var Config, section: string) =
|
||||||
|
|
||||||
proc delSectionKey*(dict: var Config, section, key: string) =
|
proc delSectionKey*(dict: var Config, section, key: string) =
|
||||||
## Delete the key of the specified section.
|
## Delete the key of the specified section.
|
||||||
if dict.haskey(section):
|
if dict.hasKey(section):
|
||||||
if dict[section].hasKey(key):
|
if dict[section].hasKey(key):
|
||||||
if dict[section].len() == 1:
|
if dict[section].len == 1:
|
||||||
dict.del(section)
|
dict.del(section)
|
||||||
else:
|
else:
|
||||||
dict[section].del(key)
|
dict[section].del(key)
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ proc rule*(nt: NonTerminal): Peg = nt.rule
|
||||||
## Gets the *Peg* object representing the rule definition of the parent *Peg*
|
## Gets the *Peg* object representing the rule definition of the parent *Peg*
|
||||||
## object variant of a given *NonTerminal*.
|
## object variant of a given *NonTerminal*.
|
||||||
|
|
||||||
proc term*(t: string): Peg {.nosideEffect, rtl, extern: "npegs$1Str".} =
|
proc term*(t: string): Peg {.noSideEffect, rtl, extern: "npegs$1Str".} =
|
||||||
## constructs a PEG from a terminal string
|
## constructs a PEG from a terminal string
|
||||||
if t.len != 1:
|
if t.len != 1:
|
||||||
result = Peg(kind: pkTerminal, term: t)
|
result = Peg(kind: pkTerminal, term: t)
|
||||||
|
|
@ -147,21 +147,21 @@ proc term*(t: string): Peg {.nosideEffect, rtl, extern: "npegs$1Str".} =
|
||||||
result = Peg(kind: pkChar, ch: t[0])
|
result = Peg(kind: pkChar, ch: t[0])
|
||||||
|
|
||||||
proc termIgnoreCase*(t: string): Peg {.
|
proc termIgnoreCase*(t: string): Peg {.
|
||||||
nosideEffect, rtl, extern: "npegs$1".} =
|
noSideEffect, rtl, extern: "npegs$1".} =
|
||||||
## constructs a PEG from a terminal string; ignore case for matching
|
## constructs a PEG from a terminal string; ignore case for matching
|
||||||
result = Peg(kind: pkTerminalIgnoreCase, term: t)
|
result = Peg(kind: pkTerminalIgnoreCase, term: t)
|
||||||
|
|
||||||
proc termIgnoreStyle*(t: string): Peg {.
|
proc termIgnoreStyle*(t: string): Peg {.
|
||||||
nosideEffect, rtl, extern: "npegs$1".} =
|
noSideEffect, rtl, extern: "npegs$1".} =
|
||||||
## constructs a PEG from a terminal string; ignore style for matching
|
## constructs a PEG from a terminal string; ignore style for matching
|
||||||
result = Peg(kind: pkTerminalIgnoreStyle, term: t)
|
result = Peg(kind: pkTerminalIgnoreStyle, term: t)
|
||||||
|
|
||||||
proc term*(t: char): Peg {.nosideEffect, rtl, extern: "npegs$1Char".} =
|
proc term*(t: char): Peg {.noSideEffect, rtl, extern: "npegs$1Char".} =
|
||||||
## constructs a PEG from a terminal char
|
## constructs a PEG from a terminal char
|
||||||
assert t != '\0'
|
assert t != '\0'
|
||||||
result = Peg(kind: pkChar, ch: t)
|
result = Peg(kind: pkChar, ch: t)
|
||||||
|
|
||||||
proc charSet*(s: set[char]): Peg {.nosideEffect, rtl, extern: "npegs$1".} =
|
proc charSet*(s: set[char]): Peg {.noSideEffect, rtl, extern: "npegs$1".} =
|
||||||
## constructs a PEG from a character set `s`
|
## constructs a PEG from a character set `s`
|
||||||
assert '\0' notin s
|
assert '\0' notin s
|
||||||
result = Peg(kind: pkCharChoice)
|
result = Peg(kind: pkCharChoice)
|
||||||
|
|
@ -195,7 +195,7 @@ template multipleOp(k: PegKind, localOpt: untyped) =
|
||||||
result = result.sons[0]
|
result = result.sons[0]
|
||||||
|
|
||||||
proc `/`*(a: varargs[Peg]): Peg {.
|
proc `/`*(a: varargs[Peg]): Peg {.
|
||||||
nosideEffect, rtl, extern: "npegsOrderedChoice".} =
|
noSideEffect, rtl, extern: "npegsOrderedChoice".} =
|
||||||
## constructs an ordered choice with the PEGs in `a`
|
## constructs an ordered choice with the PEGs in `a`
|
||||||
multipleOp(pkOrderedChoice, addChoice)
|
multipleOp(pkOrderedChoice, addChoice)
|
||||||
|
|
||||||
|
|
@ -212,11 +212,11 @@ proc addSequence(dest: var Peg, elem: Peg) =
|
||||||
else: add(dest, elem)
|
else: add(dest, elem)
|
||||||
|
|
||||||
proc sequence*(a: varargs[Peg]): Peg {.
|
proc sequence*(a: varargs[Peg]): Peg {.
|
||||||
nosideEffect, rtl, extern: "npegs$1".} =
|
noSideEffect, rtl, extern: "npegs$1".} =
|
||||||
## constructs a sequence with all the PEGs from `a`
|
## constructs a sequence with all the PEGs from `a`
|
||||||
multipleOp(pkSequence, addSequence)
|
multipleOp(pkSequence, addSequence)
|
||||||
|
|
||||||
proc `?`*(a: Peg): Peg {.nosideEffect, rtl, extern: "npegsOptional".} =
|
proc `?`*(a: Peg): Peg {.noSideEffect, rtl, extern: "npegsOptional".} =
|
||||||
## constructs an optional for the PEG `a`
|
## constructs an optional for the PEG `a`
|
||||||
if a.kind in {pkOption, pkGreedyRep, pkGreedyAny, pkGreedyRepChar,
|
if a.kind in {pkOption, pkGreedyRep, pkGreedyAny, pkGreedyRepChar,
|
||||||
pkGreedyRepSet}:
|
pkGreedyRepSet}:
|
||||||
|
|
@ -226,7 +226,7 @@ proc `?`*(a: Peg): Peg {.nosideEffect, rtl, extern: "npegsOptional".} =
|
||||||
else:
|
else:
|
||||||
result = Peg(kind: pkOption, sons: @[a])
|
result = Peg(kind: pkOption, sons: @[a])
|
||||||
|
|
||||||
proc `*`*(a: Peg): Peg {.nosideEffect, rtl, extern: "npegsGreedyRep".} =
|
proc `*`*(a: Peg): Peg {.noSideEffect, rtl, extern: "npegsGreedyRep".} =
|
||||||
## constructs a "greedy repetition" for the PEG `a`
|
## constructs a "greedy repetition" for the PEG `a`
|
||||||
case a.kind
|
case a.kind
|
||||||
of pkGreedyRep, pkGreedyRepChar, pkGreedyRepSet, pkGreedyAny, pkOption:
|
of pkGreedyRep, pkGreedyRepChar, pkGreedyRepSet, pkGreedyAny, pkOption:
|
||||||
|
|
@ -241,7 +241,7 @@ proc `*`*(a: Peg): Peg {.nosideEffect, rtl, extern: "npegsGreedyRep".} =
|
||||||
else:
|
else:
|
||||||
result = Peg(kind: pkGreedyRep, sons: @[a])
|
result = Peg(kind: pkGreedyRep, sons: @[a])
|
||||||
|
|
||||||
proc `!*`*(a: Peg): Peg {.nosideEffect, rtl, extern: "npegsSearch".} =
|
proc `!*`*(a: Peg): Peg {.noSideEffect, rtl, extern: "npegsSearch".} =
|
||||||
## constructs a "search" for the PEG `a`
|
## constructs a "search" for the PEG `a`
|
||||||
result = Peg(kind: pkSearch, sons: @[a])
|
result = Peg(kind: pkSearch, sons: @[a])
|
||||||
|
|
||||||
|
|
@ -250,15 +250,15 @@ proc `!*\`*(a: Peg): Peg {.noSideEffect, rtl,
|
||||||
## constructs a "captured search" for the PEG `a`
|
## constructs a "captured search" for the PEG `a`
|
||||||
result = Peg(kind: pkCapturedSearch, sons: @[a])
|
result = Peg(kind: pkCapturedSearch, sons: @[a])
|
||||||
|
|
||||||
proc `+`*(a: Peg): Peg {.nosideEffect, rtl, extern: "npegsGreedyPosRep".} =
|
proc `+`*(a: Peg): Peg {.noSideEffect, rtl, extern: "npegsGreedyPosRep".} =
|
||||||
## constructs a "greedy positive repetition" with the PEG `a`
|
## constructs a "greedy positive repetition" with the PEG `a`
|
||||||
return sequence(a, *a)
|
return sequence(a, *a)
|
||||||
|
|
||||||
proc `&`*(a: Peg): Peg {.nosideEffect, rtl, extern: "npegsAndPredicate".} =
|
proc `&`*(a: Peg): Peg {.noSideEffect, rtl, extern: "npegsAndPredicate".} =
|
||||||
## constructs an "and predicate" with the PEG `a`
|
## constructs an "and predicate" with the PEG `a`
|
||||||
result = Peg(kind: pkAndPredicate, sons: @[a])
|
result = Peg(kind: pkAndPredicate, sons: @[a])
|
||||||
|
|
||||||
proc `!`*(a: Peg): Peg {.nosideEffect, rtl, extern: "npegsNotPredicate".} =
|
proc `!`*(a: Peg): Peg {.noSideEffect, rtl, extern: "npegsNotPredicate".} =
|
||||||
## constructs a "not predicate" with the PEG `a`
|
## constructs a "not predicate" with the PEG `a`
|
||||||
result = Peg(kind: pkNotPredicate, sons: @[a])
|
result = Peg(kind: pkNotPredicate, sons: @[a])
|
||||||
|
|
||||||
|
|
@ -303,24 +303,24 @@ proc endAnchor*: Peg {.inline.} =
|
||||||
## constructs the PEG ``$`` which matches the end of the input.
|
## constructs the PEG ``$`` which matches the end of the input.
|
||||||
result = !any()
|
result = !any()
|
||||||
|
|
||||||
proc capture*(a: Peg): Peg {.nosideEffect, rtl, extern: "npegsCapture".} =
|
proc capture*(a: Peg): Peg {.noSideEffect, rtl, extern: "npegsCapture".} =
|
||||||
## constructs a capture with the PEG `a`
|
## constructs a capture with the PEG `a`
|
||||||
result = Peg(kind: pkCapture, sons: @[a])
|
result = Peg(kind: pkCapture, sons: @[a])
|
||||||
|
|
||||||
proc backref*(index: range[1..MaxSubpatterns]): Peg {.
|
proc backref*(index: range[1..MaxSubpatterns]): Peg {.
|
||||||
nosideEffect, rtl, extern: "npegs$1".} =
|
noSideEffect, rtl, extern: "npegs$1".} =
|
||||||
## constructs a back reference of the given `index`. `index` starts counting
|
## constructs a back reference of the given `index`. `index` starts counting
|
||||||
## from 1.
|
## from 1.
|
||||||
result = Peg(kind: pkBackRef, index: index-1)
|
result = Peg(kind: pkBackRef, index: index-1)
|
||||||
|
|
||||||
proc backrefIgnoreCase*(index: range[1..MaxSubpatterns]): Peg {.
|
proc backrefIgnoreCase*(index: range[1..MaxSubpatterns]): Peg {.
|
||||||
nosideEffect, rtl, extern: "npegs$1".} =
|
noSideEffect, rtl, extern: "npegs$1".} =
|
||||||
## constructs a back reference of the given `index`. `index` starts counting
|
## constructs a back reference of the given `index`. `index` starts counting
|
||||||
## from 1. Ignores case for matching.
|
## from 1. Ignores case for matching.
|
||||||
result = Peg(kind: pkBackRefIgnoreCase, index: index-1)
|
result = Peg(kind: pkBackRefIgnoreCase, index: index-1)
|
||||||
|
|
||||||
proc backrefIgnoreStyle*(index: range[1..MaxSubpatterns]): Peg {.
|
proc backrefIgnoreStyle*(index: range[1..MaxSubpatterns]): Peg {.
|
||||||
nosideEffect, rtl, extern: "npegs$1".}=
|
noSideEffect, rtl, extern: "npegs$1".}=
|
||||||
## constructs a back reference of the given `index`. `index` starts counting
|
## constructs a back reference of the given `index`. `index` starts counting
|
||||||
## from 1. Ignores style for matching.
|
## from 1. Ignores style for matching.
|
||||||
result = Peg(kind: pkBackRefIgnoreStyle, index: index-1)
|
result = Peg(kind: pkBackRefIgnoreStyle, index: index-1)
|
||||||
|
|
@ -341,7 +341,7 @@ proc spaceCost(n: Peg): int =
|
||||||
if result >= InlineThreshold: break
|
if result >= InlineThreshold: break
|
||||||
|
|
||||||
proc nonterminal*(n: NonTerminal): Peg {.
|
proc nonterminal*(n: NonTerminal): Peg {.
|
||||||
nosideEffect, rtl, extern: "npegs$1".} =
|
noSideEffect, rtl, extern: "npegs$1".} =
|
||||||
## constructs a PEG that consists of the nonterminal symbol
|
## constructs a PEG that consists of the nonterminal symbol
|
||||||
assert n != nil
|
assert n != nil
|
||||||
if ntDeclared in n.flags and spaceCost(n.rule) < InlineThreshold:
|
if ntDeclared in n.flags and spaceCost(n.rule) < InlineThreshold:
|
||||||
|
|
@ -351,7 +351,7 @@ proc nonterminal*(n: NonTerminal): Peg {.
|
||||||
result = Peg(kind: pkNonTerminal, nt: n)
|
result = Peg(kind: pkNonTerminal, nt: n)
|
||||||
|
|
||||||
proc newNonTerminal*(name: string, line, column: int): NonTerminal {.
|
proc newNonTerminal*(name: string, line, column: int): NonTerminal {.
|
||||||
nosideEffect, rtl, extern: "npegs$1".} =
|
noSideEffect, rtl, extern: "npegs$1".} =
|
||||||
## constructs a nonterminal symbol
|
## constructs a nonterminal symbol
|
||||||
result = NonTerminal(name: name, line: line, col: column)
|
result = NonTerminal(name: name, line: line, col: column)
|
||||||
|
|
||||||
|
|
@ -518,7 +518,7 @@ proc toStrAux(r: Peg, res: var string) =
|
||||||
of pkStartAnchor:
|
of pkStartAnchor:
|
||||||
add(res, '^')
|
add(res, '^')
|
||||||
|
|
||||||
proc `$` *(r: Peg): string {.nosideEffect, rtl, extern: "npegsToString".} =
|
proc `$` *(r: Peg): string {.noSideEffect, rtl, extern: "npegsToString".} =
|
||||||
## converts a PEG to its string representation
|
## converts a PEG to its string representation
|
||||||
result = ""
|
result = ""
|
||||||
toStrAux(r, result)
|
toStrAux(r, result)
|
||||||
|
|
@ -1058,7 +1058,7 @@ template fillMatches(s, caps, c) =
|
||||||
caps[k] = ""
|
caps[k] = ""
|
||||||
|
|
||||||
proc matchLen*(s: string, pattern: Peg, matches: var openArray[string],
|
proc matchLen*(s: string, pattern: Peg, matches: var openArray[string],
|
||||||
start = 0): int {.nosideEffect, rtl, extern: "npegs$1Capture".} =
|
start = 0): int {.noSideEffect, rtl, extern: "npegs$1Capture".} =
|
||||||
## the same as ``match``, but it returns the length of the match,
|
## the same as ``match``, but it returns the length of the match,
|
||||||
## if there is no match, -1 is returned. Note that a match length
|
## if there is no match, -1 is returned. Note that a match length
|
||||||
## of zero can happen. It's possible that a suffix of `s` remains
|
## of zero can happen. It's possible that a suffix of `s` remains
|
||||||
|
|
@ -1069,7 +1069,7 @@ proc matchLen*(s: string, pattern: Peg, matches: var openArray[string],
|
||||||
if result >= 0: fillMatches(s, matches, c)
|
if result >= 0: fillMatches(s, matches, c)
|
||||||
|
|
||||||
proc matchLen*(s: string, pattern: Peg,
|
proc matchLen*(s: string, pattern: Peg,
|
||||||
start = 0): int {.nosideEffect, rtl, extern: "npegs$1".} =
|
start = 0): int {.noSideEffect, rtl, extern: "npegs$1".} =
|
||||||
## the same as ``match``, but it returns the length of the match,
|
## the same as ``match``, but it returns the length of the match,
|
||||||
## if there is no match, -1 is returned. Note that a match length
|
## if there is no match, -1 is returned. Note that a match length
|
||||||
## of zero can happen. It's possible that a suffix of `s` remains
|
## of zero can happen. It's possible that a suffix of `s` remains
|
||||||
|
|
@ -1079,7 +1079,7 @@ proc matchLen*(s: string, pattern: Peg,
|
||||||
result = rawMatch(s, pattern, start, c)
|
result = rawMatch(s, pattern, start, c)
|
||||||
|
|
||||||
proc match*(s: string, pattern: Peg, matches: var openArray[string],
|
proc match*(s: string, pattern: Peg, matches: var openArray[string],
|
||||||
start = 0): bool {.nosideEffect, rtl, extern: "npegs$1Capture".} =
|
start = 0): bool {.noSideEffect, rtl, extern: "npegs$1Capture".} =
|
||||||
## returns ``true`` if ``s[start..]`` matches the ``pattern`` and
|
## returns ``true`` if ``s[start..]`` matches the ``pattern`` and
|
||||||
## the captured substrings in the array ``matches``. If it does not
|
## the captured substrings in the array ``matches``. If it does not
|
||||||
## match, nothing is written into ``matches`` and ``false`` is
|
## match, nothing is written into ``matches`` and ``false`` is
|
||||||
|
|
@ -1087,13 +1087,13 @@ proc match*(s: string, pattern: Peg, matches: var openArray[string],
|
||||||
result = matchLen(s, pattern, matches, start) != -1
|
result = matchLen(s, pattern, matches, start) != -1
|
||||||
|
|
||||||
proc match*(s: string, pattern: Peg,
|
proc match*(s: string, pattern: Peg,
|
||||||
start = 0): bool {.nosideEffect, rtl, extern: "npegs$1".} =
|
start = 0): bool {.noSideEffect, rtl, extern: "npegs$1".} =
|
||||||
## returns ``true`` if ``s`` matches the ``pattern`` beginning from ``start``.
|
## returns ``true`` if ``s`` matches the ``pattern`` beginning from ``start``.
|
||||||
result = matchLen(s, pattern, start) != -1
|
result = matchLen(s, pattern, start) != -1
|
||||||
|
|
||||||
|
|
||||||
proc find*(s: string, pattern: Peg, matches: var openArray[string],
|
proc find*(s: string, pattern: Peg, matches: var openArray[string],
|
||||||
start = 0): int {.nosideEffect, rtl, extern: "npegs$1Capture".} =
|
start = 0): int {.noSideEffect, rtl, extern: "npegs$1Capture".} =
|
||||||
## returns the starting position of ``pattern`` in ``s`` and the captured
|
## returns the starting position of ``pattern`` in ``s`` and the captured
|
||||||
## substrings in the array ``matches``. If it does not match, nothing
|
## substrings in the array ``matches``. If it does not match, nothing
|
||||||
## is written into ``matches`` and -1 is returned.
|
## is written into ``matches`` and -1 is returned.
|
||||||
|
|
@ -1109,7 +1109,7 @@ proc find*(s: string, pattern: Peg, matches: var openArray[string],
|
||||||
|
|
||||||
proc findBounds*(s: string, pattern: Peg, matches: var openArray[string],
|
proc findBounds*(s: string, pattern: Peg, matches: var openArray[string],
|
||||||
start = 0): tuple[first, last: int] {.
|
start = 0): tuple[first, last: int] {.
|
||||||
nosideEffect, rtl, extern: "npegs$1Capture".} =
|
noSideEffect, rtl, extern: "npegs$1Capture".} =
|
||||||
## returns the starting position and end position of ``pattern`` in ``s``
|
## returns the starting position and end position of ``pattern`` in ``s``
|
||||||
## and the captured
|
## and the captured
|
||||||
## substrings in the array ``matches``. If it does not match, nothing
|
## substrings in the array ``matches``. If it does not match, nothing
|
||||||
|
|
@ -1125,7 +1125,7 @@ proc findBounds*(s: string, pattern: Peg, matches: var openArray[string],
|
||||||
return (-1, 0)
|
return (-1, 0)
|
||||||
|
|
||||||
proc find*(s: string, pattern: Peg,
|
proc find*(s: string, pattern: Peg,
|
||||||
start = 0): int {.nosideEffect, rtl, extern: "npegs$1".} =
|
start = 0): int {.noSideEffect, rtl, extern: "npegs$1".} =
|
||||||
## returns the starting position of ``pattern`` in ``s``. If it does not
|
## returns the starting position of ``pattern`` in ``s``. If it does not
|
||||||
## match, -1 is returned.
|
## match, -1 is returned.
|
||||||
var c: Captures
|
var c: Captures
|
||||||
|
|
@ -1149,7 +1149,7 @@ iterator findAll*(s: string, pattern: Peg, start = 0): string =
|
||||||
inc(i, L)
|
inc(i, L)
|
||||||
|
|
||||||
proc findAll*(s: string, pattern: Peg, start = 0): seq[string] {.
|
proc findAll*(s: string, pattern: Peg, start = 0): seq[string] {.
|
||||||
nosideEffect, rtl, extern: "npegs$1".} =
|
noSideEffect, rtl, extern: "npegs$1".} =
|
||||||
## returns all matching *substrings* of `s` that match `pattern`.
|
## returns all matching *substrings* of `s` that match `pattern`.
|
||||||
## If it does not match, @[] is returned.
|
## If it does not match, @[] is returned.
|
||||||
accumulateResult(findAll(s, pattern, start))
|
accumulateResult(findAll(s, pattern, start))
|
||||||
|
|
@ -1183,22 +1183,22 @@ template `=~`*(s: string, pattern: Peg): bool =
|
||||||
# ------------------------- more string handling ------------------------------
|
# ------------------------- more string handling ------------------------------
|
||||||
|
|
||||||
proc contains*(s: string, pattern: Peg, start = 0): bool {.
|
proc contains*(s: string, pattern: Peg, start = 0): bool {.
|
||||||
nosideEffect, rtl, extern: "npegs$1".} =
|
noSideEffect, rtl, extern: "npegs$1".} =
|
||||||
## same as ``find(s, pattern, start) >= 0``
|
## same as ``find(s, pattern, start) >= 0``
|
||||||
return find(s, pattern, start) >= 0
|
return find(s, pattern, start) >= 0
|
||||||
|
|
||||||
proc contains*(s: string, pattern: Peg, matches: var openArray[string],
|
proc contains*(s: string, pattern: Peg, matches: var openArray[string],
|
||||||
start = 0): bool {.nosideEffect, rtl, extern: "npegs$1Capture".} =
|
start = 0): bool {.noSideEffect, rtl, extern: "npegs$1Capture".} =
|
||||||
## same as ``find(s, pattern, matches, start) >= 0``
|
## same as ``find(s, pattern, matches, start) >= 0``
|
||||||
return find(s, pattern, matches, start) >= 0
|
return find(s, pattern, matches, start) >= 0
|
||||||
|
|
||||||
proc startsWith*(s: string, prefix: Peg, start = 0): bool {.
|
proc startsWith*(s: string, prefix: Peg, start = 0): bool {.
|
||||||
nosideEffect, rtl, extern: "npegs$1".} =
|
noSideEffect, rtl, extern: "npegs$1".} =
|
||||||
## returns true if `s` starts with the pattern `prefix`
|
## returns true if `s` starts with the pattern `prefix`
|
||||||
result = matchLen(s, prefix, start) >= 0
|
result = matchLen(s, prefix, start) >= 0
|
||||||
|
|
||||||
proc endsWith*(s: string, suffix: Peg, start = 0): bool {.
|
proc endsWith*(s: string, suffix: Peg, start = 0): bool {.
|
||||||
nosideEffect, rtl, extern: "npegs$1".} =
|
noSideEffect, rtl, extern: "npegs$1".} =
|
||||||
## returns true if `s` ends with the pattern `suffix`
|
## returns true if `s` ends with the pattern `suffix`
|
||||||
var c: Captures
|
var c: Captures
|
||||||
c.origStart = start
|
c.origStart = start
|
||||||
|
|
@ -1206,7 +1206,7 @@ proc endsWith*(s: string, suffix: Peg, start = 0): bool {.
|
||||||
if rawMatch(s, suffix, i, c) == s.len - i: return true
|
if rawMatch(s, suffix, i, c) == s.len - i: return true
|
||||||
|
|
||||||
proc replacef*(s: string, sub: Peg, by: string): string {.
|
proc replacef*(s: string, sub: Peg, by: string): string {.
|
||||||
nosideEffect, rtl, extern: "npegs$1".} =
|
noSideEffect, rtl, extern: "npegs$1".} =
|
||||||
## Replaces `sub` in `s` by the string `by`. Captures can be accessed in `by`
|
## Replaces `sub` in `s` by the string `by`. Captures can be accessed in `by`
|
||||||
## with the notation ``$i`` and ``$#`` (see strutils.`%`). Examples:
|
## with the notation ``$i`` and ``$#`` (see strutils.`%`). Examples:
|
||||||
##
|
##
|
||||||
|
|
@ -1235,7 +1235,7 @@ proc replacef*(s: string, sub: Peg, by: string): string {.
|
||||||
add(result, substr(s, i))
|
add(result, substr(s, i))
|
||||||
|
|
||||||
proc replace*(s: string, sub: Peg, by = ""): string {.
|
proc replace*(s: string, sub: Peg, by = ""): string {.
|
||||||
nosideEffect, rtl, extern: "npegs$1".} =
|
noSideEffect, rtl, extern: "npegs$1".} =
|
||||||
## Replaces `sub` in `s` by the string `by`. Captures cannot be accessed
|
## Replaces `sub` in `s` by the string `by`. Captures cannot be accessed
|
||||||
## in `by`.
|
## in `by`.
|
||||||
result = ""
|
result = ""
|
||||||
|
|
@ -1253,7 +1253,7 @@ proc replace*(s: string, sub: Peg, by = ""): string {.
|
||||||
|
|
||||||
proc parallelReplace*(s: string, subs: varargs[
|
proc parallelReplace*(s: string, subs: varargs[
|
||||||
tuple[pattern: Peg, repl: string]]): string {.
|
tuple[pattern: Peg, repl: string]]): string {.
|
||||||
nosideEffect, rtl, extern: "npegs$1".} =
|
noSideEffect, rtl, extern: "npegs$1".} =
|
||||||
## Returns a modified copy of `s` with the substitutions in `subs`
|
## Returns a modified copy of `s` with the substitutions in `subs`
|
||||||
## applied in parallel.
|
## applied in parallel.
|
||||||
result = ""
|
result = ""
|
||||||
|
|
@ -1368,7 +1368,7 @@ iterator split*(s: string, sep: Peg): string =
|
||||||
yield substr(s, first, last-1)
|
yield substr(s, first, last-1)
|
||||||
|
|
||||||
proc split*(s: string, sep: Peg): seq[string] {.
|
proc split*(s: string, sep: Peg): seq[string] {.
|
||||||
nosideEffect, rtl, extern: "npegs$1".} =
|
noSideEffect, rtl, extern: "npegs$1".} =
|
||||||
## Splits the string `s` into substrings.
|
## Splits the string `s` into substrings.
|
||||||
accumulateResult(split(s, sep))
|
accumulateResult(split(s, sep))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ proc regSetValue(key: HKEY, lpSubKey, lpValueName: WideCString,
|
||||||
dwType: int32; lpData: WideCString; cbData: int32): int32 {.
|
dwType: int32; lpData: WideCString; cbData: int32): int32 {.
|
||||||
importc: "RegSetKeyValueW", dynlib: "Advapi32.dll", stdcall.}
|
importc: "RegSetKeyValueW", dynlib: "Advapi32.dll", stdcall.}
|
||||||
|
|
||||||
proc setUnicodeValue*(path, key, val: string; handle: HKey) =
|
proc setUnicodeValue*(path, key, val: string; handle: HKEY) =
|
||||||
let hh = newWideCString path
|
let hh = newWideCString path
|
||||||
let kk = newWideCString key
|
let kk = newWideCString key
|
||||||
let vv = newWideCString val
|
let vv = newWideCString val
|
||||||
|
|
|
||||||
|
|
@ -263,6 +263,8 @@ type
|
||||||
JitStack16* = object
|
JitStack16* = object
|
||||||
JitStack32* = object
|
JitStack32* = object
|
||||||
|
|
||||||
|
when defined(nimHasStyleChecks):
|
||||||
|
{.push styleChecks: off.}
|
||||||
|
|
||||||
## The structure for passing additional data to pcre_exec(). This is defined in
|
## The structure for passing additional data to pcre_exec(). This is defined in
|
||||||
## such as way as to be extensible. Always add new fields at the end, in order
|
## such as way as to be extensible. Always add new fields at the end, in order
|
||||||
|
|
@ -302,6 +304,8 @@ type
|
||||||
mark* : pointer ## Pointer to current mark or NULL
|
mark* : pointer ## Pointer to current mark or NULL
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
when defined(nimHasStyleChecks):
|
||||||
|
{.pop.}
|
||||||
|
|
||||||
## User defined callback which provides a stack just before the match starts.
|
## User defined callback which provides a stack just before the match starts.
|
||||||
type
|
type
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,9 @@ proc process(dir, infile: string, outfile: File,
|
||||||
proc main(dir, outfile: string) =
|
proc main(dir, outfile: string) =
|
||||||
var o: File
|
var o: File
|
||||||
if open(o, outfile, fmWrite):
|
if open(o, outfile, fmWrite):
|
||||||
var processed = initSet[string]()
|
var processed = initHashSet[string]()
|
||||||
processed.incl(outfile)
|
processed.incl(outfile)
|
||||||
for infile in walkfiles(dir / "*.c"):
|
for infile in walkFiles(dir / "*.c"):
|
||||||
discard process(dir, extractFilename(infile), o, processed)
|
discard process(dir, extractFilename(infile), o, processed)
|
||||||
close(o)
|
close(o)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ proc findNim*(): string =
|
||||||
proc exec*(cmd: string, errorcode: int = QuitFailure, additionalPath = "") =
|
proc exec*(cmd: string, errorcode: int = QuitFailure, additionalPath = "") =
|
||||||
let prevPath = getEnv("PATH")
|
let prevPath = getEnv("PATH")
|
||||||
if additionalPath.len > 0:
|
if additionalPath.len > 0:
|
||||||
var absolute = additionalPATH
|
var absolute = additionalPath
|
||||||
if not absolute.isAbsolute:
|
if not absolute.isAbsolute:
|
||||||
absolute = getCurrentDir() / absolute
|
absolute = getCurrentDir() / absolute
|
||||||
echo("Adding to $PATH: ", absolute)
|
echo("Adding to $PATH: ", absolute)
|
||||||
|
|
@ -57,10 +57,10 @@ proc execCleanPath*(cmd: string,
|
||||||
# simulate a poor man's virtual environment
|
# simulate a poor man's virtual environment
|
||||||
let prevPath = getEnv("PATH")
|
let prevPath = getEnv("PATH")
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
let CleanPath = r"$1\system32;$1;$1\System32\Wbem" % getEnv"SYSTEMROOT"
|
let cleanPath = r"$1\system32;$1;$1\System32\Wbem" % getEnv"SYSTEMROOT"
|
||||||
else:
|
else:
|
||||||
const CleanPath = r"/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin"
|
const cleanPath = r"/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin"
|
||||||
putEnv("PATH", CleanPath & PathSep & additionalPath)
|
putEnv("PATH", cleanPath & PathSep & additionalPath)
|
||||||
echo(cmd)
|
echo(cmd)
|
||||||
if execShellCmd(cmd) != 0: quit("FAILURE", errorcode)
|
if execShellCmd(cmd) != 0: quit("FAILURE", errorcode)
|
||||||
putEnv("PATH", prevPath)
|
putEnv("PATH", prevPath)
|
||||||
|
|
@ -280,14 +280,14 @@ lib/wrappers/odbcsql.nim
|
||||||
lib/js/jscore.nim
|
lib/js/jscore.nim
|
||||||
""".splitWhitespace()
|
""".splitWhitespace()
|
||||||
|
|
||||||
proc sexec(cmds: openarray[string]) =
|
proc sexec(cmds: openArray[string]) =
|
||||||
## Serial queue wrapper around exec.
|
## Serial queue wrapper around exec.
|
||||||
for cmd in cmds:
|
for cmd in cmds:
|
||||||
echo(cmd)
|
echo(cmd)
|
||||||
let (outp, exitCode) = osproc.execCmdEx(cmd)
|
let (outp, exitCode) = osproc.execCmdEx(cmd)
|
||||||
if exitCode != 0: quit outp
|
if exitCode != 0: quit outp
|
||||||
|
|
||||||
proc mexec(cmds: openarray[string]) =
|
proc mexec(cmds: openArray[string]) =
|
||||||
## Multiprocessor version of exec
|
## Multiprocessor version of exec
|
||||||
let r = execProcesses(cmds, {poStdErrToStdOut, poParentStreams, poEchoCmd})
|
let r = execProcesses(cmds, {poStdErrToStdOut, poParentStreams, poEchoCmd})
|
||||||
if r != 0:
|
if r != 0:
|
||||||
|
|
|
||||||
|
|
@ -89,14 +89,14 @@ proc countLines(s: string, first, last: int): int =
|
||||||
proc beforePattern(s: string, first: int): int =
|
proc beforePattern(s: string, first: int): int =
|
||||||
result = first-1
|
result = first-1
|
||||||
while result >= 0:
|
while result >= 0:
|
||||||
if s[result] in NewLines: break
|
if s[result] in Newlines: break
|
||||||
dec(result)
|
dec(result)
|
||||||
inc(result)
|
inc(result)
|
||||||
|
|
||||||
proc afterPattern(s: string, last: int): int =
|
proc afterPattern(s: string, last: int): int =
|
||||||
result = last+1
|
result = last+1
|
||||||
while result < s.len:
|
while result < s.len:
|
||||||
if s[result] in NewLines: break
|
if s[result] in Newlines: break
|
||||||
inc(result)
|
inc(result)
|
||||||
dec(result)
|
dec(result)
|
||||||
|
|
||||||
|
|
@ -280,7 +280,7 @@ for kind, key, val in getopt():
|
||||||
replacement = key
|
replacement = key
|
||||||
else:
|
else:
|
||||||
filenames.add(key)
|
filenames.add(key)
|
||||||
of cmdLongoption, cmdShortOption:
|
of cmdLongOption, cmdShortOption:
|
||||||
case normalize(key)
|
case normalize(key)
|
||||||
of "find", "f": incl(options, optFind)
|
of "find", "f": incl(options, optFind)
|
||||||
of "replace", "r": incl(options, optReplace)
|
of "replace", "r": incl(options, optReplace)
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ proc parseCmdLine(c: var ConfigData) =
|
||||||
c.infile = addFileExt(key.string, "ini")
|
c.infile = addFileExt(key.string, "ini")
|
||||||
c.nimArgs = cmdLineRest(p).string
|
c.nimArgs = cmdLineRest(p).string
|
||||||
break
|
break
|
||||||
of cmdLongoption, cmdShortOption:
|
of cmdLongOption, cmdShortOption:
|
||||||
case normalize(key.string)
|
case normalize(key.string)
|
||||||
of "help", "h":
|
of "help", "h":
|
||||||
stdout.write(Usage)
|
stdout.write(Usage)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue