Skip to content

Commit

Permalink
Fixes after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
defuz committed Feb 18, 2016
1 parent e4f54de commit f9cc5d6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::collections::HashMap;
use std::sync::Arc;

use backtrack::{self, Backtrack};
use dfa::{self, Dfa, DfaResult};
use input::{ByteInput, CharInput};
Expand Down Expand Up @@ -375,6 +378,12 @@ impl Exec {
&self.prog.cap_names
}

/// Return a reference to named groups mapping (from group name to
/// group position).
pub fn named_groups(&self) -> &Arc<HashMap<String, usize>> {
&self.prog.named_groups
}

/// Return a fresh allocation for storing all possible captures in the
/// underlying regular expression.
pub fn alloc_captures(&self) -> Vec<Option<usize>> {
Expand Down
8 changes: 7 additions & 1 deletion src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::{char, cmp};
use std::collections::HashMap;
use std::sync::Arc;

Expand Down Expand Up @@ -122,10 +121,17 @@ impl ProgramBuilder {
insts.anchored_begin(),
insts.anchored_end(),
);
let mut named_groups = HashMap::new();
for (i, name) in cap_names.iter().enumerate() {
if let Some(ref name) = *name {
named_groups.insert(name.to_owned(), i);
}
}
Ok(Program {
original: self.re,
insts: insts,
cap_names: cap_names,
named_groups: Arc::new(named_groups),
prefixes: prefixes,
anchored_begin: anchored_begin,
anchored_end: anchored_end,
Expand Down
4 changes: 2 additions & 2 deletions src/re.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,8 @@ impl NamedGroups {
match *regex {
Regex::Native(ExNative { ref groups, .. }) =>
NamedGroups::Native(groups),
Regex::Dynamic(Program { ref named_groups, .. }) =>
NamedGroups::Dynamic(named_groups.clone())
Regex::Dynamic(ref exec) =>
NamedGroups::Dynamic(exec.named_groups().clone())
}
}

Expand Down

0 comments on commit f9cc5d6

Please sign in to comment.