code generator supports constant sequences; more consistent compile time evaluation

This commit is contained in:
Araq 2011-10-07 09:02:08 +02:00
commit 42516c0086
18 changed files with 180 additions and 137 deletions

View file

@ -8,8 +8,8 @@
#
## This module contains various string utility routines.
## See the module `re` for regular expression support.
## See the module `pegs` for PEG support.
## See the module `re <re.html>`_ for regular expression support.
## See the module `pegs <pegs.html>`_ for PEG support.
import parseutils
@ -369,6 +369,19 @@ proc splitLines*(s: string): seq[string] {.noSideEffect,
## sequence of substrings.
accumulateResult(splitLines(s))
proc countLines*(s: string): int {.noSideEffect,
rtl, extern: "nsuCountLines".} =
## same as ``len(splitLines(s))``, but much more efficient.
var i = 0
while i < s.len:
case s[i]
of '\c':
if s[i+1] == '\l': inc i
inc result
of '\l': inc result
else: nil
inc i
proc split*(s: string, seps: set[char] = Whitespace): seq[string] {.
noSideEffect, rtl, extern: "nsuSplitCharSet".} =
## The same as the `split` iterator, but is a proc that returns a
@ -754,7 +767,7 @@ proc replace*(s: string, sub, by: char): string {.noSideEffect,
proc delete*(s: var string, first, last: int) {.noSideEffect,
rtl, extern: "nsuDelete".} =
## Deletes in `s` the characters at position `first`..`last`. This modifies
## Deletes in `s` the characters at position `first` .. `last`. This modifies
## `s` itself, it does not return a copy.
var i = first
var j = last+1
@ -865,8 +878,8 @@ proc validIdentifier*(s: string): bool {.noSideEffect,
proc editDistance*(a, b: string): int {.noSideEffect,
rtl, extern: "nsuEditDistance".} =
## returns the edit distance between `a` and `b`. This uses the
## `Levenshtein`:idx: distance algorithm with only a linear memory overhead.
## returns the edit distance between `a` and `b`. This uses the
## `Levenshtein`:idx: distance algorithm with only a linear memory overhead.
## This implementation is highly optimized!
var len1 = a.len
var len2 = b.len
@ -958,7 +971,7 @@ proc c_sprintf(buf, frmt: CString) {.nodecl, importc: "sprintf", varargs,
noSideEffect.}
type
TFloatFormat* = enum
TFloatFormat* = enum ## the different modes of floating point formating
ffDefault, ## use the shorter floating point notation
ffDecimal, ## use decimal floating point notation
ffScientific ## use scientific notation (using ``e`` character)