compilation cache: mostly working; generics not yet
This commit is contained in:
parent
9fb97e24bf
commit
9fb36bd20c
17 changed files with 160 additions and 2949 deletions
|
|
@ -274,30 +274,30 @@ type
|
|||
ikDollar, ## escaped ``$`` part of the interpolated string
|
||||
ikVar, ## ``var`` part of the interpolated string
|
||||
ikExpr ## ``expr`` part of the interpolated string
|
||||
|
||||
|
||||
iterator interpolatedFragments*(s: string): tuple[kind: TInterpolatedKind,
|
||||
value: string] =
|
||||
## Tokenizes the string `s` into substrings for interpolation purposes.
|
||||
##
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## for k, v in interpolatedFragments(" $this is ${an example} $$"):
|
||||
## echo "(", k, ", \"", v, "\")"
|
||||
##
|
||||
## Results in:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## (ikString, " ")
|
||||
## (ikExpr, "this")
|
||||
## (ikString, " is ")
|
||||
## (ikExpr, "an example")
|
||||
value: string] =
|
||||
## Tokenizes the string `s` into substrings for interpolation purposes.
|
||||
##
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## for k, v in interpolatedFragments(" $this is ${an example} $$"):
|
||||
## echo "(", k, ", \"", v, "\")"
|
||||
##
|
||||
## Results in:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## (ikString, " ")
|
||||
## (ikDollar, "$")
|
||||
## (ikExpr, "this")
|
||||
## (ikString, " is ")
|
||||
## (ikExpr, "an example")
|
||||
## (ikString, " ")
|
||||
## (ikDollar, "$")
|
||||
var i = 0
|
||||
var kind: TInterpolatedKind
|
||||
while true:
|
||||
var j = i
|
||||
var kind: TInterpolatedKind
|
||||
while true:
|
||||
var j = i
|
||||
if s[j] == '$':
|
||||
if s[j+1] == '{':
|
||||
inc j, 2
|
||||
|
|
@ -333,15 +333,15 @@ iterator interpolatedFragments*(s: string): tuple[kind: TInterpolatedKind,
|
|||
while j < s.len and s[j] != '$': inc j
|
||||
kind = ikStr
|
||||
if j > i:
|
||||
# do not copy the trailing } for ikExpr:
|
||||
yield (kind, substr(s, i, j-1-ord(kind == ikExpr)))
|
||||
else:
|
||||
break
|
||||
i = j
|
||||
# do not copy the trailing } for ikExpr:
|
||||
yield (kind, substr(s, i, j-1-ord(kind == ikExpr)))
|
||||
else:
|
||||
break
|
||||
i = j
|
||||
|
||||
when isMainModule:
|
||||
for k, v in interpolatedFragments("$test{} $this is ${an{ example}} "):
|
||||
echo "(", k, ", \"", v, "\")"
|
||||
for k, v in interpolatedFragments("$test{} $this is ${an{ example}} "):
|
||||
echo "(", k, ", \"", v, "\")"
|
||||
|
||||
|
||||
{.pop.}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue