@@ -4,6 +4,7 @@ extern crate regex_syntax2 as syntax;
4
4
extern crate serde;
5
5
#[ macro_use]
6
6
extern crate serde_derive;
7
+ extern crate utf8_ranges;
7
8
8
9
use std:: error;
9
10
use std:: io:: { self , Write } ;
24
25
regex-debug [options] anchors <pattern>
25
26
regex-debug [options] captures <pattern>
26
27
regex-debug [options] compile <patterns> ...
28
+ regex-debug [options] utf8-ranges <class>
27
29
regex-debug --help
28
30
29
31
Options:
@@ -59,9 +61,11 @@ struct Args {
59
61
cmd_anchors : bool ,
60
62
cmd_captures : bool ,
61
63
cmd_compile : bool ,
64
+ cmd_utf8_ranges : bool ,
62
65
63
66
arg_pattern : String ,
64
67
arg_patterns : Vec < String > ,
68
+ arg_class : String ,
65
69
66
70
flag_size_limit : usize ,
67
71
flag_bytes : bool ,
@@ -108,6 +112,8 @@ fn run(args: &Args) -> Result<()> {
108
112
cmd_captures ( args)
109
113
} else if args. cmd_compile {
110
114
cmd_compile ( args)
115
+ } else if args. cmd_utf8_ranges {
116
+ cmd_utf8_ranges ( args)
111
117
} else {
112
118
unreachable ! ( )
113
119
}
@@ -202,6 +208,37 @@ fn cmd_compile(args: &Args) -> Result<()> {
202
208
Ok ( ( ) )
203
209
}
204
210
211
+ fn cmd_utf8_ranges ( args : & Args ) -> Result < ( ) > {
212
+ use syntax:: ParserBuilder ;
213
+ use syntax:: hir:: { self , HirKind } ;
214
+ use utf8_ranges:: Utf8Sequences ;
215
+
216
+ let hir = try!( ParserBuilder :: new ( )
217
+ . build ( )
218
+ . parse ( & format ! ( "[{}]" , args. arg_class) ) ) ;
219
+ let cls = match hir. into_kind ( ) {
220
+ HirKind :: Class ( hir:: Class :: Unicode ( cls) ) => cls,
221
+ _ => return Err (
222
+ format ! ( "unexpected HIR, expected Unicode class" ) . into ( ) ,
223
+ ) ,
224
+ } ;
225
+ for ( i, range) in cls. iter ( ) . enumerate ( ) {
226
+ if i > 0 {
227
+ println ! ( "----------------------------" ) ;
228
+ }
229
+ for seq in Utf8Sequences :: new ( range. start ( ) , range. end ( ) ) {
230
+ for ( i, utf8_range) in seq. into_iter ( ) . enumerate ( ) {
231
+ if i > 0 {
232
+ print ! ( "|" ) ;
233
+ }
234
+ print ! ( "[{:02X}-{:02X}]" , utf8_range. start, utf8_range. end) ;
235
+ }
236
+ println ! ( ) ;
237
+ }
238
+ }
239
+ Ok ( ( ) )
240
+ }
241
+
205
242
impl Args {
206
243
fn parse_one ( & self ) -> Result < Hir > {
207
244
parse ( & self . arg_pattern )
0 commit comments