@@ -4,6 +4,7 @@ extern crate regex_syntax2 as syntax;
44extern crate serde;
55#[ macro_use]
66extern crate serde_derive;
7+ extern crate utf8_ranges;
78
89use std:: error;
910use std:: io:: { self , Write } ;
2425 regex-debug [options] anchors <pattern>
2526 regex-debug [options] captures <pattern>
2627 regex-debug [options] compile <patterns> ...
28+ regex-debug [options] utf8-ranges <class>
2729 regex-debug --help
2830
2931Options:
@@ -59,9 +61,11 @@ struct Args {
5961 cmd_anchors : bool ,
6062 cmd_captures : bool ,
6163 cmd_compile : bool ,
64+ cmd_utf8_ranges : bool ,
6265
6366 arg_pattern : String ,
6467 arg_patterns : Vec < String > ,
68+ arg_class : String ,
6569
6670 flag_size_limit : usize ,
6771 flag_bytes : bool ,
@@ -108,6 +112,8 @@ fn run(args: &Args) -> Result<()> {
108112 cmd_captures ( args)
109113 } else if args. cmd_compile {
110114 cmd_compile ( args)
115+ } else if args. cmd_utf8_ranges {
116+ cmd_utf8_ranges ( args)
111117 } else {
112118 unreachable ! ( )
113119 }
@@ -202,6 +208,37 @@ fn cmd_compile(args: &Args) -> Result<()> {
202208 Ok ( ( ) )
203209}
204210
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+
205242impl Args {
206243 fn parse_one ( & self ) -> Result < Hir > {
207244 parse ( & self . arg_pattern )
0 commit comments