Skip to content

Generate aliases for use by string parser. #4572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ license = "MIT"
[features]
threading = ["parking_lot"]

[build-dependencies]
anyhow = { workspace = true }
phf_codegen = "0.11.1"

[dependencies]
ascii = { workspace = true }
bitflags = { workspace = true }
Expand All @@ -27,6 +31,7 @@ hexf-parse = "0.2.1"
lexical-parse-float = { version = "0.8.0", features = ["format"] }
lock_api = "0.4"
radium = "0.7"
phf = "0.11.1"
siphasher = "0.3"
unic-ucd-category = "0.9"
volatile = "0.3"
Expand Down
507 changes: 507 additions & 0 deletions common/build.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub mod rc;
pub mod refcount;
pub mod static_cell;
pub mod str;
pub mod unicode_aliases;
#[cfg(windows)]
pub mod windows;

Expand Down
24 changes: 24 additions & 0 deletions common/src/unicode_aliases.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//! Unicode aliases.
//!
//! This module contains a map of unicode aliases to their corresponding values. The map is generated
//! from the [NamesList.txt] file in the Unicode Character Database.
//!
//! [NamesList.txt]: https://www.unicode.org/Public/14.0.0/ucd/NameAliases.txt

// generated in build.rs, in gen_unicode_aliases()
/// A map of unicode aliases to their corresponding values.
static ALIASES: phf::Map<&'static str, char> = include!(concat!(env!("OUT_DIR"), "/aliases.rs"));

/// Get alias value from alias name, returns `None` if the alias is not found.
///
/// # Examples
///
/// ```
/// use rustpython_common::unicode_aliases::unicode_alias;
///
/// assert_eq!(unicode_alias("NEW LINE"), Some('\n'));
/// assert_eq!(unicode_alias("BACKSPACE"), Some('\u{8}'));
/// assert_eq!(unicode_alias("NOT AN ALIAS"), None);
pub fn unicode_alias(alias: &str) -> Option<char> {
ALIASES.get(alias).copied()
}
1 change: 1 addition & 0 deletions compiler/parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ tiny-keccak = { version = "2", features = ["sha3"] }
[dependencies]
rustpython-ast = { path = "../ast", version = "0.2.0" }
rustpython-compiler-core = { path = "../core", version = "0.2.0" }
rustpython-common = { path = "../../common" }

ahash = { workspace = true }
itertools = { workspace = true }
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading