code generator supports constant sequences; more consistent compile time evaluation
This commit is contained in:
parent
e9b7d5e68e
commit
42516c0086
18 changed files with 180 additions and 137 deletions
|
|
@ -362,7 +362,7 @@ static N_INLINE(NI32, float32ToInt32)(float val) {
|
|||
#define STRING_LITERAL(name, str, length) \
|
||||
static const struct { \
|
||||
TGenericSeq Sup; \
|
||||
NIM_CHAR data[length + 1]; \
|
||||
NIM_CHAR data[(length) + 1]; \
|
||||
} name = {{length, length}, str}
|
||||
|
||||
typedef struct TStringDesc* string;
|
||||
|
|
|
|||
|
|
@ -1651,20 +1651,20 @@ proc peg*(pattern: string): TPeg =
|
|||
## peg"{\ident} \s* '=' \s* {.*}"
|
||||
result = parsePeg(pattern, "pattern")
|
||||
|
||||
proc escapePeg*(s: string): string =
|
||||
proc escapePeg*(s: string): string =
|
||||
## escapes `s` so that it is matched verbatim when used as a peg.
|
||||
result = ""
|
||||
var inQuote = false
|
||||
for c in items(s):
|
||||
for c in items(s):
|
||||
case c
|
||||
of '\0'..'\31', '\'', '"', '\\':
|
||||
if inQuote:
|
||||
of '\0'..'\31', '\'', '"', '\\':
|
||||
if inQuote:
|
||||
result.add('\'')
|
||||
inQuote = false
|
||||
result.add("\\x")
|
||||
result.add(toHex(ord(c), 2))
|
||||
else:
|
||||
if not inQuote:
|
||||
if not inQuote:
|
||||
result.add('\'')
|
||||
inQuote = true
|
||||
result.add(c)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue