You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -142,13 +146,19 @@ let mk_example name num mode = match mode with
142
146
| Some _ | None -> { name; num; mode = `Default}
143
147
144
148
let mk_example_re = function%mikmatch
145
-
| {|/ (['a'-'z'] as name := String.capitalize_ascii) ' ' (digit+ as num : int) ' ' ('a'|'b' as mode)? >>> mk_example as res /|} -> (* (res : example) available here, and all other bound variables *)
149
+
| {|/ (['a'-'z']~ as name := String.capitalize_ascii) ' ' (digit+ as num : int) ' ' ('a'|'b' as mode)? >>> mk_example as res /|} -> (* (res : example) available here, and all other bound variables *)
146
150
| _ -> ...
147
151
```
148
152
149
-
## Case Insensitive Match
153
+
### Default catch-all case
154
+
The PPX generates a default catch-all case if none is provided. This catch-all case executes if none of the RE match cases does, and it raises a `Failure` exception with the location of the function and name of the file where it was raised.
155
+
156
+
## Flags
150
157
151
-
You can use `%mikmatch_i`: `match%mikmatch_i` and `function%mikmatch_i`. (not available at the variable level)
158
+
The `/` delimiters are optional, except if flags are needed using the syntax `/ ... / flags`, where `flags` can be
159
+
-`i` for caseless matching
160
+
-`u` for unanchored matching (`%mikmatch` is anchored at the beginning and end by default)
161
+
- or both
152
162
153
163
## Alternatives
154
164
### Defining variables
@@ -159,7 +169,6 @@ let%mikmatch re = {|some regex|}
159
169
let re = {%mikmatch|some regex|}
160
170
```
161
171
162
-
No `/` delimiters are needed here.
163
172
164
173
### Matching:
165
174
#### `match%mikmatch` and `function%mikmatch`
@@ -172,7 +181,7 @@ function%mikmatch
172
181
| _ -> ...
173
182
```
174
183
175
-
This match expression will compile all of the REs in the branches into one, and use marks to find which branch was executed.
184
+
This match expression will compile all of the REs in the branches into one, with some exceptions around pattern guards, and use marks to find which branch was executed.
176
185
Efficient if you have multiple branches.
177
186
178
187
The regexes are anchored both at the beginning, and at the end. So, for example, the first match case will be compiled to `^some regex$`.
@@ -185,12 +194,10 @@ function
185
194
| {%mikmatch|/ some regex /|} -> ...
186
195
...
187
196
| "another string" -> ...
188
-
| {%mikmatch_i|/ some regex /|} -> ...
197
+
| {%mikmatch|/ some regex /|} -> ...
189
198
...
190
199
| _ -> ...
191
200
```
192
201
193
202
This match expression will compile all of the REs **individually**, and test each one in sequence.
194
-
Recommended if you only matching one RE. It is less efficient than the first option for more than one RE, but allows raw string matching.
195
-
196
203
It keeps all of the features (guards and such) of the previous extension, explored in [Semantics](#Semantics_and_Examples)
0 commit comments