diff options
| author | Nick Cameron <ncameron@mozilla.com> | 2014-09-11 17:07:49 +1200 |
|---|---|---|
| committer | Nick Cameron <ncameron@mozilla.com> | 2014-09-19 15:11:00 +1200 |
| commit | ce0907e46e8e1aa23ee39f69e4f628f68bfbb0d7 (patch) | |
| tree | 9ea529bfee7d62b85288d37b0e2bbcdd1c866e0d /src/libregex | |
| parent | af3889f6979647b9bd2dc5f5132d80e3e5b405a5 (diff) | |
| download | rust-ce0907e46e8e1aa23ee39f69e4f628f68bfbb0d7.tar.gz rust-ce0907e46e8e1aa23ee39f69e4f628f68bfbb0d7.zip | |
Add enum variants to the type namespace
Change to resolve and update compiler and libs for uses. [breaking-change] Enum variants are now in both the value and type namespaces. This means that if you have a variant with the same name as a type in scope in a module, you will get a name clash and thus an error. The solution is to either rename the type or the variant.
Diffstat (limited to 'src/libregex')
| -rw-r--r-- | src/libregex/compile.rs | 4 | ||||
| -rw-r--r-- | src/libregex/lib.rs | 2 | ||||
| -rw-r--r-- | src/libregex/parse.rs | 26 | ||||
| -rw-r--r-- | src/libregex/re.rs | 22 |
4 files changed, 27 insertions, 27 deletions
diff --git a/src/libregex/compile.rs b/src/libregex/compile.rs index 869dd25e3fa..c4b517c5259 100644 --- a/src/libregex/compile.rs +++ b/src/libregex/compile.rs @@ -16,7 +16,7 @@ use std::cmp; use parse; use parse::{ Flags, FLAG_EMPTY, - Nothing, Literal, Dot, Class, Begin, End, WordBoundary, Capture, Cat, Alt, + Nothing, Literal, Dot, AstClass, Begin, End, WordBoundary, Capture, Cat, Alt, Rep, ZeroOne, ZeroMore, OneMore, }; @@ -148,7 +148,7 @@ impl<'r> Compiler<'r> { Nothing => {}, Literal(c, flags) => self.push(OneChar(c, flags)), Dot(nl) => self.push(Any(nl)), - Class(ranges, flags) => + AstClass(ranges, flags) => self.push(CharClass(ranges, flags)), Begin(flags) => self.push(EmptyBegin(flags)), End(flags) => self.push(EmptyEnd(flags)), diff --git a/src/libregex/lib.rs b/src/libregex/lib.rs index 4f849a8a67b..9ff65fe3e2a 100644 --- a/src/libregex/lib.rs +++ b/src/libregex/lib.rs @@ -425,7 +425,7 @@ pub mod native { FLAG_EMPTY, FLAG_NOCASE, FLAG_MULTI, FLAG_DOTNL, FLAG_SWAP_GREED, FLAG_NEGATED, }; - pub use re::{Dynamic, Native}; + pub use re::{Dynamic, ExDynamic, Native, ExNative}; pub use vm::{ MatchKind, Exists, Location, Submatches, StepState, StepMatchEarlyReturn, StepMatch, StepContinue, diff --git a/src/libregex/parse.rs b/src/libregex/parse.rs index 12555b7c443..ad60829c088 100644 --- a/src/libregex/parse.rs +++ b/src/libregex/parse.rs @@ -53,7 +53,7 @@ pub enum Ast { Nothing, Literal(char, Flags), Dot(Flags), - Class(Vec<(char, char)>, Flags), + AstClass(Vec<(char, char)>, Flags), Begin(Flags), End(Flags), WordBoundary(Flags), @@ -101,7 +101,7 @@ impl Greed { /// state. #[deriving(Show)] enum BuildAst { - Ast(Ast), + Expr(Ast), Paren(Flags, uint, String), // '(' Bar, // '|' } @@ -152,7 +152,7 @@ impl BuildAst { fn unwrap(self) -> Result<Ast, Error> { match self { - Ast(x) => Ok(x), + Expr(x) => Ok(x), _ => fail!("Tried to unwrap non-AST item: {}", self), } } @@ -311,7 +311,7 @@ impl<'a> Parser<'a> { } fn push(&mut self, ast: Ast) { - self.stack.push(Ast(ast)) + self.stack.push(Expr(ast)) } fn push_repeater(&mut self, c: char) -> Result<(), Error> { @@ -388,8 +388,8 @@ impl<'a> Parser<'a> { match c { '[' => match self.try_parse_ascii() { - Some(Class(asciis, flags)) => { - alts.push(Class(asciis, flags ^ negated)); + Some(AstClass(asciis, flags)) => { + alts.push(AstClass(asciis, flags ^ negated)); continue } Some(ast) => @@ -399,8 +399,8 @@ impl<'a> Parser<'a> { }, '\\' => { match try!(self.parse_escape()) { - Class(asciis, flags) => { - alts.push(Class(asciis, flags ^ negated)); + AstClass(asciis, flags) => { + alts.push(AstClass(asciis, flags ^ negated)); continue } Literal(c2, _) => c = c2, // process below @@ -417,7 +417,7 @@ impl<'a> Parser<'a> { ']' => { if ranges.len() > 0 { let flags = negated | (self.flags & FLAG_NOCASE); - let mut ast = Class(combine_ranges(ranges), flags); + let mut ast = AstClass(combine_ranges(ranges), flags); for alt in alts.into_iter() { ast = Alt(box alt, box ast) } @@ -485,7 +485,7 @@ impl<'a> Parser<'a> { Some(ranges) => { self.chari = closer; let flags = negated | (self.flags & FLAG_NOCASE); - Some(Class(combine_ranges(ranges), flags)) + Some(AstClass(combine_ranges(ranges), flags)) } } } @@ -611,7 +611,7 @@ impl<'a> Parser<'a> { let ranges = perl_unicode_class(c); let mut flags = self.flags & FLAG_NOCASE; if c.is_uppercase() { flags |= FLAG_NEGATED } - Ok(Class(ranges, flags)) + Ok(AstClass(ranges, flags)) } _ => { self.err(format!("Invalid escape sequence '\\\\{}'", @@ -655,7 +655,7 @@ impl<'a> Parser<'a> { name).as_slice()) } Some(ranges) => { - Ok(Class(ranges, negated | (self.flags & FLAG_NOCASE))) + Ok(AstClass(ranges, negated | (self.flags & FLAG_NOCASE))) } } } @@ -888,7 +888,7 @@ impl<'a> Parser<'a> { while i > from { i = i - 1; match self.stack.pop().unwrap() { - Ast(x) => combined = mk(x, combined), + Expr(x) => combined = mk(x, combined), _ => {}, } } diff --git a/src/libregex/re.rs b/src/libregex/re.rs index 8e4145b2a31..c2578d227ee 100644 --- a/src/libregex/re.rs +++ b/src/libregex/re.rs @@ -110,14 +110,14 @@ pub enum Regex { // See the comments for the `program` module in `lib.rs` for a more // detailed explanation for what `regex!` requires. #[doc(hidden)] - Dynamic(Dynamic), + Dynamic(ExDynamic), #[doc(hidden)] - Native(Native), + Native(ExNative), } #[deriving(Clone)] #[doc(hidden)] -pub struct Dynamic { +pub struct ExDynamic { original: String, names: Vec<Option<String>>, #[doc(hidden)] @@ -125,7 +125,7 @@ pub struct Dynamic { } #[doc(hidden)] -pub struct Native { +pub struct ExNative { #[doc(hidden)] pub original: &'static str, #[doc(hidden)] @@ -134,8 +134,8 @@ pub struct Native { pub prog: fn(MatchKind, &str, uint, uint) -> Vec<Option<uint>> } -impl Clone for Native { - fn clone(&self) -> Native { *self } +impl Clone for ExNative { + fn clone(&self) -> ExNative { *self } } impl fmt::Show for Regex { @@ -156,7 +156,7 @@ impl Regex { pub fn new(re: &str) -> Result<Regex, parse::Error> { let ast = try!(parse::parse(re)); let (prog, names) = Program::new(ast); - Ok(Dynamic(Dynamic { + Ok(Dynamic(ExDynamic { original: re.to_string(), names: names, prog: prog, @@ -510,8 +510,8 @@ impl Regex { /// Returns the original string of this regex. pub fn as_str<'a>(&'a self) -> &'a str { match *self { - Dynamic(Dynamic { ref original, .. }) => original.as_slice(), - Native(Native { ref original, .. }) => original.as_slice(), + Dynamic(ExDynamic { ref original, .. }) => original.as_slice(), + Native(ExNative { ref original, .. }) => original.as_slice(), } } @@ -915,8 +915,8 @@ fn exec(re: &Regex, which: MatchKind, input: &str) -> CaptureLocs { fn exec_slice(re: &Regex, which: MatchKind, input: &str, s: uint, e: uint) -> CaptureLocs { match *re { - Dynamic(Dynamic { ref prog, .. }) => vm::run(which, prog, input, s, e), - Native(Native { prog, .. }) => prog(which, input, s, e), + Dynamic(ExDynamic { ref prog, .. }) => vm::run(which, prog, input, s, e), + Native(ExNative { prog, .. }) => prog(which, input, s, e), } } |
