Replace num-bigint with malachite-bigint (#18)

Co-authored-by: Jeong YunWon <jeong@youknowone.org>
This commit is contained in:
Steve Shi 2023-06-02 10:06:18 +02:00 committed by GitHub
parent 5e9e8a7589
commit a2e3209c42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 51 additions and 37 deletions

View file

@ -28,6 +28,7 @@
//!
//! [Lexical analysis]: https://docs.python.org/3/reference/lexical_analysis.html
use crate::{
ast::bigint::BigInt,
soft_keywords::SoftKeywordTransformer,
string::FStringErrorType,
text_size::{TextLen, TextRange, TextSize},
@ -35,7 +36,6 @@ use crate::{
Mode,
};
use log::trace;
use num_bigint::BigInt;
use num_traits::{Num, Zero};
use std::{char, cmp::Ordering, ops::Index, slice::SliceIndex, str::FromStr};
use unic_emoji_char::is_emoji_presentation;
@ -466,6 +466,13 @@ where
}
}
#[cfg(feature = "full-lexer")]
fn lex_and_emit_comment(&mut self) -> Result<(), LexicalError> {
let comment = self.lex_comment()?;
self.emit(comment);
Ok(())
}
/// Discard comment if full-lexer is not enabled.
#[cfg(not(feature = "full-lexer"))]
fn lex_comment(&mut self) {
@ -480,6 +487,13 @@ where
}
}
#[cfg(not(feature = "full-lexer"))]
#[inline]
fn lex_and_emit_comment(&mut self) -> Result<(), LexicalError> {
self.lex_comment();
Ok(())
}
/// Lex a string literal.
fn lex_string(&mut self, kind: StringKind) -> LexResult {
let start_pos = self.get_pos();
@ -626,9 +640,7 @@ where
tabs += 1;
}
Some('#') => {
let _comment = self.lex_comment();
#[cfg(feature = "full-lexer")]
self.emit(_comment?);
self.lex_and_emit_comment()?;
spaces = 0;
tabs = 0;
}
@ -775,9 +787,7 @@ where
self.emit(number);
}
'#' => {
let _comment = self.lex_comment();
#[cfg(feature = "full-lexer")]
self.emit(_comment?);
self.lex_and_emit_comment()?;
}
'"' | '\'' => {
let string = self.lex_string(StringKind::String)?;
@ -1360,7 +1370,7 @@ impl std::fmt::Display for LexicalErrorType {
#[cfg(test)]
mod tests {
use super::*;
use num_bigint::BigInt;
use crate::ast::bigint::BigInt;
const WINDOWS_EOL: &str = "\r\n";
const MAC_EOL: &str = "\r";