Move universal newline handling into its own crate (#4729)

This commit is contained in:
Charlie Marsh 2023-05-31 12:00:47 -04:00 committed by GitHub
parent e209b5fc5f
commit 9d0ffd33ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 80 additions and 51 deletions

View file

@ -1,8 +1,9 @@
use ruff_text_size::TextRange;
use rustpython_parser::Tok;
use std::fmt::{Debug, Formatter};
use std::ops::Deref;
use ruff_text_size::TextRange;
use rustpython_parser::Tok;
/// Stores the ranges of comments sorted by [`TextRange::start`] in increasing order. No two ranges are overlapping.
#[derive(Clone)]
pub struct CommentRanges {

View file

@ -8,7 +8,8 @@ use rustpython_parser::ast::{
Excepthandler, Expr, Identifier, MatchCase, Operator, Pattern, Stmt, Suite, Withitem,
};
use crate::newlines::LineEnding;
use ruff_newlines::LineEnding;
use crate::source_code::stylist::{Indentation, Quote, Stylist};
mod precedence {
@ -1459,7 +1460,8 @@ mod tests {
use rustpython_ast::Suite;
use rustpython_parser::Parse;
use crate::newlines::LineEnding;
use ruff_newlines::LineEnding;
use crate::source_code::stylist::{Indentation, Quote};
use crate::source_code::Generator;

View file

@ -1,11 +1,11 @@
//! Struct used to index source code, to enable efficient lookup of tokens that
//! are omitted from the AST (e.g., commented lines).
use crate::source_code::comment_ranges::{CommentRanges, CommentRangesBuilder};
use ruff_text_size::{TextRange, TextSize};
use rustpython_parser::lexer::LexResult;
use rustpython_parser::{StringKind, Tok};
use crate::source_code::comment_ranges::{CommentRanges, CommentRangesBuilder};
use crate::source_code::Locator;
pub struct Indexer {

View file

@ -6,7 +6,8 @@ use memchr::{memchr2, memrchr2};
use once_cell::unsync::OnceCell;
use ruff_text_size::{TextLen, TextRange, TextSize};
use crate::newlines::find_newline;
use ruff_newlines::find_newline;
use crate::source_code::{LineIndex, OneIndexed, SourceCode, SourceLocation};
pub struct Locator<'a> {

View file

@ -7,13 +7,13 @@ use rustpython_parser::{ast, lexer, Mode, Parse, ParseError};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
pub use comment_ranges::{CommentRanges, CommentRangesBuilder};
pub use generator::Generator;
pub use indexer::Indexer;
pub use locator::Locator;
pub use stylist::{Quote, Stylist};
pub use crate::source_code::line_index::{LineIndex, OneIndexed};
pub use comment_ranges::{CommentRanges, CommentRangesBuilder};
mod comment_ranges;
mod generator;

View file

@ -4,11 +4,11 @@ use std::fmt;
use std::ops::Deref;
use once_cell::unsync::OnceCell;
use ruff_newlines::{find_newline, LineEnding};
use rustpython_literal::escape::Quote as StrQuote;
use rustpython_parser::lexer::LexResult;
use rustpython_parser::Tok;
use crate::newlines::{find_newline, LineEnding};
use crate::source_code::Locator;
use crate::str::leading_quote;
@ -166,7 +166,8 @@ mod tests {
use rustpython_parser::lexer::lex;
use rustpython_parser::Mode;
use crate::newlines::{find_newline, LineEnding};
use ruff_newlines::{find_newline, LineEnding};
use crate::source_code::stylist::{Indentation, Quote};
use crate::source_code::{Locator, Stylist};