Skip to content
This repository was archived by the owner on Jul 27, 2023. It is now read-only.

Commit 7cbec09

Browse files
committed
Cursor based lexer
1 parent 4d03b9b commit 7cbec09

24 files changed

+2664
-1639
lines changed

ast/Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@ edition = "2021"
77
repository = "https://github.com/RustPython/Parser/"
88
license = "MIT"
99

10-
[features]
11-
default = ["malachite-bigint"]
12-
1310
[dependencies]
1411
rustpython-parser-core = { workspace = true }
1512
rustpython-literal = { workspace = true, optional = true }
1613

1714
is-macro = { workspace = true }
18-
num-bigint = { workspace = true, optional = true }
19-
malachite-bigint = { workspace = true, optional = true }
15+
num-bigint = { workspace = true }
2016
static_assertions = "1.1.0"

ast/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use rustpython_parser_core::text_size::TextRange;
44

5-
use crate::bigint::BigInt;
65
use crate::Ranged;
6+
use num_bigint::BigInt;
77

88
pub type String = std::string::String;
99

ast/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ mod generic;
2020
mod impls;
2121
mod ranged;
2222

23-
#[cfg(feature = "malachite-bigint")]
24-
pub use malachite_bigint as bigint;
25-
#[cfg(all(feature = "num-bigint", not(feature = "malachite-bigint")))]
26-
pub use num_bigint as bigint;
27-
2823
pub use builtin::*;
2924
pub use generic::*;
3025
pub use ranged::Ranged;

format/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ rustpython-literal = { workspace = true }
1313
bitflags = "2.3.1"
1414
itertools = "0.10.5"
1515
num-traits = { workspace = true }
16-
num-bigint = { workspace = true, optional = true }
17-
malachite-bigint = { workspace = true, optional = true }
16+
num-bigint = { workspace = true }
1817

1918
[features]
20-
default = ["malachite-bigint"]

format/src/cformat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99
str::FromStr,
1010
};
1111

12-
use crate::bigint::{BigInt, Sign};
12+
use num_bigint::{BigInt, Sign};
1313

1414
#[derive(Debug, PartialEq)]
1515
pub enum CFormatErrorType {

format/src/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustpython_literal::format::Case;
66
use std::ops::Deref;
77
use std::{cmp, str::FromStr};
88

9-
use crate::bigint::{BigInt, Sign};
9+
use num_bigint::{BigInt, Sign};
1010

1111
trait FormatParse {
1212
fn parse(text: &str) -> (Option<Self>, &str)

format/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
#[cfg(feature = "malachite-bigint")]
2-
pub use malachite_bigint as bigint;
3-
#[cfg(all(feature = "num-bigint", not(feature = "malachite-bigint")))]
4-
pub use num_bigint as bigint;
5-
61
pub use crate::format::*;
72

83
pub mod cformat;

literal/src/escape.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl<'a> Escape for AsciiEscape<'a> {
385385
fn layout(&self) -> &EscapeLayout {
386386
&self.layout
387387
}
388-
388+
#[allow(unsafe_code)]
389389
fn write_source(&self, formatter: &mut impl std::fmt::Write) -> std::fmt::Result {
390390
formatter.write_str(unsafe {
391391
// SAFETY: this function must be called only when source is printable ascii characters

parser/Cargo.toml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ license = "MIT"
99
edition = "2021"
1010

1111
[features]
12-
default = ["malachite-bigint"]
1312
serde = ["dep:serde", "rustpython-parser-core/serde"]
14-
full-lexer = []
15-
malachite-bigint = ["dep:malachite-bigint", "rustpython-ast/malachite-bigint"]
16-
num-bigint = ["dep:num-bigint", "rustpython-ast/num-bigint"]
1713

1814
[build-dependencies]
1915
anyhow = { workspace = true }
@@ -28,17 +24,16 @@ rustpython-parser-core = { workspace = true }
2824
itertools = { workspace = true }
2925
is-macro = { workspace = true }
3026
log = { workspace = true }
31-
malachite-bigint = { workspace = true, optional = true }
32-
num-bigint = { workspace = true, optional = true }
27+
num-bigint = { workspace = true }
3328
num-traits = { workspace = true }
3429
unicode_names2 = { workspace = true }
3530

3631
unic-emoji-char = "0.9.0"
3732
unic-ucd-ident = "0.9.0"
3833
lalrpop-util = { version = "0.20.0", default-features = false }
39-
phf = "0.11.1"
4034
rustc-hash = "1.1.0"
4135
serde = { version = "1.0.133", optional = true, default-features = false, features = ["derive"] }
36+
static_assertions = "1.1.0"
4237

4338
[dev-dependencies]
4439
insta = { workspace = true }

parser/build.rs

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
use std::fmt::Write as _;
22
use std::fs::File;
3-
use std::io::{BufRead, BufReader, BufWriter, Write};
3+
use std::io::{BufRead, BufReader};
44
use std::path::{Path, PathBuf};
55
use tiny_keccak::{Hasher, Sha3};
66

77
fn main() -> anyhow::Result<()> {
8-
let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
9-
gen_phf(&out_dir);
10-
118
const SOURCE: &str = "src/python.lalrpop";
129
println!("cargo:rerun-if-changed={SOURCE}");
1310

@@ -16,6 +13,7 @@ fn main() -> anyhow::Result<()> {
1613

1714
#[cfg(feature = "lalrpop")]
1815
{
16+
let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
1917
target = out_dir.join("src/python.rs");
2018
}
2119
#[cfg(not(feature = "lalrpop"))]
@@ -113,55 +111,3 @@ fn sha_equal(expected_sha3_str: &str, actual_sha3: &[u8; 32]) -> bool {
113111
}
114112
*actual_sha3 == expected_sha3
115113
}
116-
117-
fn gen_phf(out_dir: &Path) {
118-
let mut kwds = phf_codegen::Map::new();
119-
let kwds = kwds
120-
// Alphabetical keywords:
121-
.entry("...", "Tok::Ellipsis")
122-
.entry("False", "Tok::False")
123-
.entry("None", "Tok::None")
124-
.entry("True", "Tok::True")
125-
// more so "standard" keywords
126-
.entry("and", "Tok::And")
127-
.entry("as", "Tok::As")
128-
.entry("assert", "Tok::Assert")
129-
.entry("async", "Tok::Async")
130-
.entry("await", "Tok::Await")
131-
.entry("break", "Tok::Break")
132-
.entry("case", "Tok::Case")
133-
.entry("class", "Tok::Class")
134-
.entry("continue", "Tok::Continue")
135-
.entry("def", "Tok::Def")
136-
.entry("del", "Tok::Del")
137-
.entry("elif", "Tok::Elif")
138-
.entry("else", "Tok::Else")
139-
.entry("except", "Tok::Except")
140-
.entry("finally", "Tok::Finally")
141-
.entry("for", "Tok::For")
142-
.entry("from", "Tok::From")
143-
.entry("global", "Tok::Global")
144-
.entry("if", "Tok::If")
145-
.entry("import", "Tok::Import")
146-
.entry("in", "Tok::In")
147-
.entry("is", "Tok::Is")
148-
.entry("lambda", "Tok::Lambda")
149-
.entry("match", "Tok::Match")
150-
.entry("nonlocal", "Tok::Nonlocal")
151-
.entry("not", "Tok::Not")
152-
.entry("or", "Tok::Or")
153-
.entry("pass", "Tok::Pass")
154-
.entry("raise", "Tok::Raise")
155-
.entry("return", "Tok::Return")
156-
.entry("try", "Tok::Try")
157-
.entry("type", "Tok::Type")
158-
.entry("while", "Tok::While")
159-
.entry("with", "Tok::With")
160-
.entry("yield", "Tok::Yield")
161-
.build();
162-
writeln!(
163-
BufWriter::new(File::create(out_dir.join("keywords.rs")).unwrap()),
164-
"{kwds}",
165-
)
166-
.unwrap();
167-
}

0 commit comments

Comments
 (0)