summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/core/macros.nim2
-rw-r--r--lib/pure/fsmonitor.nim10
-rw-r--r--lib/pure/htmlparser.nim30
-rw-r--r--lib/system.nim53
-rw-r--r--lib/system/channels.nim3
-rw-r--r--lib/system/threads.nim3
6 files changed, 69 insertions, 32 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim
index fc93a157d..d01d4ebee 100644
--- a/lib/core/macros.nim
+++ b/lib/core/macros.nim
@@ -494,7 +494,7 @@ const
 
 from strutils import cmpIgnoreStyle, format
 
-proc ExpectKind*(n: PNimrodNode; k: set[TNimrodNodeKind]) {.compileTime.} =
+proc expectKind*(n: PNimrodNode; k: set[TNimrodNodeKind]) {.compileTime.} =
   assert n.kind in k, "Expected one of $1, got $2".format(k, n.kind)
 
 proc newProc*(name = newEmptyNode(); params: openarray[PNimrodNode] = [];  
diff --git a/lib/pure/fsmonitor.nim b/lib/pure/fsmonitor.nim
index a554cf963..d6584c1a0 100644
--- a/lib/pure/fsmonitor.nim
+++ b/lib/pure/fsmonitor.nim
@@ -64,10 +64,10 @@ const
 proc newMonitor*(): PFSMonitor =
   ## Creates a new file system monitor.
   new(result)
-  result.fd = inotifyInit()
   result.targets = initTable[cint, string]()
+  result.fd = inotifyInit()
   if result.fd < 0:
-    OSError()
+    OSError(OSLastError())
 
 proc add*(monitor: PFSMonitor, target: string,
                filters = {MonitorAll}): cint {.discardable.} =
@@ -93,7 +93,7 @@ proc add*(monitor: PFSMonitor, target: string,
   
   result = inotifyAddWatch(monitor.fd, target, INFilter.uint32)
   if result < 0:
-    OSError()
+    OSError(OSLastError())
   monitor.targets.add(result, target)
 
 proc del*(monitor: PFSMonitor, wd: cint) =
@@ -101,7 +101,7 @@ proc del*(monitor: PFSMonitor, wd: cint) =
   ##
   ## If ``wd`` is not a part of ``monitor`` an EOS error is raised.
   if inotifyRmWatch(monitor.fd, wd) < 0:
-    OSError()
+    OSError(OSLastError())
 
 proc getEvent(m: PFSMonitor, fd: cint): seq[TMonitorEvent] =
   result = @[]
@@ -184,7 +184,7 @@ proc FSMonitorRead(h: PObject) =
 proc toDelegate(m: PFSMonitor): PDelegate =
   result = newDelegate()
   result.deleVal = m
-  result.fd = m.fd
+  result.fd = (type(result.fd))(m.fd)
   result.mode = fmRead
   result.handleRead = FSMonitorRead
   result.open = true
diff --git a/lib/pure/htmlparser.nim b/lib/pure/htmlparser.nim
index d60d2e583..060f0e386 100644
--- a/lib/pure/htmlparser.nim
+++ b/lib/pure/htmlparser.nim
@@ -17,11 +17,37 @@
 ##
 ##   echo loadHtml("mydirty.html")
 ##
-##
 ## Every tag in the resulting tree is in lower case.
 ##
 ## **Note:** The resulting ``PXmlNode`` already uses the ``clientData`` field, 
 ## so it cannot be used by clients of this library.
+##
+## Example: Transforming hyperlinks
+## ================================
+##
+## This code demonstrates how you can iterate over all the tags in an HTML file
+## and write back the modified version. In this case we look for hyperlinks
+## ending with the extension ``.rst`` and convert them to ``.html``.
+##
+## .. code-block:: nimrod
+##
+##   import htmlparser
+##   import xmltree  # To use '$' for PXmlNode
+##   import strtabs  # To access PXmlAttributes
+##   import os       # To use splitFile
+##   import strutils # To use cmpIgnoreCase
+##
+##   proc transformHyperlinks() =
+##     let html = loadHTML("input.html")
+##
+##     for a in html.findAll("a"):
+##       let href = a.attrs["href"]
+##       if not href.isNil:
+##         let (dir, filename, ext) = splitFile(href)
+##         if cmpIgnoreCase(ext, ".rst") == 0:
+##           a.attrs["href"] = dir / filename & ".html"
+##
+##     writeFile("output.html", $html)
 
 import strutils, streams, parsexml, xmltree, unicode, strtabs
 
@@ -528,7 +554,7 @@ proc parseHtml*(s: PStream, filename: string,
   ## parses the XML from stream `s` and returns a ``PXmlNode``. Every
   ## occured parsing error is added to the `errors` sequence.
   var x: TXmlParser
-  open(x, s, filename, {reportComments})
+  open(x, s, filename, {reportComments, reportWhitespace})
   next(x)
   # skip the DOCTYPE:
   if x.kind == xmlSpecial: next(x)
diff --git a/lib/system.nim b/lib/system.nim
index b2d19a885..dc5a406d1 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -374,10 +374,10 @@ proc newSeq*[T](s: var seq[T], len: int) {.magic: "NewSeq", noSideEffect.}
   ## This is equivalent to ``s = @[]; setlen(s, len)``, but more
   ## efficient since no reallocation is needed.
   ##
-  ## Note that the sequence will be filled with uninitialized entries, which
-  ## can be a problem for sequences containing strings. After the creation of
-  ## the sequence you should assign entries to the sequence instead of adding
-  ## them. Example:
+  ## Note that the sequence will be filled with zeroed entries, which can be a
+  ## problem for sequences containing strings since their value will be
+  ## ``nil``. After the creation of the sequence you should assign entries to
+  ## the sequence instead of adding them. Example:
   ##
   ## .. code-block:: nimrod
   ##   var inputStrings : seq[string]
@@ -390,10 +390,10 @@ proc newSeq*[T](s: var seq[T], len: int) {.magic: "NewSeq", noSideEffect.}
 proc newSeq*[T](len = 0): seq[T] =
   ## creates a new sequence of type ``seq[T]`` with length ``len``.
   ##
-  ## Note that the sequence will be filled with uninitialized entries, which
-  ## can be a problem for sequences containing strings. After the creation of
-  ## the sequence you should assign entries to the sequence instead of adding
-  ## them. Example:
+  ## Note that the sequence will be filled with zeroed entries, which can be a
+  ## problem for sequences containing strings since their value will be
+  ## ``nil``. After the creation of the sequence you should assign entries to
+  ## the sequence instead of adding them. Example:
   ##
   ## .. code-block:: nimrod
   ##   var inputStrings = newSeq[string](3)
@@ -999,11 +999,17 @@ type
     ## platform-dependant in general.
 
 when defined(windows):
-  type clong* {.importc: "long", nodecl.} = int32
-    ## This is the same as the type ``long`` in *C*.
+  type
+    clong* {.importc: "long", nodecl.} = int32
+      ## This is the same as the type ``long`` in *C*.
+    culong* {.importc: "unsigned long", nodecl.} = uint32
+      ## This is the same as the type ``unsigned long`` in *C*.
 else:
-  type clong* {.importc: "long", nodecl.} = int
-    ## This is the same as the type ``long`` in *C*.
+  type
+    clong* {.importc: "long", nodecl.} = int
+      ## This is the same as the type ``long`` in *C*.
+    culong* {.importc: "unsigned long", nodecl.} = uint
+      ## This is the same as the type ``unsigned long`` in *C*.
 
 type # these work for most platforms:
   cchar* {.importc: "char", nodecl.} = char
@@ -1032,8 +1038,6 @@ type # these work for most platforms:
     ## This is the same as the type ``unsigned short`` in *C*.
   cuint* {.importc: "int", nodecl.} = uint32
     ## This is the same as the type ``unsigned int`` in *C*.
-  culong* {.importc: "unsigned long", nodecl.} = uint
-    ## This is the same as the type ``unsigned long`` in *C*.
   culonglong* {.importc: "unsigned long long", nodecl.} = uint64
     ## This is the same as the type ``unsigned long long`` in *C*.
 
@@ -1042,10 +1046,10 @@ type # these work for most platforms:
     ## high value is large enough to disable bounds checking in practice.
     ## Use `cstringArrayToSeq` to convert it into a ``seq[string]``.
   
-  PFloat32* = ptr Float32 ## an alias for ``ptr float32``
-  PFloat64* = ptr Float64 ## an alias for ``ptr float64``
-  PInt64* = ptr Int64 ## an alias for ``ptr int64``
-  PInt32* = ptr Int32 ## an alias for ``ptr int32``
+  PFloat32* = ptr float32 ## an alias for ``ptr float32``
+  PFloat64* = ptr float64 ## an alias for ``ptr float64``
+  PInt64* = ptr int64 ## an alias for ``ptr int64``
+  PInt32* = ptr int32 ## an alias for ``ptr int32``
 
 proc toFloat*(i: int): float {.
   magic: "ToFloat", noSideEffect, importc: "toFloat".}
@@ -2615,12 +2619,13 @@ type
   PNimrodNode* {.magic: "PNimrodNode".} = ref TNimrodNode
     ## represents a Nimrod AST node. Macros operate on this type.
 
-template eval*(blk: stmt): stmt =
-  ## executes a block of code at compile time just as if it was a macro
-  ## optionally, the block can return an AST tree that will replace the 
-  ## eval expression
-  macro payload: stmt {.gensym.} = blk
-  payload()
+when false:
+  template eval*(blk: stmt): stmt =
+    ## executes a block of code at compile time just as if it was a macro
+    ## optionally, the block can return an AST tree that will replace the 
+    ## eval expression
+    macro payload: stmt {.gensym.} = blk
+    payload()
 
 when hostOS != "standalone":
   proc insert*(x: var string, item: string, i = 0) {.noSideEffect.} = 
diff --git a/lib/system/channels.nim b/lib/system/channels.nim
index d0294322a..9c3cc93e0 100644
--- a/lib/system/channels.nim
+++ b/lib/system/channels.nim
@@ -13,6 +13,9 @@
 ##

 ## **Note:** The current implementation of message passing is slow and does

 ## not work with cyclic data structures.

+  
+when not defined(NimString): 
+  {.error: "You must not import this module explicitly".}
 

 type

   pbytes = ptr array[0.. 0xffff, byte]

diff --git a/lib/system/threads.nim b/lib/system/threads.nim
index 7d74de92d..104ca63c1 100644
--- a/lib/system/threads.nim
+++ b/lib/system/threads.nim
@@ -39,6 +39,9 @@
 ##    createThread(thr[i], threadFunc, (i*10, i*10+5))
 ##  joinThreads(thr)
   
+when not defined(NimString): 
+  {.error: "You must not import this module explicitly".}
+
 const
   maxRegisters = 256 # don't think there is an arch with more registers
   useStackMaskHack = false ## use the stack mask hack for better performance