summary refs log tree commit diff stats
path: root/lib/impure
diff options
context:
space:
mode:
authorFlaviu Tamas <me@flaviutamas.com>2016-05-13 16:43:43 -0400
committerFlaviu Tamas <me@flaviutamas.com>2016-05-13 16:43:43 -0400
commit4febf2784aeb75529f3bb6fd8a988aecadc0ef78 (patch)
tree43e9d0f8546e6a54508fab3a189661fd305f9b0a /lib/impure
parent755225d0e07378d6fa50c712e81908fffc0e443d (diff)
downloadNim-4febf2784aeb75529f3bb6fd8a988aecadc0ef78.tar.gz
Update NRE documentation
Diffstat (limited to 'lib/impure')
-rw-r--r--lib/impure/nre.nim81
1 files changed, 35 insertions, 46 deletions
diff --git a/lib/impure/nre.nim b/lib/impure/nre.nim
index c8f690461..1c2a39854 100644
--- a/lib/impure/nre.nim
+++ b/lib/impure/nre.nim
@@ -24,46 +24,35 @@ from unicode import runeLenAt
 ## Licencing
 ## ---------
 ##
-## PCRE has some additional terms that you must comply with if you use this module.::
+## PCRE has `some additional terms`_ that you must agree to in order to use
+## this module.
 ##
-## > Copyright (c) 1997-2001 University of Cambridge
-## >
-## > Permission is granted to anyone to use this software for any purpose on any
-## > computer system, and to redistribute it freely, subject to the following
-## > restrictions:
-## >
-## > 1. This software is distributed in the hope that it will be useful,
-## >    but WITHOUT ANY WARRANTY; without even the implied warranty of
-## >    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-## >
-## > 2. The origin of this software must not be misrepresented, either by
-## >    explicit claim or by omission. In practice, this means that if you use
-## >    PCRE in software that you distribute to others, commercially or
-## >    otherwise, you must put a sentence like this
-## >
-## >      Regular expression support is provided by the PCRE library package,
-## >      which is open source software, written by Philip Hazel, and copyright
-## >      by the University of Cambridge, England.
-## >
-## >    somewhere reasonably visible in your documentation and in any relevant
-## >    files or online help data or similar. A reference to the ftp site for
-## >    the source, that is, to
-## >
-## >      ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
-## >
-## >    should also be given in the documentation. However, this condition is not
-## >    intended to apply to whole chains of software. If package A includes PCRE,
-## >    it must acknowledge it, but if package B is software that includes package
-## >    A, the condition is not imposed on package B (unless it uses PCRE
-## >    independently).
-## >
-## > 3. Altered versions must be plainly marked as such, and must not be
-## >    misrepresented as being the original software.
-## >
-## > 4. If PCRE is embedded in any software that is released under the GNU
-## >    General Purpose Licence (GPL), or Lesser General Purpose Licence (LGPL),
-## >    then the terms of that licence shall supersede any condition above with
-## >    which it is incompatible.
+## .. _`some additional terms`: http://pcre.sourceforge.net/license.txt
+##
+## Example
+## -------
+##
+## .. code-block:: nim
+##
+##     import nre
+##
+##     let vowels = re"[aeoui]"
+##
+##     for match in "moigagoo".findIter(vowels):
+##       echo match.matchBounds
+##     # (a: 1, b: 1)
+##     # (a: 2, b: 2)
+##     # (a: 4, b: 4)
+##     # (a: 6, b: 6)
+##     # (a: 7, b: 7)
+##
+##     import options  # critical to use isSome() and get()
+##     let firstVowel = "foo".find(vowels)
+##     let hasVowel = firstVowel.isSome()
+##     if hasVowel:
+##       let matchBounds = firstVowel.get().captureBounds[-1]
+##       echo "first vowel @", matchBounds.get().a
+##       # first vowel @1
 
 
 # Type definitions {{{
@@ -125,11 +114,11 @@ type
     ## -  ``(*NO_STUDY)`` - turn off studying; study is enabled by default
     ##
     ## For more details on the leading option groups, see the `Option
-    ## Setting <http://man7.org/linux/man-pages/man3/pcresyntax.3.html#OPTION_SETTING>`__
+    ## Setting <http://man7.org/linux/man-pages/man3/pcresyntax.3.html#OPTION_SETTING>`_
     ## and the `Newline
-    ## Convention <http://man7.org/linux/man-pages/man3/pcresyntax.3.html#NEWLINE_CONVENTION>`__
+    ## Convention <http://man7.org/linux/man-pages/man3/pcresyntax.3.html#NEWLINE_CONVENTION>`_
     ## sections of the `PCRE syntax
-    ## manual <http://man7.org/linux/man-pages/man3/pcresyntax.3.html>`__.
+    ## manual <http://man7.org/linux/man-pages/man3/pcresyntax.3.html>`_.
     pattern*: string  ## not nil
     pcreObj: ptr pcre.Pcre  ## not nil
     pcreExtra: ptr pcre.ExtraData  ## nil
@@ -493,17 +482,17 @@ proc matchImpl(str: string, pattern: Regex, start, endpos: int, flags: int): Opt
       raise RegexInternalError(msg : "Unknown internal error: " & $execRet)
 
 proc match*(str: string, pattern: Regex, start = 0, endpos = int.high): Option[RegexMatch] =
-  ## Like ```find(...)`` <#proc-find>`__, but anchored to the start of the
+  ## Like ```find(...)`` <#proc-find>`_, but anchored to the start of the
   ## string. This means that ``"foo".match(re"f") == true``, but
   ## ``"foo".match(re"o") == false``.
   return str.matchImpl(pattern, start, endpos, pcre.ANCHORED)
 
 iterator findIter*(str: string, pattern: Regex, start = 0, endpos = int.high): RegexMatch =
-  ## Works the same as ```find(...)`` <#proc-find>`__, but finds every
+  ## Works the same as ```find(...)`` <#proc-find>`_, but finds every
   ## non-overlapping match. ``"2222".find(re"22")`` is ``"22", "22"``, not
   ## ``"22", "22", "22"``.
   ##
-  ## Arguments are the same as ```find(...)`` <#proc-find>`__
+  ## Arguments are the same as ```find(...)`` <#proc-find>`_
   ##
   ## Variants:
   ##
@@ -581,7 +570,7 @@ proc split*(str: string, pattern: Regex, maxSplit = -1, start = 0): seq[string]
   ##    strings in the output seq.
   ##    ``"1.2.3".split(re"\.", maxsplit = 2) == @["1", "2.3"]``
   ##
-  ## ``start`` behaves the same as in ```find(...)`` <#proc-find>`__.
+  ## ``start`` behaves the same as in ```find(...)`` <#proc-find>`_.
   result = @[]
   var lastIdx = start
   var splits = 0
bf7eb7cbf13ae0dc053bb2de9d'>0b44d812f ^
45862e58a ^
0b44d812f ^
45862e58a ^
053309e60 ^
adf13aaea ^




053309e60 ^





















0b44d812f ^
053309e60 ^
0b44d812f ^
053309e60 ^





0b44d812f ^
ac421c37b ^
053309e60 ^
0b44d812f ^
053309e60 ^

8ee63f983 ^
437eb2c37 ^
0b44d812f ^





40ea1d033 ^


0b44d812f ^
053309e60 ^

0b44d812f ^
053309e60 ^



0b44d812f ^

ec67d9828 ^

3ea644690 ^
ec67d9828 ^




053309e60 ^


11b695875 ^
053309e60 ^
3ea644690 ^
053309e60 ^

0b44d812f ^
053309e60 ^
3ea644690 ^
7a010cf65 ^
053309e60 ^


3ea644690 ^
053309e60 ^

ac421c37b ^

053309e60 ^



ac421c37b ^

053309e60 ^
ac421c37b ^
053309e60 ^
45862e58a ^

053309e60 ^



11b695875 ^
110c4aca7 ^
053309e60 ^


281609c35 ^
053309e60 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222