summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--doc/astspec.txt75
-rw-r--r--doc/tut2.txt12
-rw-r--r--lib/impure/nre.nim8
-rw-r--r--tests/stdlib/nre/split.nim1
4 files changed, 50 insertions, 46 deletions
diff --git a/doc/astspec.txt b/doc/astspec.txt
index 797413bd0..d3ca7755e 100644
--- a/doc/astspec.txt
+++ b/doc/astspec.txt
@@ -1,5 +1,6 @@
 The AST in Nim
-=================
+==============
+
 This section describes how the AST is modelled with Nim's type system.
 The AST consists of nodes (``NimNode``) with a variable number of
 children. Each node has a field named ``kind`` which describes what the node
@@ -24,9 +25,9 @@ contains:
       of nnkNone, nnkEmpty, nnkNilLit:
         discard                        ## node contains no additional fields
       of nnkCharLit..nnkUInt64Lit:
-        intVal: biggestInt             ## the int literal
+        intVal: BiggestInt             ## the int literal
       of nnkFloatLit..nnkFloat64Lit:
-        floatVal: biggestFloat         ## the float literal
+        floatVal: BiggestFloat         ## the float literal
       of nnkStrLit..nnkTripleStrLit:
         strVal: string                 ## the string literal
       of nnkIdent:
@@ -360,7 +361,7 @@ AST:
 .. code-block:: nim
   nnkCurly(nnkIntLit(1), nnkIntLit(2), nnkIntLit(3))
 
-When used as a table constructor, the syntax (and result) is different.
+When used as a table constructor, the syntax is different.
 
 Concrete syntax:
 
@@ -411,7 +412,7 @@ AST:
 If expression
 -------------
 
-The representation of the if expression is subtle, but easy to traverse.
+The representation of the ``if`` expression is subtle, but easy to traverse.
 
 Concrete syntax:
 
@@ -472,7 +473,7 @@ AST:
     )
   )
 
-As many ``nnkIdent``s appear as there are pragmas between ``{..}``. Note that
+As many ``nnkIdent`` appear as there are pragmas between ``{..}``. Note that
 the declaration of new pragmas is essentially the same:
 
 Concrete syntax:
@@ -824,7 +825,7 @@ AST:
 .. code-block:: nim
   nnkExportStmt(nnkIdent(!"unsigned"))
 
-Similar to the ``import`` statement, the AST is different for 
+Similar to the ``import`` statement, the AST is different for
 ``export ... except``.
 
 Concrete syntax:
@@ -1035,42 +1036,42 @@ AST:
     nnkEmpty(),
     nnkRecList( # list of object parameters
       nnkIdentDefs(
-            nnkIdent(!"name"),
-            nnkIdent(!"string"),
-            nnkEmpty()
+        nnkIdent(!"name"),
+        nnkIdent(!"string"),
+        nnkEmpty()
       ),
       nnkRecCase( # case statement within object (not nnkCaseStmt)
         nnkIdentDefs(
-              nnkIdent(!"isFat"),
-              nnkIdent(!"bool"),
-              nnkEmpty()
+          nnkIdent(!"isFat"),
+          nnkIdent(!"bool"),
+          nnkEmpty()
         ),
         nnkOfBranch(
-              nnkIdent(!"true"),
-              nnkRecList( # again, a list of object parameters
-                nnkIdentDefs(
-                  nnkIdent(!"m"),
-                  nnkBracketExpr(
-                    nnkIdent(!"array"),
-                    nnkIntLit(100000),
-                    nnkIdent(!"T")
-                  ),
-                  nnkEmpty()
-              )
+          nnkIdent(!"true"),
+          nnkRecList( # again, a list of object parameters
+            nnkIdentDefs(
+              nnkIdent(!"m"),
+              nnkBracketExpr(
+                nnkIdent(!"array"),
+                nnkIntLit(100000),
+                nnkIdent(!"T")
+              ),
+              nnkEmpty()
+          )
         ),
         nnkOfBranch(
-              nnkIdent(!"false"),
-              nnkRecList(
-                nnkIdentDefs(
-                  nnkIdent(!"m"),
-                  nnkBracketExpr(
-                    nnkIdent(!"array"),
-                    nnkIntLit(10),
-                    nnkIdent(!"T")
-                  ),
-                  nnkEmpty()
-                )
-              )
+          nnkIdent(!"false"),
+          nnkRecList(
+            nnkIdentDefs(
+              nnkIdent(!"m"),
+              nnkBracketExpr(
+                nnkIdent(!"array"),
+                nnkIntLit(10),
+                nnkIdent(!"T")
+              ),
+              nnkEmpty()
+            )
+          )
         )
       )
     )
@@ -1135,7 +1136,7 @@ AST:
   # ...
 
 In general, declaring types mirrors this syntax (i.e., ``nnkStaticTy`` for
-``static``, etc.). Examples follow (exceptions marked by ``*``:
+``static``, etc.). Examples follow (exceptions marked by ``*``):
 
 -------------                ---------------------------------------------
 Nim type                     Corresponding AST
diff --git a/doc/tut2.txt b/doc/tut2.txt
index e1ac20074..966423844 100644
--- a/doc/tut2.txt
+++ b/doc/tut2.txt
@@ -233,17 +233,15 @@ is needed:
 
   type
     Socket* = ref object of RootObj
-      FHost: int # cannot be accessed from the outside of the module
-                 # the `F` prefix is a convention to avoid clashes since
-                 # the accessors are named `host`
+      host: int # cannot be accessed from the outside of the module due to missing star
 
   proc `host=`*(s: var Socket, value: int) {.inline.} =
-    ## setter of hostAddr
-    s.FHost = value
+    ## setter of host address
+    s.host = value
 
   proc host*(s: Socket): int {.inline.} =
-    ## getter of hostAddr
-    s.FHost
+    ## getter of host address
+    s.host
 
   var s: Socket
   new s
diff --git a/lib/impure/nre.nim b/lib/impure/nre.nim
index 6f92b0d71..973f1f2ee 100644
--- a/lib/impure/nre.nim
+++ b/lib/impure/nre.nim
@@ -586,9 +586,12 @@ proc split*(str: string, pattern: Regex, maxSplit = -1, start = 0): seq[string]
   result = @[]
   var lastIdx = start
   var splits = 0
-  var bounds = 0 .. 0
+  var bounds = 0 .. -1
+  var never_ran = true
 
   for match in str.findIter(pattern, start = start):
+    never_ran = false
+
     # bounds are inclusive:
     #
     # 0123456
@@ -615,7 +618,8 @@ proc split*(str: string, pattern: Regex, maxSplit = -1, start = 0): seq[string]
   # "12".split("\b") would be @["1", "2", ""], but
   # if we skip an empty last match, it's the correct
   # @["1", "2"]
-  if bounds.a <= bounds.b or bounds.b < str.high:
+  # If matches were never found, then the input string is the result
+  if bounds.a <= bounds.b or bounds.b < str.high or never_ran:
     # last match: Each match takes the previous substring,
     # but "1 2".split(/ /) needs to return @["1", "2"].
     # This handles "2"
diff --git a/tests/stdlib/nre/split.nim b/tests/stdlib/nre/split.nim
index 8064e40b7..9d57ea7d8 100644
--- a/tests/stdlib/nre/split.nim
+++ b/tests/stdlib/nre/split.nim
@@ -8,6 +8,7 @@ suite "string splitting":
     check("1 2".split(re(" ")) == @["1", "2"])
     check("foo".split(re("foo")) == @["", ""])
     check("".split(re"foo") == @[""])
+    check("9".split(re"\son\s") == @["9"])
 
   test "captured patterns":
     check("12".split(re"(\d)") == @["", "1", "", "2", ""])