bugfix: semfold supports merging of '&'
This commit is contained in:
parent
b88d98c17a
commit
ccd58fba2c
3 changed files with 29 additions and 2 deletions
|
|
@ -372,6 +372,14 @@ proc foldFieldAccess(m: PSym, n: PNode): PNode =
|
||||||
return
|
return
|
||||||
localError(n.info, errFieldXNotFound, field.name.s)
|
localError(n.info, errFieldXNotFound, field.name.s)
|
||||||
|
|
||||||
|
proc foldConStrStr(m: PSym, n: PNode): PNode =
|
||||||
|
result = newNodeIT(nkStrLit, n.info, n.typ)
|
||||||
|
result.strVal = ""
|
||||||
|
for i in countup(1, sonsLen(n) - 1):
|
||||||
|
let a = getConstExpr(m, n.sons[i])
|
||||||
|
if a == nil: return nil
|
||||||
|
result.strVal.add(getStrOrChar(a))
|
||||||
|
|
||||||
proc getConstExpr(m: PSym, n: PNode): PNode =
|
proc getConstExpr(m: PSym, n: PNode): PNode =
|
||||||
result = nil
|
result = nil
|
||||||
case n.kind
|
case n.kind
|
||||||
|
|
@ -444,6 +452,8 @@ proc getConstExpr(m: PSym, n: PNode): PNode =
|
||||||
result = newIntNodeT(ord(sameType(n[1].typ, n[2].typ)), n)
|
result = newIntNodeT(ord(sameType(n[1].typ, n[2].typ)), n)
|
||||||
of mAstToStr:
|
of mAstToStr:
|
||||||
result = newStrNodeT(renderTree(n[1], {renderNoComments}), n)
|
result = newStrNodeT(renderTree(n[1], {renderNoComments}), n)
|
||||||
|
of mConStrStr:
|
||||||
|
result = foldConStrStr(m, n)
|
||||||
else:
|
else:
|
||||||
result = magicCall(m, n)
|
result = magicCall(m, n)
|
||||||
except EOverflow:
|
except EOverflow:
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,21 @@ proc validEmailAddress*(s: string): bool {.noSideEffect,
|
||||||
"aero", "jobs", "museum": return true
|
"aero", "jobs", "museum": return true
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
proc parseInt*(s: string, value: var int, validRange: TSlice[int]) {.
|
||||||
|
noSideEffect, rtl, extern: "nmatchParseInt".} =
|
||||||
|
## parses `s` into an integer in the range `validRange`. If successful,
|
||||||
|
## `value` is modified to contain the result. Otherwise no exception is
|
||||||
|
## raised and `value` is not touched; this way a reasonable default value
|
||||||
|
## won't be overwritten.
|
||||||
|
var x = value
|
||||||
|
try:
|
||||||
|
x = parseInt(s)
|
||||||
|
except EOverflow:
|
||||||
|
nil
|
||||||
|
if x in validRange: value = x
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
assert "wuseldusel@codehome.com".validEmailAddress
|
doAssert "wuseldusel@codehome.com".validEmailAddress
|
||||||
|
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -196,7 +196,11 @@ proc parseBiggestInt*(s: string, number: var biggestInt, start = 0): int {.
|
||||||
## parses an integer starting at `start` and stores the value into `number`.
|
## parses an integer starting at `start` and stores the value into `number`.
|
||||||
## Result is the number of processed chars or 0 if there is no integer.
|
## Result is the number of processed chars or 0 if there is no integer.
|
||||||
## `EOverflow` is raised if an overflow occurs.
|
## `EOverflow` is raised if an overflow occurs.
|
||||||
result = rawParseInt(s, number, start)
|
var res: biggestInt = number
|
||||||
|
# use 'res' for exception safety (don't write to 'number' in case of an
|
||||||
|
# overflow exception:
|
||||||
|
result = rawParseInt(s, res, start)
|
||||||
|
number = res
|
||||||
|
|
||||||
proc parseInt*(s: string, number: var int, start = 0): int {.
|
proc parseInt*(s: string, number: var int, start = 0): int {.
|
||||||
rtl, extern: "npuParseInt", noSideEffect.} =
|
rtl, extern: "npuParseInt", noSideEffect.} =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue