diff options
| author | Aleksey Kladov <aleksey.kladov@gmail.com> | 2019-07-21 16:46:11 +0300 |
|---|---|---|
| committer | Aleksey Kladov <aleksey.kladov@gmail.com> | 2019-07-21 16:46:11 +0300 |
| commit | e63fe150bfbce632dd7ff0a656a4180557128e4f (patch) | |
| tree | 170f3255b60200428510d1398c66150b89556e4e /src | |
| parent | 83dfe7b27cf2debecebedd3b038f9a1c2e05e051 (diff) | |
| download | rust-e63fe150bfbce632dd7ff0a656a4180557128e4f.tar.gz rust-e63fe150bfbce632dd7ff0a656a4180557128e4f.zip | |
move unescape module to rustc_lexer
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_lexer/src/lib.rs | 1 | ||||
| -rw-r--r-- | src/librustc_lexer/src/unescape.rs (renamed from src/libsyntax/parse/unescape.rs) | 22 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/literal.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/parse/unescape_error_reporting.rs | 3 |
6 files changed, 17 insertions, 18 deletions
diff --git a/src/librustc_lexer/src/lib.rs b/src/librustc_lexer/src/lib.rs index a21190ec332..12e095b8bd5 100644 --- a/src/librustc_lexer/src/lib.rs +++ b/src/librustc_lexer/src/lib.rs @@ -4,6 +4,7 @@ #![cfg_attr(not(feature = "unicode-xid"), feature(unicode_internals))] mod cursor; +pub mod unescape; use crate::cursor::{Cursor, EOF_CHAR}; diff --git a/src/libsyntax/parse/unescape.rs b/src/librustc_lexer/src/unescape.rs index 87cc9c1c9e3..70085df9948 100644 --- a/src/libsyntax/parse/unescape.rs +++ b/src/librustc_lexer/src/unescape.rs @@ -5,7 +5,7 @@ use std::str::Chars; use std::ops::Range; #[derive(Debug, PartialEq, Eq)] -pub(crate) enum EscapeError { +pub enum EscapeError { ZeroChars, MoreThanOneChar, @@ -35,7 +35,7 @@ pub(crate) enum EscapeError { /// Takes a contents of a char literal (without quotes), and returns an /// unescaped char or an error -pub(crate) fn unescape_char(literal_text: &str) -> Result<char, (usize, EscapeError)> { +pub fn unescape_char(literal_text: &str) -> Result<char, (usize, EscapeError)> { let mut chars = literal_text.chars(); unescape_char_or_byte(&mut chars, Mode::Char) .map_err(|err| (literal_text.len() - chars.as_str().len(), err)) @@ -43,14 +43,14 @@ pub(crate) fn unescape_char(literal_text: &str) -> Result<char, (usize, EscapeEr /// Takes a contents of a string literal (without quotes) and produces a /// sequence of escaped characters or errors. -pub(crate) fn unescape_str<F>(literal_text: &str, callback: &mut F) +pub fn unescape_str<F>(literal_text: &str, callback: &mut F) where F: FnMut(Range<usize>, Result<char, EscapeError>), { unescape_str_or_byte_str(literal_text, Mode::Str, callback) } -pub(crate) fn unescape_byte(literal_text: &str) -> Result<u8, (usize, EscapeError)> { +pub fn unescape_byte(literal_text: &str) -> Result<u8, (usize, EscapeError)> { let mut chars = literal_text.chars(); unescape_char_or_byte(&mut chars, Mode::Byte) .map(byte_from_char) @@ -59,7 +59,7 @@ pub(crate) fn unescape_byte(literal_text: &str) -> Result<u8, (usize, EscapeErro /// Takes a contents of a string literal (without quotes) and produces a /// sequence of escaped characters or errors. -pub(crate) fn unescape_byte_str<F>(literal_text: &str, callback: &mut F) +pub fn unescape_byte_str<F>(literal_text: &str, callback: &mut F) where F: FnMut(Range<usize>, Result<u8, EscapeError>), { @@ -72,7 +72,7 @@ where /// sequence of characters or errors. /// NOTE: Raw strings do not perform any explicit character escaping, here we /// only translate CRLF to LF and produce errors on bare CR. -pub(crate) fn unescape_raw_str<F>(literal_text: &str, callback: &mut F) +pub fn unescape_raw_str<F>(literal_text: &str, callback: &mut F) where F: FnMut(Range<usize>, Result<char, EscapeError>), { @@ -83,7 +83,7 @@ where /// sequence of characters or errors. /// NOTE: Raw strings do not perform any explicit character escaping, here we /// only translate CRLF to LF and produce errors on bare CR. -pub(crate) fn unescape_raw_byte_str<F>(literal_text: &str, callback: &mut F) +pub fn unescape_raw_byte_str<F>(literal_text: &str, callback: &mut F) where F: FnMut(Range<usize>, Result<u8, EscapeError>), { @@ -93,7 +93,7 @@ where } #[derive(Debug, Clone, Copy)] -pub(crate) enum Mode { +pub enum Mode { Char, Str, Byte, @@ -101,18 +101,18 @@ pub(crate) enum Mode { } impl Mode { - fn in_single_quotes(self) -> bool { + pub fn in_single_quotes(self) -> bool { match self { Mode::Char | Mode::Byte => true, Mode::Str | Mode::ByteStr => false, } } - pub(crate) fn in_double_quotes(self) -> bool { + pub fn in_double_quotes(self) -> bool { !self.in_single_quotes() } - pub(crate) fn is_bytes(self) -> bool { + pub fn is_bytes(self) -> bool { match self { Mode::Byte | Mode::ByteStr => true, Mode::Char | Mode::Str => false, diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 317c49c7d35..ebb02737822 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -1,12 +1,12 @@ use crate::parse::ParseSess; use crate::parse::token::{self, Token, TokenKind}; use crate::symbol::{sym, Symbol}; -use crate::parse::unescape; use crate::parse::unescape_error_reporting::{emit_unescape_error, push_escaped_char}; use errors::{FatalError, Diagnostic, DiagnosticBuilder}; use syntax_pos::{BytePos, Pos, Span, NO_EXPANSION}; use rustc_lexer::Base; +use rustc_lexer::unescape; use std::borrow::Cow; use std::char; diff --git a/src/libsyntax/parse/literal.rs b/src/libsyntax/parse/literal.rs index 683d1641565..6409acba573 100644 --- a/src/libsyntax/parse/literal.rs +++ b/src/libsyntax/parse/literal.rs @@ -4,9 +4,6 @@ use crate::ast::{self, Lit, LitKind}; use crate::parse::parser::Parser; use crate::parse::PResult; use crate::parse::token::{self, Token, TokenKind}; -use crate::parse::unescape::{unescape_char, unescape_byte}; -use crate::parse::unescape::{unescape_str, unescape_byte_str}; -use crate::parse::unescape::{unescape_raw_str, unescape_raw_byte_str}; use crate::print::pprust; use crate::symbol::{kw, sym, Symbol}; use crate::tokenstream::{TokenStream, TokenTree}; @@ -15,6 +12,9 @@ use errors::{Applicability, Handler}; use log::debug; use rustc_data_structures::sync::Lrc; use syntax_pos::Span; +use rustc_lexer::unescape::{unescape_char, unescape_byte}; +use rustc_lexer::unescape::{unescape_str, unescape_byte_str}; +use rustc_lexer::unescape::{unescape_raw_str, unescape_raw_byte_str}; use std::ascii; diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 4c4551b1757..225065c1cf1 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -32,7 +32,6 @@ pub mod token; crate mod classify; crate mod diagnostics; crate mod literal; -crate mod unescape; crate mod unescape_error_reporting; /// Info about a parsing session. diff --git a/src/libsyntax/parse/unescape_error_reporting.rs b/src/libsyntax/parse/unescape_error_reporting.rs index 71b41161ad8..bc3ee8620e0 100644 --- a/src/libsyntax/parse/unescape_error_reporting.rs +++ b/src/libsyntax/parse/unescape_error_reporting.rs @@ -3,12 +3,11 @@ use std::ops::Range; use std::iter::once; +use rustc_lexer::unescape::{EscapeError, Mode}; use syntax_pos::{Span, BytePos}; use crate::errors::{Handler, Applicability}; -use super::unescape::{EscapeError, Mode}; - pub(crate) fn emit_unescape_error( handler: &Handler, // interior part of the literal, without quotes |
