diff --git a/Lib/keyword.py b/Lib/keyword.py new file mode 100644 index 0000000000..eab8204c91 --- /dev/null +++ b/Lib/keyword.py @@ -0,0 +1,63 @@ +"""Keywords (from "Grammar/python.gram") + +This file is automatically generated; please don't muck it up! + +To update the symbols in this file, 'cd' to the top directory of +the python source tree and run: + + PYTHONPATH=Tools/peg_generator python3 -m pegen.keywordgen \ + Grammar/python.gram \ + Grammar/Tokens \ + Lib/keyword.py + +Alternatively, you can run 'make regen-keyword'. +""" + +__all__ = ["iskeyword", "issoftkeyword", "kwlist", "softkwlist"] + +kwlist = [ + 'False', + 'None', + 'True', + 'and', + 'as', + 'assert', + 'async', + 'await', + 'break', + 'class', + 'continue', + 'def', + 'del', + 'elif', + 'else', + 'except', + 'finally', + 'for', + 'from', + 'global', + 'if', + 'import', + 'in', + 'is', + 'lambda', + 'nonlocal', + 'not', + 'or', + 'pass', + 'raise', + 'return', + 'try', + 'while', + 'with', + 'yield' +] + +softkwlist = [ + '_', + 'case', + 'match' +] + +iskeyword = frozenset(kwlist).__contains__ +issoftkeyword = frozenset(softkwlist).__contains__ diff --git a/stdlib/src/keyword.rs b/stdlib/src/keyword.rs deleted file mode 100644 index 0cfaeafdbc..0000000000 --- a/stdlib/src/keyword.rs +++ /dev/null @@ -1,27 +0,0 @@ -/// Testing if a string is a keyword. -pub(crate) use keyword::make_module; - -#[pymodule] -mod keyword { - use crate::vm::{builtins::PyStr, PyObjectRef, VirtualMachine}; - use itertools::Itertools; - use rustpython_parser::lexer; - - #[pyfunction] - fn iskeyword(s: PyObjectRef) -> bool { - if let Some(s) = s.payload::() { - lexer::KEYWORDS.contains_key(s.as_str()) - } else { - false - } - } - - #[pyattr] - fn kwlist(vm: &VirtualMachine) -> Vec { - lexer::KEYWORDS - .keys() - .sorted() - .map(|&k| vm.ctx.new_str(k).into()) - .collect() - } -} diff --git a/stdlib/src/lib.rs b/stdlib/src/lib.rs index 7b5e01bf16..0be798fe9b 100644 --- a/stdlib/src/lib.rs +++ b/stdlib/src/lib.rs @@ -14,8 +14,6 @@ mod dis; mod gc; mod hashlib; mod json; -#[cfg(feature = "rustpython-parser")] -mod keyword; mod math; mod platform; mod pyexpat; @@ -96,10 +94,6 @@ pub fn get_module_inits() -> impl Iterator, StdlibInit { "_ast" => ast::make_module, } - #[cfg(feature = "rustpython-parser")] - { - "keyword" => keyword::make_module, - } #[cfg(any(unix, target_os = "wasi"))] { "fcntl" => fcntl::make_module,