mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-08 05:35:22 +00:00
dual bigint support
This commit is contained in:
parent
a70d14c9ba
commit
c0b7af1a4a
12 changed files with 47 additions and 33 deletions
14
.github/workflows/ci.yaml
vendored
14
.github/workflows/ci.yaml
vendored
|
@ -37,12 +37,10 @@ jobs:
|
|||
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
|
||||
- name: run tests with default features
|
||||
run: cargo test --all
|
||||
- name: run tests with embedded parser
|
||||
run: cargo test --all --no-default-features
|
||||
- name: run tests with generated parser
|
||||
run: cargo test --all --all-features
|
||||
- name: run tests with num-bigint
|
||||
run: cargo test --all --no-default-features --features num-bigint
|
||||
- name: run tests with malachite-bigint and all features
|
||||
run: cargo test --all --features location,malachite-bigint,constant-optimization,fold,unparse,visitor,all-nodes-with-ranges,full-lexer,serde --exclude rustpython-ast-pyo3
|
||||
|
||||
lint:
|
||||
name: Check Rust code with rustfmt and clippy
|
||||
|
@ -55,7 +53,9 @@ jobs:
|
|||
- name: run rustfmt
|
||||
run: cargo fmt --all -- --check
|
||||
- name: run clippy
|
||||
run: cargo clippy --all --all-features -- -Dwarnings
|
||||
run: cargo clippy --all --no-default-features --features num-bigint
|
||||
- name: run clippy
|
||||
run: cargo clippy --all --features location,malachite-bigint,constant-optimization,fold,unparse,visitor,all-nodes-with-ranges,full-lexer,serde --exclude rustpython-ast-pyo3 -- -Dwarnings
|
||||
|
||||
- uses: actions/setup-python@v4
|
||||
with:
|
||||
|
|
|
@ -21,7 +21,7 @@ rustpython-ast = { path = "ast", default-features = false }
|
|||
rustpython-parser-core = { path = "core", features = [] }
|
||||
rustpython-literal = { path = "literal" }
|
||||
rustpython-format = { path = "format" }
|
||||
rustpython-parser = { path = "parser" }
|
||||
rustpython-parser = { path = "parser", default-features = false }
|
||||
|
||||
ahash = "0.7.6"
|
||||
anyhow = "1.0.45"
|
||||
|
@ -34,7 +34,7 @@ num-complex = "0.4.0"
|
|||
num-bigint = "0.4.3"
|
||||
num-traits = "0.2"
|
||||
pyo3 = { version = "0.18.3" }
|
||||
malachite-bigint = { version = "0.1.8", git = "https://github.com/RustPython/malachite-bigint.git" }
|
||||
malachite-bigint = { version = "0.1.0" }
|
||||
rand = "0.8.5"
|
||||
serde = "1.0"
|
||||
static_assertions = "1.1"
|
||||
|
|
|
@ -14,7 +14,7 @@ crate-type = ["cdylib"]
|
|||
|
||||
[dependencies]
|
||||
rustpython-ast = { workspace = true, features = ["location"] }
|
||||
rustpython-parser = { workspace = true }
|
||||
rustpython-parser = { workspace = true, features = ["num-bigint"] }
|
||||
num-complex = { workspace = true }
|
||||
once_cell = { workspace = true }
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ repository = "https://github.com/RustPython/Parser/"
|
|||
license = "MIT"
|
||||
|
||||
[features]
|
||||
default = ["location"]
|
||||
default = ["location", "malachite-bigint"]
|
||||
constant-optimization = ["fold"]
|
||||
location = ["fold", "rustpython-parser-core/location"]
|
||||
fold = []
|
||||
|
@ -22,6 +22,5 @@ rustpython-literal = { workspace = true, optional = true }
|
|||
|
||||
is-macro = { workspace = true }
|
||||
num-bigint = { workspace = true, optional = true }
|
||||
malachite-bigint = { workspace = true, optional = true }
|
||||
static_assertions = "1.1.0"
|
||||
|
||||
malachite-bigint = { workspace = true }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! `builtin_types` in asdl.py and Attributed
|
||||
|
||||
use malachite_bigint::BigInt;
|
||||
use crate::bigint::BigInt;
|
||||
|
||||
pub type String = std::string::String;
|
||||
|
||||
|
|
|
@ -14,6 +14,11 @@ mod ranged;
|
|||
#[cfg(feature = "unparse")]
|
||||
mod unparse;
|
||||
|
||||
#[cfg(feature = "malachite-bigint")]
|
||||
pub use malachite_bigint as bigint;
|
||||
#[cfg(feature = "num-bigint")]
|
||||
pub use num_bigint as bigint;
|
||||
|
||||
pub use builtin::*;
|
||||
pub use generic::*;
|
||||
pub use ranged::Ranged;
|
||||
|
|
|
@ -55,7 +55,7 @@ impl<U> crate::fold::Fold<U> for ConstantOptimizer {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use malachite_bigint::BigInt;
|
||||
use crate::bigint::BigInt;
|
||||
use rustpython_parser_core::text_size::TextRange;
|
||||
|
||||
#[cfg(feature = "constant-optimization")]
|
||||
|
|
|
@ -9,11 +9,13 @@ license = "MIT"
|
|||
edition = "2021"
|
||||
|
||||
[features]
|
||||
default = ["location"]
|
||||
default = ["location", "malachite-bigint"]
|
||||
location = ["rustpython-ast/location", "rustpython-parser-core/location"]
|
||||
serde = ["dep:serde", "rustpython-parser-core/serde"]
|
||||
all-nodes-with-ranges = ["rustpython-ast/all-nodes-with-ranges"]
|
||||
full-lexer = []
|
||||
malachite-bigint = ["dep:malachite-bigint", "rustpython-ast/malachite-bigint"]
|
||||
num-bigint = ["dep:num-bigint", "rustpython-ast/num-bigint"]
|
||||
|
||||
[build-dependencies]
|
||||
anyhow = { workspace = true }
|
||||
|
@ -28,7 +30,8 @@ rustpython-parser-core = { workspace = true }
|
|||
itertools = { workspace = true }
|
||||
is-macro = { workspace = true }
|
||||
log = { workspace = true }
|
||||
malachite-bigint = { workspace = true }
|
||||
malachite-bigint = { workspace = true, optional = true }
|
||||
num-bigint = { workspace = true, optional = true }
|
||||
num-traits = { workspace = true }
|
||||
unicode_names2 = { workspace = true }
|
||||
|
||||
|
|
|
@ -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 malachite_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 malachite_bigint::BigInt;
|
||||
use crate::ast::bigint::BigInt;
|
||||
|
||||
const WINDOWS_EOL: &str = "\r\n";
|
||||
const MAC_EOL: &str = "\r";
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
// See also: https://greentreesnakes.readthedocs.io/en/latest/nodes.html#keyword
|
||||
|
||||
use crate::{
|
||||
ast::{self as ast, Ranged},
|
||||
ast::{self as ast, Ranged, bigint::BigInt},
|
||||
lexer::{LexicalError, LexicalErrorType},
|
||||
function::{ArgumentList, parse_args, validate_pos_params, validate_arguments},
|
||||
context::set_context,
|
||||
|
@ -12,7 +12,6 @@ use crate::{
|
|||
token::{self, StringKind},
|
||||
text_size::TextSize, parser::optional_range
|
||||
};
|
||||
use malachite_bigint::BigInt;
|
||||
|
||||
grammar;
|
||||
|
||||
|
|
8
parser/src/python.rs
generated
8
parser/src/python.rs
generated
|
@ -1,7 +1,7 @@
|
|||
// auto-generated: "lalrpop 0.20.0"
|
||||
// sha3: 5b283ac4fb75961faa865fa48facd04eb934dc9500dc46f3c7c128ba0d860a73
|
||||
// sha3: b94dbacf01253c4fc4605d489e98f5929504a78e0baa83381e126895ec61cb59
|
||||
use crate::{
|
||||
ast::{self as ast, Ranged},
|
||||
ast::{self as ast, Ranged, bigint::BigInt},
|
||||
lexer::{LexicalError, LexicalErrorType},
|
||||
function::{ArgumentList, parse_args, validate_pos_params, validate_arguments},
|
||||
context::set_context,
|
||||
|
@ -9,7 +9,6 @@ use crate::{
|
|||
token::{self, StringKind},
|
||||
text_size::TextSize, parser::optional_range
|
||||
};
|
||||
use malachite_bigint::BigInt;
|
||||
#[allow(unused_extern_crates)]
|
||||
extern crate lalrpop_util as __lalrpop_util;
|
||||
#[allow(unused_imports)]
|
||||
|
@ -22,7 +21,7 @@ extern crate alloc;
|
|||
mod __parse__Top {
|
||||
|
||||
use crate::{
|
||||
ast::{self as ast, Ranged},
|
||||
ast::{self as ast, Ranged, bigint::BigInt},
|
||||
lexer::{LexicalError, LexicalErrorType},
|
||||
function::{ArgumentList, parse_args, validate_pos_params, validate_arguments},
|
||||
context::set_context,
|
||||
|
@ -30,7 +29,6 @@ mod __parse__Top {
|
|||
token::{self, StringKind},
|
||||
text_size::TextSize, parser::optional_range
|
||||
};
|
||||
use malachite_bigint::BigInt;
|
||||
#[allow(unused_extern_crates)]
|
||||
extern crate lalrpop_util as __lalrpop_util;
|
||||
#[allow(unused_imports)]
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
//! loosely based on the token definitions found in the [CPython source].
|
||||
//!
|
||||
//! [CPython source]: https://github.com/python/cpython/blob/dfc2e065a2e71011017077e549cd2f9bf4944c54/Include/internal/pycore_token.h
|
||||
use crate::ast::bigint::BigInt;
|
||||
use crate::{text_size::TextSize, Mode};
|
||||
use malachite_bigint::BigInt;
|
||||
use std::fmt;
|
||||
|
||||
/// The set of tokens the Python source code can be tokenized in.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue