git.delta.rocks / jrsonnet / refs/commits / 0a23a80af017

difftreelog

feat make both parsers available at the same time

sklkzktrYaroslav Bolyukin2026-03-23parent: #c02b270.patch.diff
in: master

2 files changed

modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
6060
61use crate::gc::WithCapacityExt as _;61use crate::gc::WithCapacityExt as _;
6262
63#[allow(clippy::needless_return)]
63pub(crate) fn parse_jsonnet(code: &str, source: Source) -> Result<Expr, SyntaxError> {64pub(crate) fn parse_jsonnet(code: &str, source: Source) -> Result<Expr, SyntaxError> {
64 #[cfg(all(feature = "ir-parser", feature = "peg-parser"))]65 #[cfg(feature = "peg-parser")]
65 {66 {
67 static USE_LEGACY_PARSER: LazyLock<bool> =
66 if std::env::var_os("JRSONNET_LEGACY_PARSER").is_some() {68 LazyLock::new(|| std::env::var_os("JRSONNET_LEGACY_PARSER").is_some());
67 return parse_peg(code, source);69
68 }70 if USE_LEGACY_PARSER {
69 return parse_ir(code, source);71 return parse_peg(code, source);
72 }
70 }73 }
71 #[cfg(all(feature = "ir-parser", not(feature = "peg-parser")))]74 #[cfg(feature = "ir-parser")]
72 {75 {
73 return parse_ir(code, source);76 return parse_ir(code, source);
74 }77 }
75 #[cfg(all(feature = "peg-parser", not(feature = "ir-parser")))]78 #[cfg(feature = "peg-parser")]
76 {79 {
77 return parse_peg(code, source);80 return parse_peg(code, source);
78 }81 }
79}82}
8083
81#[cfg(feature = "ir-parser")]84#[cfg(feature = "ir-parser")]
82fn parse_ir(code: &str, source: Source) -> Result<Expr, SyntaxError> {85fn parse_ir(code: &str, source: Source) -> Result<Expr, SyntaxError> {
83 jrsonnet_ir_parser::parse(code, &jrsonnet_ir_parser::ParserSettings { source }).map_err(86 jrsonnet_ir_parser::parse(code, &jrsonnet_ir_parser::ParserSettings { source }).map_err(|e| {
84 |e| SyntaxError {87 SyntaxError {
85 message: e.message,88 message: e.message,
86 location: SyntaxErrorLocation {89 location: SyntaxErrorLocation {
87 offset: e.location.offset,90 offset: e.location.offset,
88 },91 },
89 },92 }
90 )93 })
91}94}
9295
93#[cfg(feature = "peg-parser")]96#[cfg(feature = "peg-parser")]
modifiedtests/Cargo.tomldiffbeforeafterboth
7[features]7[features]
8default = ["ir-parser"]8default = ["ir-parser"]
9ir-parser = ["jrsonnet-evaluator/ir-parser"]9ir-parser = ["jrsonnet-evaluator/ir-parser"]
10peg-parser = ["jrsonnet-evaluator/peg-parser"]
11exp-destruct = ["jrsonnet-evaluator/exp-destruct"]
10exp-null-coaelse = ["jrsonnet-evaluator/exp-null-coaelse"]12exp-null-coaelse = ["jrsonnet-evaluator/exp-null-coaelse"]
1113
12[lints]14[lints]