|
2 | 2 | This module provides a regular expression parser. |
3 | 3 | */ |
4 | 4 |
|
5 | | -use std::borrow::Borrow; |
6 | | -use std::cell::{Cell, RefCell}; |
7 | | -use std::mem; |
8 | | -use std::result; |
9 | | - |
10 | | -use crate::ast::{self, Ast, Position, Span}; |
11 | | -use crate::either::Either; |
12 | | - |
13 | | -use crate::is_meta_character; |
14 | | - |
15 | | -type Result<T> = result::Result<T, ast::Error>; |
| 5 | +use core::{ |
| 6 | + borrow::Borrow, |
| 7 | + cell::{Cell, RefCell}, |
| 8 | + mem, |
| 9 | +}; |
| 10 | + |
| 11 | +use alloc::{ |
| 12 | + boxed::Box, |
| 13 | + string::{String, ToString}, |
| 14 | + vec, |
| 15 | + vec::Vec, |
| 16 | +}; |
| 17 | + |
| 18 | +use crate::{ |
| 19 | + ast::{self, Ast, Position, Span}, |
| 20 | + either::Either, |
| 21 | + is_meta_character, |
| 22 | +}; |
| 23 | + |
| 24 | +type Result<T> = core::result::Result<T, ast::Error>; |
16 | 25 |
|
17 | 26 | /// A primitive is an expression with no sub-expressions. This includes |
18 | 27 | /// literals, assertions and non-set character classes. This representation |
@@ -1533,9 +1542,6 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> { |
1533 | 1542 | /// Assuming the preconditions are met, this routine can never fail. |
1534 | 1543 | #[inline(never)] |
1535 | 1544 | fn parse_octal(&self) -> ast::Literal { |
1536 | | - use std::char; |
1537 | | - use std::u32; |
1538 | | - |
1539 | 1545 | assert!(self.parser().octal); |
1540 | 1546 | assert!('0' <= self.char() && self.char() <= '7'); |
1541 | 1547 | let start = self.pos(); |
@@ -1600,9 +1606,6 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> { |
1600 | 1606 | &self, |
1601 | 1607 | kind: ast::HexLiteralKind, |
1602 | 1608 | ) -> Result<ast::Literal> { |
1603 | | - use std::char; |
1604 | | - use std::u32; |
1605 | | - |
1606 | 1609 | let mut scratch = self.parser().scratch.borrow_mut(); |
1607 | 1610 | scratch.clear(); |
1608 | 1611 |
|
@@ -1646,9 +1649,6 @@ impl<'s, P: Borrow<Parser>> ParserI<'s, P> { |
1646 | 1649 | &self, |
1647 | 1650 | kind: ast::HexLiteralKind, |
1648 | 1651 | ) -> Result<ast::Literal> { |
1649 | | - use std::char; |
1650 | | - use std::u32; |
1651 | | - |
1652 | 1652 | let mut scratch = self.parser().scratch.borrow_mut(); |
1653 | 1653 | scratch.clear(); |
1654 | 1654 |
|
@@ -2146,7 +2146,7 @@ impl<'p, 's, P: Borrow<Parser>> NestLimiter<'p, 's, P> { |
2146 | 2146 | let new = self.depth.checked_add(1).ok_or_else(|| { |
2147 | 2147 | self.p.error( |
2148 | 2148 | span.clone(), |
2149 | | - ast::ErrorKind::NestLimitExceeded(::std::u32::MAX), |
| 2149 | + ast::ErrorKind::NestLimitExceeded(u32::MAX), |
2150 | 2150 | ) |
2151 | 2151 | })?; |
2152 | 2152 | let limit = self.p.parser().nest_limit; |
@@ -2297,11 +2297,14 @@ fn specialize_err<T>( |
2297 | 2297 |
|
2298 | 2298 | #[cfg(test)] |
2299 | 2299 | mod tests { |
2300 | | - use std::ops::Range; |
| 2300 | + use core::ops::Range; |
| 2301 | + |
| 2302 | + use alloc::format; |
2301 | 2303 |
|
2302 | | - use super::{Parser, ParserBuilder, ParserI, Primitive}; |
2303 | 2304 | use crate::ast::{self, Ast, Position, Span}; |
2304 | 2305 |
|
| 2306 | + use super::*; |
| 2307 | + |
2305 | 2308 | // Our own assert_eq, which has slightly better formatting (but honestly |
2306 | 2309 | // still kind of crappy). |
2307 | 2310 | macro_rules! assert_eq { |
@@ -4272,7 +4275,7 @@ bar |
4272 | 4275 | Ok(Primitive::Literal(ast::Literal { |
4273 | 4276 | span: span(0..pat.len()), |
4274 | 4277 | kind: ast::LiteralKind::Octal, |
4275 | | - c: ::std::char::from_u32(i).unwrap(), |
| 4278 | + c: char::from_u32(i).unwrap(), |
4276 | 4279 | })) |
4277 | 4280 | ); |
4278 | 4281 | } |
@@ -4347,7 +4350,7 @@ bar |
4347 | 4350 | Ok(Primitive::Literal(ast::Literal { |
4348 | 4351 | span: span(0..pat.len()), |
4349 | 4352 | kind: ast::LiteralKind::HexFixed(ast::HexLiteralKind::X), |
4350 | | - c: ::std::char::from_u32(i).unwrap(), |
| 4353 | + c: char::from_u32(i).unwrap(), |
4351 | 4354 | })) |
4352 | 4355 | ); |
4353 | 4356 | } |
@@ -4378,7 +4381,7 @@ bar |
4378 | 4381 | #[test] |
4379 | 4382 | fn parse_hex_four() { |
4380 | 4383 | for i in 0..65536 { |
4381 | | - let c = match ::std::char::from_u32(i) { |
| 4384 | + let c = match char::from_u32(i) { |
4382 | 4385 | None => continue, |
4383 | 4386 | Some(c) => c, |
4384 | 4387 | }; |
@@ -4442,7 +4445,7 @@ bar |
4442 | 4445 | #[test] |
4443 | 4446 | fn parse_hex_eight() { |
4444 | 4447 | for i in 0..65536 { |
4445 | | - let c = match ::std::char::from_u32(i) { |
| 4448 | + let c = match char::from_u32(i) { |
4446 | 4449 | None => continue, |
4447 | 4450 | Some(c) => c, |
4448 | 4451 | }; |
|
0 commit comments