@@ -24,6 +24,19 @@ impl ConfigurationSection {
2424 fn get_section < I : Iterator < Item = String > > (
2525 file : & mut Enumerate < I > ,
2626 ) -> Option < ConfigurationSection > {
27+ lazy_static ! {
28+ static ref CONFIG_NAME_REGEX : regex:: Regex =
29+ regex:: Regex :: new( r"^## `([^`]+)`" ) . expect( "failed creating configuration pattern" ) ;
30+ // Configuration values, which will be passed to `from_str`:
31+ //
32+ // - must be prefixed with `####`
33+ // - must be wrapped in backticks
34+ // - may by wrapped in double quotes (which will be stripped)
35+ static ref CONFIG_VALUE_REGEX : regex:: Regex =
36+ regex:: Regex :: new( r#"^#### `"?([^`]+?)"?`"# )
37+ . expect( "failed creating configuration value pattern" ) ;
38+ }
39+
2740 loop {
2841 match file. next ( ) {
2942 Some ( ( i, line) ) => {
@@ -40,14 +53,9 @@ impl ConfigurationSection {
4053 let start_line = ( i + 2 ) as u32 ;
4154
4255 return Some ( ConfigurationSection :: CodeBlock ( ( block, start_line) ) ) ;
43- } else if let Some ( c) = static_regex ! ( r"^## `([^`]+)`" ) . captures ( & line) {
56+ } else if let Some ( c) = CONFIG_NAME_REGEX . captures ( & line) {
4457 return Some ( ConfigurationSection :: ConfigName ( String :: from ( & c[ 1 ] ) ) ) ;
45- } else if let Some ( c) = static_regex ! ( r#"^#### `"?([^`]+?)"?`"# ) . captures ( & line) {
46- // Configuration values, which will be passed to `from_str`
47- //
48- // - must be prefixed with `####`
49- // - must be wrapped in backticks
50- // - may by wrapped in double quotes (which will be stripped)
58+ } else if let Some ( c) = CONFIG_VALUE_REGEX . captures ( & line) {
5159 return Some ( ConfigurationSection :: ConfigValue ( String :: from ( & c[ 1 ] ) ) ) ;
5260 }
5361 }
0 commit comments