Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Changed regex() (Closes: #1123).

  • Loading branch information...
commit 25383ea312d0ec93c1056a07c5135bdbbfbca2ce 1 parent d80efea
authored February 03, 2011
1  RELEASE_NOTES
@@ -23,6 +23,7 @@ MPSL Release Notes
23 23
     - sscanf().
24 24
     - map().
25 25
     - grep().
  26
+    - regex().
26 27
     - sregex().
27 28
 
28 29
 1.0.9
2  TODO
@@ -27,7 +27,6 @@ Pending Enhancements
27 27
  * 1109: There must be possible to have executable components with
28 28
    arguments in compact symbols (as in 'h.code(a1,a2).other').
29 29
  * 1115: Add C++ style comments.
30  
- * 1123: Invert regex() arguments.
31 30
 
32 31
 Closed
33 32
 ------
@@ -202,5 +201,6 @@ Closed
202 201
  * 1125: Invert map() arguments (Thu, 03 Feb 2011 10:51:53 +0100).
203 202
  * 1126: Invert grep() arguments (Thu, 03 Feb 2011 12:23:20 +0100).
204 203
  * 1124: Invert sregex() arguments (Thu, 03 Feb 2011 13:09:17 +0100).
  204
+ * 1123: Invert regex() arguments (Thu, 03 Feb 2011 15:59:47 +0100).
205 205
 
206 206
 Email bugs to angel@triptico.com
16  doc/mpsl_overview.txt
@@ -726,7 +726,7 @@ of its forms, it can be used to test if a string matches:
726 726
  /* hours, minutes, seconds */
727 727
  v = "07:55:35";
728 728
  
729  
- if (regex("/^[0-2][0-9]:[0-5][0-9]:[0-5][0-9]$/", v))
  729
+ if (regex(v, "/^[0-2][0-9]:[0-5][0-9]:[0-5][0-9]$/"))
730 730
  	print("The v variable contains a valid time\n");
731 731
 
732 732
 The regular expression can contain flags; those are `i', for case
@@ -742,7 +742,7 @@ the `g' flag is used. If no match is found, NULL is returned.
742 742
 
743 743
  v = "The value of PI is 3.1416, more or less";
744 744
  
745  
- pi = regex("/[0-9]+\.[0-9]+/", v);
  745
+ pi = regex(v, "/[0-9]+\.[0-9]+/");
746 746
 
747 747
 If regex() is called without arguments, it returns the last match as an array
748 748
 of two elements; the first contain the offset of the matched strings, and the
@@ -763,7 +763,7 @@ This can be used to extract many values from the same string:
763 763
  s = "There is 10 and 35 and 42 in the number 103542!";
764 764
  offset = 0;
765 765
  
766  
- while (n = regex("/[0-9]+/", s, offset)) {
  766
+ while (n = regex(s, "/[0-9]+/", offset)) {
767 767
  	local c;
768 768
  
769 769
  	/* print result */
@@ -779,10 +779,10 @@ This can be used to extract many values from the same string:
779 779
 Though, for this particular example, the `g' flag could be more suitable:
780 780
 
781 781
  /* return all numbers in one step */
782  
- foreach (s, regex('/[0-9]+/g', s))
783  
- 	print(s, "\n");
  782
+ foreach (i, regex(s, '/[0-9]+/g'))
  783
+ 	print(i, "\n");
784 784
 
785  
-For more complex situations, the first argument of regex() can be an array
  785
+For more complex situations, the second argument of regex() can be an array
786 786
 of regular expressions (instead of a string). Those expressions will tried
787 787
 one after the other on the string, each one using the offset returned by
788 788
 the previous one. If all of them are matched, an array with the matched strings
@@ -794,11 +794,11 @@ is returned.
794 794
  v3 = "key3=333  ";
795 795
  
796 796
  /* array regex: a regex for each part */
797  
- r = regex([ "/\s*/",        /* possible leading blanks (0) */
  797
+ r = regex(v1, [ "/\s*/",    /* possible leading blanks (0) */
798 798
              "/[a-z0-9]+/i", /* the key (1) */
799 799
              "/\s*=\s*/",    /* optional blanks, the = , more blanks (2) */
800 800
              "/[a-z0-9]+/i"  /* the value (3) */
801  
-           ], v1);
  801
+           ]);
802 802
  
803 803
  if (r != NULL) {
804 804
  	/* the key is the element #1 and the value the #3 */
10  doc/mpsl_quickref.txt
@@ -148,10 +148,10 @@ sub func(a) { ... }	of ary and returns an array
148 148
 ary2 = map(ary, hash);	Uses the elements of ary as
149 149
 			keys of hash and returns an
150 150
 			array with the values
151  
-ary2 = grep(rx, ary);	Matches the regex on all
  151
+ary2 = grep(ary, rx);	Matches the regex on all
152 152
 			elements in ary and returns
153 153
 			all the matching ones
154  
-ary2 = grep(func, ary);	Executes func on all elements
  154
+ary2 = grep(ary, func);	Executes func on all elements
155 155
 sub func(a) { ... }	of ary and returns a new array
156 156
 			with all elements on which
157 157
 			func returned true
@@ -199,15 +199,15 @@ chdir(dir);		Change current directory
199 199
 
200 200
 *Regular expression functions
201 201
 
202  
-s = regex(reg, str);	Matches the reg regexp into
  202
+s = regex(str, reg);	Matches the reg regexp into
203 203
 			str, returns the matching
204 204
 			substring
205  
-s = regex(r, str, off);	The same, but starting at off
  205
+s = regex(str, r, off);	The same, but starting at off
206 206
 			offset into str
207 207
 ary = regex();		Returns the last matching
208 208
 			offset and size as a
209 209
 			two element array
210  
-ary2 = regex(ary, str);	Matches an array of regular
  210
+ary2 = regex(str, ary);	Matches an array of regular
211 211
 			expressions, returns as many
212 212
 			matches as elements in ary
213 213
 res = sregex(str, reg,	Matches the reg regexp into
8  mpsl_f.c
@@ -749,9 +749,9 @@ static mpdm_t F_pclose(F_ARGS)
749 749
 
750 750
 /**
751 751
  * regex - Matches a regular expression.
  752
+ * @v: the value to be matched
752 753
  * @r: the regular expression
753 754
  * @ra: an array of regular expressions
754  
- * @v: the value to be matched
755 755
  * @offset: offset from the start of the value
756 756
  *
757 757
  * Matches a regular expression against a value. Valid flags are `i',
@@ -780,9 +780,9 @@ static mpdm_t F_pclose(F_ARGS)
780 780
  * is returned.
781 781
  * [Regular Expressions]
782 782
  */
783  
-/** string = regex(r, v); */
784  
-/** string = regex(r, v, offset); */
785  
-/** array = regex(ra, v); */
  783
+/** string = regex(v, r); */
  784
+/** string = regex(v, r, offset); */
  785
+/** array = regex(v, ra); */
786 786
 /** array = regex(); */
787 787
 static mpdm_t F_regex(F_ARGS)
788 788
 {
4  scripts/mkquickref.mpsl
@@ -68,11 +68,11 @@ while (line = read(STDIN)) {
68 68
                  sregex("/\)/g", '\)');
69 69
 
70 70
 	/* leading asterisk? it's a title */
71  
-	if ((l = regex([ "/^\*/", "/.*$/" ], line)) && size(l) == 2)
  71
+	if ((l = regex(line, [ "/^\*/", "/.*$/" ])) && size(l) == 2)
72 72
 		print("(", l[1], ") qr_title\n");
73 73
 	else
74 74
 	/* text-tabs-text: two columns */
75  
-	if ((l = regex([ "/^[^\t]*/", "/\t+/", "/.*$/" ], line)) && size(l) == 3)
  75
+	if ((l = regex(line, [ "/^[^\t]*/", "/\t+/", "/.*$/" ])) && size(l) == 3)
76 76
 		print("(", l[0], ") (", l[2], ") qr_2cols\n");
77 77
 	else
78 78
 	/* other: two columns, with empty second one */
12  test.mpsl
@@ -216,17 +216,17 @@ r = "|/\*[^*]*\*+([^/*][^*]*\*+)*/|";
216 216
 
217 217
 sub substr(s, o, l) { local w=splice(s, NULL, o, l); return(w[1]); }
218 218
 
219  
-v = regex(r, source);
  219
+v = regex(source, r);
220 220
 dump(v);
221 221
 /* get last matching coords */
222 222
 c = regex();
223 223
 
224  
-v = regex(r, source, c[0] + c[1]);
  224
+v = regex(source, r, c[0] + c[1]);
225 225
 dump(v);
226 226
 /* get last matching coords */
227 227
 c = regex();
228 228
 
229  
-v = regex(r, source, c[0] + c[1]);
  229
+v = regex(source, r, c[0] + c[1]);
230 230
 dump(v);
231 231
 
232 232
 /* assignations as expressions */
@@ -243,7 +243,7 @@ if(f = open("config.h", "r"))
243 243
 print("\nAssignations as expressions: looped regex matching\n");
244 244
 c = 0;
245 245
 
246  
-while(v = regex(r, source, c))
  246
+while(v = regex(source, r, c))
247 247
 {
248 248
 	print(v, "\n");
249 249
 	c = regex();
@@ -323,7 +323,7 @@ r = "/\w+/";
323 323
 c = 0;
324 324
 
325 325
 print("Words:\n");
326  
-while(w = regex(r, v, c))
  326
+while(w = regex(v, r, c))
327 327
 {
328 328
 	print(w, "\n");
329 329
 	c = regex();
@@ -334,7 +334,7 @@ r = "/'[^']*'/";
334 334
 c = 0;
335 335
 
336 336
 print("Quotes:\n");
337  
-while(w = regex(r, v, c))
  337
+while(w = regex(v, r, c))
338 338
 {
339 339
 	print(w, "\n");
340 340
 	c = regex();

0 notes on commit 25383ea

Please sign in to comment.
Something went wrong with that request. Please try again.