Merge branch 'master' into newparser

This commit is contained in:
Araq 2013-05-04 19:10:12 +02:00
commit 23bd3ccd8b
31 changed files with 277 additions and 63 deletions

View file

@ -130,12 +130,14 @@ proc `==`*(a, b: PNimrodNode): bool {.magic: "EqNimrodNode", noSideEffect.}
proc len*(n: PNimrodNode): int {.magic: "NLen".}
## returns the number of children of `n`.
proc add*(father, child: PNimrodNode) {.magic: "NAdd".}
## adds the `child` to the `father` node
proc add*(father, child: PNimrodNode): PNimrodNode {.magic: "NAdd", discardable.}
## Adds the `child` to the `father` node. Returns the
## father node so that calls can be nested.
proc add*(father: PNimrodNode, children: varargs[PNimrodNode]) {.
magic: "NAddMultiple".}
## adds each child of `children` to the `father` node
proc add*(father: PNimrodNode, children: varargs[PNimrodNode]): PNimrodNode {.
magic: "NAddMultiple", discardable.}
## Adds each child of `children` to the `father` node.
## Returns the `father` node so that calls can be nested.
proc del*(father: PNimrodNode, idx = 0, n = 1) {.magic: "NDel".}
## deletes `n` children of `father` starting at index `idx`.

View file

@ -34,7 +34,10 @@ const
proc getIdent(e: PNimrodNode): string {.compileTime.} =
case e.kind
of nnkIdent: result = normalize($e.ident)
of nnkAccQuoted: result = getIdent(e[0])
of nnkAccQuoted:
result = getIdent(e[0])
for i in 1 .. e.len-1:
result.add getIdent(e[i])
else: error("cannot extract identifier from node: " & toStrLit(e).strVal)
proc delete[T](s: var seq[T], attr: T): bool =
@ -478,4 +481,5 @@ macro `var`*(e: expr): expr {.immediate.} =
when isMainModule:
var nim = "Nimrod"
echo h1(a(href="http://nimrod-code.org", nim))
echo form(action="test", `accept-charset` = "Content-Type")

View file

@ -106,6 +106,12 @@ proc write*(s: PStream, x: string) =
## terminating zero is written.
writeData(s, cstring(x), x.len)
proc writeln*(s: PStream, args: varargs[string, `$`]) =
## writes one or more strings to the the stream `s` followed
## by a new line. No length field or terminating zero is written.
for str in args: write(s, str)
write(s, "\n")
proc read[T](s: PStream, result: var T) =
## generic read procedure. Reads `result` from the stream `s`.
if readData(s, addr(result), sizeof(T)) != sizeof(T):

View file

@ -2407,8 +2407,8 @@ proc astToStr*[T](x: T): string {.magic: "AstToStr", noSideEffect.}
## converts the AST of `x` into a string representation. This is very useful
## for debugging.
proc InstantiationInfo*(index = -1): tuple[filename: string, line: int] {.
magic: "InstantiationInfo", noSideEffect.}
proc InstantiationInfo*(index = -1, fullPaths = false): tuple[
filename: string, line: int] {. magic: "InstantiationInfo", noSideEffect.}
## provides access to the compiler's instantiation stack line information.
##
## This proc is mostly useful for meta programming (eg. ``assert`` template)
@ -2438,6 +2438,9 @@ proc InstantiationInfo*(index = -1): tuple[filename: string, line: int] {.
## testException(EInvalidIndex, tester(1))
## # --> Test failure at example.nim:20 with 'tester(1)'
template CurrentSourcePath*: string = InstantiationInfo(-1, true).filename
## returns the full file-system path of the current source
proc raiseAssert*(msg: string) {.noinline.} =
raise newException(EAssertionFailed, msg)