| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d66d935 commit e1f7010
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,7 +37,9 @@ jobs: | |||
| 37 | 37 | ||
| 38 | 38 | - uses: Swatinem/rust-cache@v2 | |
| 39 | 39 | ||
| 40 | - - name: run tests | ||
| 40 | + - name: run tests with embedded parser | ||
| 41 | + run: cargo test --all --no-default-features | ||
| 42 | + - name: run tests with generated parser | ||
| 41 | 43 | run: cargo test --all --all-features | |
| 42 | 44 | ||
| 43 | 45 | lint: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,7 @@ license = "MIT" | |||
| 9 | 9 | edition = "2021" | |
| 10 | 10 | ||
| 11 | 11 | [features] | |
| 12 | - default = ["lalrpop"] # removing this causes potential build failure | ||
| 12 | + default = [] | ||
| 13 | 13 | serde = ["dep:serde", "rustpython-compiler-core/serde"] | |
| 14 | 14 | ||
| 15 | 15 | [build-dependencies] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,15 +5,39 @@ use std::path::{Path, PathBuf}; | |||
| 5 | 5 | use tiny_keccak::{Hasher, Sha3}; | |
| 6 | 6 | ||
| 7 | 7 | fn main() -> anyhow::Result<()> { | |
| 8 | - const SOURCE: &str = "python.lalrpop"; | ||
| 9 | 8 | let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap()); | |
| 9 | + gen_phf(&out_dir); | ||
| 10 | 10 | ||
| 11 | + const SOURCE: &str = "src/python.lalrpop"; | ||
| 11 | 12 | println!("cargo:rerun-if-changed={SOURCE}"); | |
| 12 | 13 | ||
| 13 | - try_lalrpop(SOURCE, &out_dir.join("python.rs"))?; | ||
| 14 | - gen_phf(&out_dir); | ||
| 14 | + let target; | ||
| 15 | + let error; | ||
| 16 | + | ||
| 17 | + #[cfg(feature = "lalrpop")] | ||
| 18 | + { | ||
| 19 | + target = out_dir.join("src/python.rs"); | ||
| 20 | + } | ||
| 21 | + #[cfg(not(feature = "lalrpop"))] | ||
| 22 | + { | ||
| 23 | + target = PathBuf::from("src/python.rs"); | ||
| 24 | + error = "python.lalrpop and src/python.rs doesn't match. This is a rustpython-parser bug. Please report it unless you are editing rustpython-parser. Run `lalrpop src/python.lalrpop` to build parser again."; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + let Some(message) = requires_lalrpop(SOURCE, &target) else { | ||
| 28 | + return Ok(()); | ||
| 29 | + }; | ||
| 15 | 30 | ||
| 16 | - Ok(()) | ||
| 31 | + #[cfg(feature = "lalrpop")] | ||
| 32 | + { | ||
| 33 | + let Err(e) = try_lalrpop() else { | ||
| 34 | + return Ok(()); | ||
| 35 | + }; | ||
| 36 | + error = e; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + println!("cargo:warning={message}"); | ||
| 40 | + panic!("running lalrpop failed. {error:?}"); | ||
| 17 | 41 | } | |
| 18 | 42 | ||
| 19 | 43 | fn requires_lalrpop(source: &str, target: &Path) -> Option<String> { | |
@@ -68,28 +92,14 @@ fn requires_lalrpop(source: &str, target: &Path) -> Option<String> { | |||
| 68 | 92 | None | |
| 69 | 93 | } | |
| 70 | 94 | ||
| 71 | - fn try_lalrpop(source: &str, target: &Path) -> anyhow::Result<()> { | ||
| 72 | - let Some(_message) = requires_lalrpop(source, target) else { | ||
| 73 | - return Ok(()); | ||
| 74 | - }; | ||
| 75 | - | ||
| 76 | - #[cfg(feature = "lalrpop")] | ||
| 95 | + #[cfg(feature = "lalrpop")] | ||
| 96 | + fn try_lalrpop() -> Result<(), Box<dyn std::error::Error>> { | ||
| 77 | 97 | // We are not using lalrpop::process_root() or Configuration::process_current_dir() | |
| 78 | 98 | // because of https://github.com/lalrpop/lalrpop/issues/699. | |
| 79 | 99 | lalrpop::Configuration::new() | |
| 80 | 100 | .use_cargo_dir_conventions() | |
| 81 | 101 | .set_in_dir(Path::new(".")) | |
| 82 | 102 | .process() | |
| 83 | - .unwrap_or_else(|e| { | ||
| 84 | - println!("cargo:warning={_message}"); | ||
| 85 | - panic!("running lalrpop failed. {e:?}"); | ||
| 86 | - }); | ||
| 87 | - | ||
| 88 | - #[cfg(not(feature = "lalrpop"))] | ||
| 89 | - { | ||
| 90 | - println!("cargo:warning=try: cargo build --manifest-path=compiler/parser/Cargo.toml --features=lalrpop"); | ||
| 91 | - } | ||
| 92 | - Ok(()) | ||
| 93 | 103 | } | |
| 94 | 104 | ||
| 95 | 105 | fn sha_equal(expected_sha3_str: &str, actual_sha3: &[u8; 32]) -> bool { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -116,14 +116,12 @@ pub use rustpython_ast as ast; | |||
| 116 | 116 | ||
| 117 | 117 | mod function; | |
| 118 | 118 | // Skip flattening lexer to distinguish from full parser | |
| 119 | + mod context; | ||
| 119 | 120 | pub mod lexer; | |
| 120 | 121 | mod mode; | |
| 121 | 122 | mod parser; | |
| 122 | - mod string; | ||
| 123 | - #[rustfmt::skip] | ||
| 124 | - mod python; | ||
| 125 | - mod context; | ||
| 126 | 123 | mod soft_keywords; | |
| 124 | + mod string; | ||
| 127 | 125 | mod token; | |
| 128 | 126 | ||
| 129 | 127 | pub use mode::Mode; | |
@@ -133,3 +131,15 @@ pub use parser::{ | |||
| 133 | 131 | }; | |
| 134 | 132 | pub use string::FStringErrorType; | |
| 135 | 133 | pub use token::{StringKind, Tok}; | |
| 134 | + | ||
| 135 | + #[rustfmt::skip] | ||
| 136 | + mod python { | ||
| 137 | + #![allow(clippy::all)] | ||
| 138 | + #![allow(unused)] | ||
| 139 | + | ||
| 140 | + #[cfg(feature = "lalrpop")] | ||
| 141 | + include!(concat!(env!("OUT_DIR"), "/src/python.rs")); | ||
| 142 | + | ||
| 143 | + #[cfg(not(feature = "lalrpop"))] | ||
| 144 | + include!("python.rs"); | ||
| 145 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments