Skip to content

Commit

Permalink
Yeet box patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
elkowar committed Feb 17, 2024
1 parent 607f441 commit 7c64e6b
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 29 deletions.
4 changes: 2 additions & 2 deletions crates/eww/build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::process::Command;
fn main() {
let output = Command::new("git").args(&["rev-parse", "HEAD"]).output();
let output = Command::new("git").args(["rev-parse", "HEAD"]).output();
if let Ok(output) = output {
if let Ok(hash) = String::from_utf8(output.stdout) {
println!("cargo:rustc-env=GIT_HASH={}", hash);
println!("cargo:rustc-env=CARGO_PKG_VERSION={} {}", env!("CARGO_PKG_VERSION"), hash);
}
}
let output = Command::new("git").args(&["show", "-s", "--format=%ci"]).output();
let output = Command::new("git").args(["show", "-s", "--format=%ci"]).output();
if let Ok(output) = output {
if let Ok(date) = String::from_utf8(output.stdout) {
println!("cargo:rustc-env=GIT_COMMIT_DATE={}", date);
Expand Down
1 change: 0 additions & 1 deletion crates/eww/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![feature(trace_macros)]
#![feature(extract_if)]
#![feature(box_patterns)]
#![feature(slice_concat_trait)]
#![feature(try_blocks)]
#![feature(hash_extract_if)]
Expand Down
20 changes: 10 additions & 10 deletions crates/simplexpr/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub enum EvalError {
JaqError(String),

#[error(transparent)]
JaqParseError(JaqParseError),
JaqParseError(Box<JaqParseError>),

#[error("Error parsing date: {0}")]
ChronoError(String),
Expand Down Expand Up @@ -98,13 +98,13 @@ impl SimplExpr {
pub fn try_map_var_refs<E, F: Fn(Span, VarName) -> Result<SimplExpr, E> + Copy>(self, f: F) -> Result<Self, E> {
use SimplExpr::*;
Ok(match self {
BinOp(span, box a, op, box b) => BinOp(span, Box::new(a.try_map_var_refs(f)?), op, Box::new(b.try_map_var_refs(f)?)),
BinOp(span, a, op, b) => BinOp(span, Box::new(a.try_map_var_refs(f)?), op, Box::new(b.try_map_var_refs(f)?)),
Concat(span, elems) => Concat(span, elems.into_iter().map(|x| x.try_map_var_refs(f)).collect::<Result<_, _>>()?),
UnaryOp(span, op, box a) => UnaryOp(span, op, Box::new(a.try_map_var_refs(f)?)),
IfElse(span, box a, box b, box c) => {
UnaryOp(span, op, a) => UnaryOp(span, op, Box::new(a.try_map_var_refs(f)?)),
IfElse(span, a, b, c) => {
IfElse(span, Box::new(a.try_map_var_refs(f)?), Box::new(b.try_map_var_refs(f)?), Box::new(c.try_map_var_refs(f)?))
}
JsonAccess(span, safe, box a, box b) => {
JsonAccess(span, safe, a, b) => {
JsonAccess(span, safe, Box::new(a.try_map_var_refs(f)?), Box::new(b.try_map_var_refs(f)?))
}
FunctionCall(span, name, args) => {
Expand Down Expand Up @@ -154,13 +154,13 @@ impl SimplExpr {
Literal(..) => Vec::new(),
VarRef(span, name) => vec![(*span, name)],
Concat(_, elems) => elems.iter().flat_map(|x| x.var_refs_with_span().into_iter()).collect(),
BinOp(_, box a, _, box b) | JsonAccess(_, _, box a, box b) => {
BinOp(_, a, _, b) | JsonAccess(_, _, a, b) => {
let mut refs = a.var_refs_with_span();
refs.extend(b.var_refs_with_span().iter());
refs
}
UnaryOp(_, _, box x) => x.var_refs_with_span(),
IfElse(_, box a, box b, box c) => {
UnaryOp(_, _, x) => x.var_refs_with_span(),
IfElse(_, a, b, c) => {
let mut refs = a.var_refs_with_span();
refs.extend(b.var_refs_with_span().iter());
refs.extend(c.var_refs_with_span().iter());
Expand Down Expand Up @@ -463,7 +463,7 @@ fn prepare_jaq_filter(code: String) -> Result<Arc<jaq_core::Filter>, EvalError>
let (filter, mut errors) = jaq_core::parse::parse(&code, jaq_core::parse::main());
let filter = match filter {
Some(x) => x,
None => return Err(EvalError::JaqParseError(JaqParseError(errors.pop()))),
None => return Err(EvalError::JaqParseError(Box::new(JaqParseError(errors.pop())))),
};
let mut defs = jaq_core::Definitions::core();
for def in jaq_std::std() {
Expand All @@ -473,7 +473,7 @@ fn prepare_jaq_filter(code: String) -> Result<Arc<jaq_core::Filter>, EvalError>
let filter = defs.finish(filter, Vec::new(), &mut errors);

if let Some(error) = errors.pop() {
return Err(EvalError::JaqParseError(JaqParseError(Some(error))));
return Err(EvalError::JaqParseError(Box::new(JaqParseError(Some(error)))));
}
Ok(Arc::new(filter))
}
Expand Down
1 change: 0 additions & 1 deletion crates/simplexpr/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(box_patterns)]
#![feature(pattern)]
#![feature(try_blocks)]
#![feature(unwrap_infallible)]
Expand Down
32 changes: 18 additions & 14 deletions crates/yuck/src/format_diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,22 +199,26 @@ impl ToDiagnostic for simplexpr::eval::EvalError {
notes.push(format!("Hint: If you meant to use the literal value \"{}\", surround the value in quotes", name));
gen_diagnostic!(self).with_notes(notes)
}
EvalError::Spanned(span, box EvalError::JaqParseError(simplexpr::eval::JaqParseError(Some(err)))) => {
let span = span.new_relative(err.span().start, err.span().end).shifted(1);
let mut diag = gen_diagnostic!(self, span);

if let Some(label) = err.label() {
diag = diag.with_label(span_to_secondary_label(span).with_message(label));
}

let expected: Vec<_> = err.expected().filter_map(|x| x.clone()).sorted().collect();
if !expected.is_empty() {
let label = format!("Expected one of {} here", expected.join(", "));
diag = diag.with_label(span_to_primary_label(span).with_message(label));
EvalError::Spanned(span, err) => {
if let EvalError::JaqParseError(err) = err.as_ref() {
if let Some(ref err) = err.as_ref().0 {
let span = span.new_relative(err.span().start, err.span().end).shifted(1);
let mut diag = gen_diagnostic!(self, span);

if let Some(label) = err.label() {
diag = diag.with_label(span_to_secondary_label(span).with_message(label));
}

let expected: Vec<_> = err.expected().filter_map(|x| x.clone()).sorted().collect();
if !expected.is_empty() {
let label = format!("Expected one of {} here", expected.join(", "));
diag = diag.with_label(span_to_primary_label(span).with_message(label));
}
return diag;
}
}
diag
return err.as_ref().to_diagnostic().with_label(span_to_primary_label(*span));
}
EvalError::Spanned(span, error) => error.as_ref().to_diagnostic().with_label(span_to_primary_label(*span)),
_ => gen_diagnostic!(self, self.span()),
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/yuck/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(clippy::comparison_chain)]
#![feature(try_blocks, box_patterns)]
#![feature(try_blocks)]

pub mod ast_error;
pub mod config;
Expand Down
1 change: 1 addition & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[toolchain]
channel = "nightly-2024-02-16"
# channel = "1.76.0"
components = [ "rust-src" ]
profile = "default"

0 comments on commit 7c64e6b

Please sign in to comment.