Skip to content

Commit 744f28b

Browse files
committed
regex: move to regex-syntax-2
This commit moves the entire regex crate over to the regex-syntax-2 rewrite. Most of this is just rewriting types. The compiler got the most interesting set of changes. It got simpler in some respects, but not significantly so.
1 parent c18abfa commit 744f28b

File tree

10 files changed

+166
-188
lines changed

10 files changed

+166
-188
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ travis-ci = { repository = "rust-lang/regex" }
1818
appveyor = { repository = "rust-lang-libs/regex" }
1919

2020
[workspace]
21-
members = ["bench", "regex-capi", "regex-debug", "regex-syntax"]
21+
members = [
22+
"bench", "regex-capi", "regex-debug", "regex-syntax", "regex-syntax-2",
23+
]
2224

2325
[dependencies]
2426
# For very fast prefix literal matching.
@@ -29,6 +31,7 @@ memchr = "2.0.0"
2931
thread_local = "0.3.2"
3032
# For parsing regular expressions.
3133
regex-syntax = { path = "regex-syntax", version = "0.4.1" }
34+
regex-syntax2 = { path = "regex-syntax-2", version = "0.5.0" }
3235
# For accelerating text search.
3336
simd = { version = "0.2.1", optional = true }
3437
# For compiling UTF-8 decoding into automata.

regex-debug/src/main.rs

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
extern crate docopt;
22
extern crate regex;
3-
extern crate regex_syntax as syntax;
4-
extern crate regex_syntax2;
3+
extern crate regex_syntax2 as syntax;
54
extern crate serde;
65
#[macro_use]
76
extern crate serde_derive;
@@ -12,14 +11,14 @@ use std::process;
1211
use std::result;
1312

1413
use docopt::Docopt;
14+
use syntax::hir::Hir;
15+
use syntax::hir::literal::Literals;
1516
use regex::internal::{Compiler, LiteralSearcher};
16-
use syntax::{ExprBuilder, Expr, Literals};
1717

1818
const USAGE: &'static str = "
1919
Usage:
2020
regex-debug [options] ast <pattern>
21-
regex-debug [options] ast2 <pattern>
22-
regex-debug [options] hir2 <pattern>
21+
regex-debug [options] hir <pattern>
2322
regex-debug [options] prefixes <patterns> ...
2423
regex-debug [options] suffixes <patterns> ...
2524
regex-debug [options] anchors <pattern>
@@ -54,8 +53,7 @@ Options:
5453
#[derive(Deserialize)]
5554
struct Args {
5655
cmd_ast: bool,
57-
cmd_ast2: bool,
58-
cmd_hir2: bool,
56+
cmd_hir: bool,
5957
cmd_prefixes: bool,
6058
cmd_suffixes: bool,
6159
cmd_anchors: bool,
@@ -98,10 +96,8 @@ fn main() {
9896
fn run(args: &Args) -> Result<()> {
9997
if args.cmd_ast {
10098
cmd_ast(args)
101-
} else if args.cmd_ast2 {
102-
cmd_ast2(args)
103-
} else if args.cmd_hir2 {
104-
cmd_hir2(args)
99+
} else if args.cmd_hir {
100+
cmd_hir(args)
105101
} else if args.cmd_prefixes {
106102
cmd_literals(args)
107103
} else if args.cmd_suffixes {
@@ -118,22 +114,16 @@ fn run(args: &Args) -> Result<()> {
118114
}
119115

120116
fn cmd_ast(args: &Args) -> Result<()> {
121-
let ast = try!(args.parse_one());
122-
println!("{:#?}", ast);
123-
Ok(())
124-
}
125-
126-
fn cmd_ast2(args: &Args) -> Result<()> {
127-
use regex_syntax2::ast::parse::Parser;
117+
use syntax::ast::parse::Parser;
128118

129119
let mut parser = Parser::new();
130120
let ast = try!(parser.parse(&args.arg_pattern));
131121
println!("{:#?}", ast);
132122
Ok(())
133123
}
134124

135-
fn cmd_hir2(args: &Args) -> Result<()> {
136-
use regex_syntax2::ParserBuilder;
125+
fn cmd_hir(args: &Args) -> Result<()> {
126+
use syntax::ParserBuilder;
137127

138128
let mut parser = ParserBuilder::new()
139129
.allow_invalid_utf8(false)
@@ -213,17 +203,17 @@ fn cmd_compile(args: &Args) -> Result<()> {
213203
}
214204

215205
impl Args {
216-
fn parse_one(&self) -> Result<Expr> {
206+
fn parse_one(&self) -> Result<Hir> {
217207
parse(&self.arg_pattern)
218208
}
219209

220-
fn parse_many(&self) -> Result<Vec<Expr>> {
210+
fn parse_many(&self) -> Result<Vec<Hir>> {
221211
self.arg_patterns.iter().map(|s| parse(s)).collect()
222212
}
223213

224-
fn literals<F: Fn(&mut Literals, &Expr) -> bool>(
214+
fn literals<F: Fn(&mut Literals, &Hir) -> bool>(
225215
&self,
226-
exprs: &[Expr],
216+
exprs: &[Hir],
227217
get_literals: F,
228218
) -> Literals {
229219
let mut lits = Some(self.empty_literals());
@@ -251,8 +241,13 @@ impl Args {
251241
}
252242
}
253243

254-
fn parse(re: &str) -> Result<Expr> {
255-
ExprBuilder::new().allow_bytes(true).parse(re).map_err(From::from)
244+
fn parse(re: &str) -> Result<Hir> {
245+
use syntax::ParserBuilder;
246+
ParserBuilder::new()
247+
.allow_invalid_utf8(true)
248+
.build()
249+
.parse(re)
250+
.map_err(From::from)
256251
}
257252

258253
fn escape_unicode(bytes: &[u8]) -> String {

0 commit comments

Comments
 (0)