Cleanup code, fix clippy lints
This commit is contained in:
parent
d2c7bde29d
commit
8ff4142064
33 changed files with 115 additions and 202 deletions
|
@ -149,7 +149,7 @@ impl App {
|
|||
if let Err(e) = config_result.and_then(|new_config| self.load_config(new_config)) {
|
||||
errors.push(e)
|
||||
}
|
||||
match crate::config::scss::parse_scss_from_config(&self.paths.get_config_dir()) {
|
||||
match crate::config::scss::parse_scss_from_config(self.paths.get_config_dir()) {
|
||||
Ok((file_id, css)) => {
|
||||
if let Err(e) = self.load_css(file_id, &css) {
|
||||
errors.push(anyhow!(e));
|
||||
|
|
|
@ -38,6 +38,7 @@ pub fn format_error(err: &anyhow::Error) -> String {
|
|||
}
|
||||
|
||||
pub fn anyhow_err_to_diagnostic(err: &anyhow::Error) -> Option<Diagnostic<usize>> {
|
||||
#[allow(clippy::manual_map)]
|
||||
if let Some(err) = err.downcast_ref::<DiagError>() {
|
||||
Some(err.0.clone())
|
||||
} else if let Some(err) = err.downcast_ref::<ConversionError>() {
|
||||
|
|
|
@ -100,6 +100,7 @@ impl ScriptVarHandlerHandle {
|
|||
|
||||
/// Message enum used by the ScriptVarHandlerHandle to communicate to the ScriptVarHandler
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
enum ScriptVarHandlerMsg {
|
||||
AddVar(ScriptVarDefinition),
|
||||
Stop(VarName),
|
||||
|
|
|
@ -83,7 +83,7 @@ pub fn initialize_server(paths: EwwPaths, action: Option<DaemonCommand>, should_
|
|||
gtk::StyleContext::add_provider_for_screen(&screen, &app.css_provider, gtk::STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
}
|
||||
|
||||
if let Ok((file_id, css)) = config::scss::parse_scss_from_config(&app.paths.get_config_dir()) {
|
||||
if let Ok((file_id, css)) = config::scss::parse_scss_from_config(app.paths.get_config_dir()) {
|
||||
if let Err(e) = app.load_css(file_id, &css) {
|
||||
error_handling_ctx::print_error(e);
|
||||
}
|
||||
|
|
|
@ -144,7 +144,6 @@ pub fn unindent(text: &str) -> String {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::{replace_env_var_references, unindent};
|
||||
use std;
|
||||
|
||||
#[test]
|
||||
fn test_replace_env_var_references() {
|
||||
|
|
|
@ -104,6 +104,12 @@ impl ObjectSubclass for CircProgPriv {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for CircProg {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl CircProg {
|
||||
pub fn new() -> Self {
|
||||
glib::Object::new::<Self>(&[]).expect("Failed to create CircularProgress Widget")
|
||||
|
|
|
@ -175,6 +175,12 @@ impl ObjectSubclass for GraphPriv {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for Graph {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Graph {
|
||||
pub fn new() -> Self {
|
||||
glib::Object::new::<Self>(&[]).expect("Failed to create Graph Widget")
|
||||
|
|
|
@ -108,6 +108,12 @@ impl ObjectSubclass for TransformPriv {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for Transform {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Transform {
|
||||
pub fn new() -> Self {
|
||||
glib::Object::new::<Self>(&[]).expect("Failed to create Transform Widget")
|
||||
|
|
|
@ -905,7 +905,7 @@ fn build_gtk_calendar(bargs: &mut BuilderArgs) -> Result<gtk::Calendar> {
|
|||
def_widget!(bargs, _g, gtk_widget, {
|
||||
// @prop day - the selected day
|
||||
prop(day: as_f64) {
|
||||
if day < 1f64 || day > 31f64 {
|
||||
if !(1f64..=31f64).contains(&day) {
|
||||
log::warn!("Calendar day is not a number between 1 and 31");
|
||||
} else {
|
||||
gtk_widget.set_day(day as i32)
|
||||
|
@ -913,7 +913,7 @@ fn build_gtk_calendar(bargs: &mut BuilderArgs) -> Result<gtk::Calendar> {
|
|||
},
|
||||
// @prop month - the selected month
|
||||
prop(month: as_f64) {
|
||||
if month < 1f64 || month > 12f64 {
|
||||
if !(1f64..=12f64).contains(&month) {
|
||||
log::warn!("Calendar month is not a number between 1 and 12");
|
||||
} else {
|
||||
gtk_widget.set_month(month as i32 - 1)
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
use eww_shared_util::{AttrName, Span};
|
||||
|
||||
use crate::{
|
||||
error::{DiagError, DiagResult},
|
||||
format_diagnostic::ToDiagnostic,
|
||||
gen_diagnostic,
|
||||
parser::ast::AstType,
|
||||
};
|
||||
use crate::{format_diagnostic::ToDiagnostic, gen_diagnostic, parser::ast::AstType};
|
||||
|
||||
/// Error type representing errors that occur when trying to access parts of the AST specifically
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
@ -41,7 +36,7 @@ impl ToDiagnostic for AstError {
|
|||
note = format!("Expected: {expected}\n Got: {actual}"),
|
||||
},
|
||||
AstError::DanglingKeyword(span, kw) => gen_diagnostic! {
|
||||
msg = "{kw} is missing a value",
|
||||
msg = format!("{kw} is missing a value"),
|
||||
label = span => "No value provided for this",
|
||||
},
|
||||
AstError::EvalError(e) => e.to_diagnostic(),
|
||||
|
|
|
@ -1,19 +1,12 @@
|
|||
use std::{
|
||||
collections::HashMap,
|
||||
convert::{TryFrom, TryInto},
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use simplexpr::{
|
||||
dynval::{DynVal, FromDynVal},
|
||||
eval::EvalError,
|
||||
SimplExpr,
|
||||
};
|
||||
use simplexpr::{dynval::FromDynVal, eval::EvalError, SimplExpr};
|
||||
|
||||
use crate::{
|
||||
error::DiagError,
|
||||
parser::{ast::Ast, from_ast::FromAst},
|
||||
};
|
||||
use eww_shared_util::{AttrName, Span, Spanned, VarName};
|
||||
use eww_shared_util::{AttrName, Span, Spanned};
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum AttrError {
|
||||
|
@ -64,14 +57,14 @@ impl Attributes {
|
|||
pub fn ast_required<T: FromAst>(&mut self, key: &str) -> Result<T, DiagError> {
|
||||
let key = AttrName(key.to_string());
|
||||
match self.attrs.remove(&key) {
|
||||
Some(AttrEntry { key_span, value }) => T::from_ast(value),
|
||||
Some(AttrEntry { value, .. }) => T::from_ast(value),
|
||||
None => Err(AttrError::MissingRequiredAttr(self.span, key.clone()).into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ast_optional<T: FromAst>(&mut self, key: &str) -> Result<Option<T>, DiagError> {
|
||||
match self.attrs.remove(&AttrName(key.to_string())) {
|
||||
Some(AttrEntry { key_span, value }) => T::from_ast(value).map(Some),
|
||||
Some(AttrEntry { value, .. }) => T::from_ast(value).map(Some),
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::{
|
||||
enum_parse,
|
||||
|
@ -16,10 +16,7 @@ pub use backend::*;
|
|||
|
||||
#[cfg(feature = "x11")]
|
||||
mod backend {
|
||||
use crate::{
|
||||
error::{DiagError, DiagResultExt},
|
||||
format_diagnostic::ToDiagnostic,
|
||||
};
|
||||
use crate::error::{DiagError, DiagResultExt};
|
||||
|
||||
use super::*;
|
||||
|
||||
|
@ -103,7 +100,7 @@ mod backend {
|
|||
impl FromAstElementContent for StrutDefinition {
|
||||
const ELEMENT_NAME: &'static str = "struts";
|
||||
|
||||
fn from_tail<I: Iterator<Item = Ast>>(span: Span, mut iter: AstIterator<I>) -> DiagResult<Self> {
|
||||
fn from_tail<I: Iterator<Item = Ast>>(_span: Span, mut iter: AstIterator<I>) -> DiagResult<Self> {
|
||||
let mut attrs = iter.expect_key_values()?;
|
||||
iter.expect_done().map_err(DiagError::from).note("Check if you are missing a colon in front of a key")?;
|
||||
Ok(StrutDefinition { side: attrs.primitive_required("side")?, dist: attrs.primitive_required("distance")? })
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
use std::{collections::HashMap, path::PathBuf};
|
||||
|
||||
use codespan_reporting::files::{Files, SimpleFile, SimpleFiles};
|
||||
use eww_shared_util::Span;
|
||||
|
||||
use crate::{
|
||||
error::{DiagError, DiagResult},
|
||||
parser::ast::Ast,
|
||||
};
|
||||
use crate::{error::DiagError, parser::ast::Ast};
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum FilesError {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
pub mod attributes;
|
||||
pub mod backend_window_options;
|
||||
pub mod config;
|
||||
pub mod file_provider;
|
||||
pub mod monitor;
|
||||
pub mod script_var_definition;
|
||||
pub mod toplevel;
|
||||
pub mod validate;
|
||||
pub mod var_definition;
|
||||
pub mod widget_definition;
|
||||
|
@ -11,4 +11,4 @@ pub mod widget_use;
|
|||
pub mod window_definition;
|
||||
pub mod window_geometry;
|
||||
|
||||
pub use config::*;
|
||||
pub use toplevel::*;
|
||||
|
|
|
@ -1,17 +1,11 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use simplexpr::{dynval::DynVal, SimplExpr};
|
||||
|
||||
use crate::{
|
||||
error::{DiagError, DiagResult, DiagResultExt},
|
||||
format_diagnostic::ToDiagnostic,
|
||||
parser::{
|
||||
ast::Ast,
|
||||
ast_iterator::AstIterator,
|
||||
from_ast::{FromAst, FromAstElementContent},
|
||||
},
|
||||
parser::{ast::Ast, ast_iterator::AstIterator, from_ast::FromAstElementContent},
|
||||
};
|
||||
use eww_shared_util::{AttrName, Span, Spanned, VarName};
|
||||
use eww_shared_util::{Span, VarName};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize)]
|
||||
pub enum ScriptVarDefinition {
|
||||
|
@ -66,7 +60,7 @@ pub struct PollScriptVar {
|
|||
impl FromAstElementContent for PollScriptVar {
|
||||
const ELEMENT_NAME: &'static str = "defpoll";
|
||||
|
||||
fn from_tail<I: Iterator<Item = Ast>>(span: Span, mut iter: AstIterator<I>) -> DiagResult<Self> {
|
||||
fn from_tail<I: Iterator<Item = Ast>>(_span: Span, mut iter: AstIterator<I>) -> DiagResult<Self> {
|
||||
let result: DiagResult<_> = try {
|
||||
let (name_span, name) = iter.expect_symbol()?;
|
||||
let mut attrs = iter.expect_key_values()?;
|
||||
|
@ -103,7 +97,7 @@ pub struct ListenScriptVar {
|
|||
impl FromAstElementContent for ListenScriptVar {
|
||||
const ELEMENT_NAME: &'static str = "deflisten";
|
||||
|
||||
fn from_tail<I: Iterator<Item = Ast>>(span: Span, mut iter: AstIterator<I>) -> DiagResult<Self> {
|
||||
fn from_tail<I: Iterator<Item = Ast>>(_span: Span, mut iter: AstIterator<I>) -> DiagResult<Self> {
|
||||
let result: DiagResult<_> = try {
|
||||
let (name_span, name) = iter.expect_symbol()?;
|
||||
let mut attrs = iter.expect_key_values()?;
|
||||
|
|
|
@ -3,23 +3,18 @@ use std::{
|
|||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use codespan_reporting::files::SimpleFiles;
|
||||
use itertools::Itertools;
|
||||
use simplexpr::SimplExpr;
|
||||
|
||||
use super::{
|
||||
file_provider::{FilesError, YuckFileProvider},
|
||||
script_var_definition::ScriptVarDefinition,
|
||||
validate::ValidationError,
|
||||
var_definition::VarDefinition,
|
||||
widget_definition::WidgetDefinition,
|
||||
widget_use::WidgetUse,
|
||||
window_definition::WindowDefinition,
|
||||
};
|
||||
use crate::{
|
||||
config::script_var_definition::{ListenScriptVar, PollScriptVar},
|
||||
error::{DiagError, DiagResult},
|
||||
format_diagnostic::ToDiagnostic,
|
||||
gen_diagnostic,
|
||||
parser::{
|
||||
ast::Ast,
|
||||
|
@ -27,7 +22,7 @@ use crate::{
|
|||
from_ast::{FromAst, FromAstElementContent},
|
||||
},
|
||||
};
|
||||
use eww_shared_util::{AttrName, Span, Spanned, VarName};
|
||||
use eww_shared_util::{Span, Spanned, VarName};
|
||||
|
||||
static TOP_LEVEL_DEFINITION_NAMES: &[&str] = &[
|
||||
WidgetDefinition::ELEMENT_NAME,
|
||||
|
@ -47,7 +42,7 @@ pub struct Include {
|
|||
impl FromAstElementContent for Include {
|
||||
const ELEMENT_NAME: &'static str = "include";
|
||||
|
||||
fn from_tail<I: Iterator<Item = Ast>>(span: Span, mut iter: AstIterator<I>) -> DiagResult<Self> {
|
||||
fn from_tail<I: Iterator<Item = Ast>>(_span: Span, mut iter: AstIterator<I>) -> DiagResult<Self> {
|
||||
let (path_span, path) = iter.expect_literal()?;
|
||||
iter.expect_done()?;
|
||||
Ok(Include { path: path.to_string(), path_span })
|
||||
|
@ -127,7 +122,7 @@ impl Config {
|
|||
self.window_definitions.insert(x.name.clone(), x);
|
||||
}
|
||||
TopLevel::Include(include) => {
|
||||
let (file_id, toplevels) = files.load_yuck_file(PathBuf::from(&include.path)).map_err(|err| match err {
|
||||
let (_, toplevels) = files.load_yuck_file(PathBuf::from(&include.path)).map_err(|err| match err {
|
||||
FilesError::IoError(_) => DiagError(gen_diagnostic! {
|
||||
msg = format!("Included file `{}` not found", include.path),
|
||||
label = include.path_span => "Included here",
|
||||
|
@ -156,7 +151,7 @@ impl Config {
|
|||
}
|
||||
|
||||
pub fn generate_from_main_file(files: &mut impl YuckFileProvider, path: impl AsRef<Path>) -> DiagResult<Self> {
|
||||
let (span, top_levels) = files.load_yuck_file(path.as_ref().to_path_buf()).map_err(|err| match err {
|
||||
let (_span, top_levels) = files.load_yuck_file(path.as_ref().to_path_buf()).map_err(|err| match err {
|
||||
FilesError::IoError(err) => DiagError(gen_diagnostic!(err)),
|
||||
FilesError::DiagError(x) => x,
|
||||
})?;
|
|
@ -2,16 +2,7 @@ use std::collections::{HashMap, HashSet};
|
|||
|
||||
use simplexpr::SimplExpr;
|
||||
|
||||
use crate::{
|
||||
error::DiagResult,
|
||||
parser::{ast::Ast, ast_iterator::AstIterator, from_ast::FromAst},
|
||||
};
|
||||
|
||||
use super::{
|
||||
widget_definition::WidgetDefinition,
|
||||
widget_use::{BasicWidgetUse, WidgetUse},
|
||||
Config,
|
||||
};
|
||||
use super::{widget_definition::WidgetDefinition, widget_use::WidgetUse, Config};
|
||||
use eww_shared_util::{AttrName, Span, Spanned, VarName};
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
@ -93,7 +84,6 @@ pub fn validate_variables_in_widget_use(
|
|||
}
|
||||
let values = widget.attrs.attrs.values();
|
||||
let unknown_var = values.filter_map(|value| value.value.as_simplexpr().ok()).find_map(|expr: SimplExpr| {
|
||||
let span = expr.span();
|
||||
expr.var_refs_with_span()
|
||||
.iter()
|
||||
.cloned()
|
||||
|
|
|
@ -1,16 +1,10 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use simplexpr::{dynval::DynVal, SimplExpr};
|
||||
use simplexpr::dynval::DynVal;
|
||||
|
||||
use crate::{
|
||||
error::{DiagResult, DiagResultExt},
|
||||
parser::{
|
||||
ast::Ast,
|
||||
ast_iterator::AstIterator,
|
||||
from_ast::{FromAst, FromAstElementContent},
|
||||
},
|
||||
parser::{ast::Ast, ast_iterator::AstIterator, from_ast::FromAstElementContent},
|
||||
};
|
||||
use eww_shared_util::{AttrName, Span, VarName};
|
||||
use eww_shared_util::{Span, VarName};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, serde::Serialize)]
|
||||
pub struct VarDefinition {
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use simplexpr::SimplExpr;
|
||||
|
||||
use crate::{
|
||||
error::{DiagError, DiagResult, DiagResultExt},
|
||||
format_diagnostic::{DiagnosticExt, ToDiagnostic},
|
||||
format_diagnostic::ToDiagnostic,
|
||||
gen_diagnostic,
|
||||
parser::{
|
||||
ast::Ast,
|
||||
|
@ -12,7 +8,7 @@ use crate::{
|
|||
from_ast::{FromAst, FromAstElementContent},
|
||||
},
|
||||
};
|
||||
use eww_shared_util::{AttrName, Span, Spanned, VarName};
|
||||
use eww_shared_util::{AttrName, Span, Spanned};
|
||||
|
||||
use super::widget_use::WidgetUse;
|
||||
|
||||
|
@ -50,7 +46,7 @@ impl FromAstElementContent for WidgetDefinition {
|
|||
.expect_array()
|
||||
.map_err(|e| {
|
||||
DiagError(match e {
|
||||
crate::ast_error::AstError::WrongExprType(span, expected, actual) => gen_diagnostic! {
|
||||
crate::ast_error::AstError::WrongExprType(..) => gen_diagnostic! {
|
||||
msg = "Widget definition missing argument list",
|
||||
label = name_span.point_span_at_end() => "Insert the argument list (e.g.: `[]`) here",
|
||||
note = "This list needs to declare all the non-global variables / attributes used in this widget."
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use simplexpr::SimplExpr;
|
||||
|
||||
use crate::{
|
||||
config::attributes::AttrEntry,
|
||||
error::{DiagError, DiagResult, DiagResultExt},
|
||||
format_diagnostic::{DiagnosticExt, ToDiagnostic},
|
||||
gen_diagnostic,
|
||||
parser::{
|
||||
ast::Ast,
|
||||
|
@ -73,7 +70,7 @@ impl FromAstElementContent for LoopWidgetUse {
|
|||
const ELEMENT_NAME: &'static str = "for";
|
||||
|
||||
fn from_tail<I: Iterator<Item = Ast>>(span: Span, mut iter: AstIterator<I>) -> DiagResult<Self> {
|
||||
let (element_name_span, element_name) = iter.expect_symbol()?;
|
||||
let (_element_name_span, element_name) = iter.expect_symbol()?;
|
||||
let (in_string_span, in_string) = iter.expect_symbol()?;
|
||||
if in_string != "in" {
|
||||
return Err(DiagError(gen_diagnostic! {
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
use std::{collections::HashMap, fmt::Display, str::FromStr};
|
||||
|
||||
use simplexpr::{dynval::DynVal, SimplExpr};
|
||||
use std::fmt::Display;
|
||||
|
||||
use crate::{
|
||||
config::monitor::MonitorIdentifier,
|
||||
error::{DiagError, DiagResult},
|
||||
format_diagnostic::ToDiagnostic,
|
||||
parser::{
|
||||
ast::Ast,
|
||||
ast_iterator::AstIterator,
|
||||
from_ast::{FromAst, FromAstElementContent},
|
||||
},
|
||||
value::NumWithUnit,
|
||||
};
|
||||
use eww_shared_util::{AttrName, Span, VarName};
|
||||
use eww_shared_util::Span;
|
||||
|
||||
use super::{backend_window_options::BackendWindowOptions, widget_use::WidgetUse, window_geometry::WindowGeometry};
|
||||
|
||||
|
@ -31,7 +27,7 @@ pub struct WindowDefinition {
|
|||
impl FromAstElementContent for WindowDefinition {
|
||||
const ELEMENT_NAME: &'static str = "defwindow";
|
||||
|
||||
fn from_tail<I: Iterator<Item = Ast>>(span: Span, mut iter: AstIterator<I>) -> DiagResult<Self> {
|
||||
fn from_tail<I: Iterator<Item = Ast>>(_span: Span, mut iter: AstIterator<I>) -> DiagResult<Self> {
|
||||
let (_, name) = iter.expect_symbol()?;
|
||||
let mut attrs = iter.expect_key_values()?;
|
||||
let monitor = attrs.primitive_optional("monitor")?;
|
||||
|
|
|
@ -1,21 +1,13 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use simplexpr::{dynval::DynVal, SimplExpr};
|
||||
|
||||
use crate::{
|
||||
enum_parse,
|
||||
error::{DiagError, DiagResult},
|
||||
error::DiagResult,
|
||||
format_diagnostic::ToDiagnostic,
|
||||
parser::{
|
||||
ast::Ast,
|
||||
ast_iterator::AstIterator,
|
||||
from_ast::{FromAst, FromAstElementContent},
|
||||
},
|
||||
parser::{ast::Ast, ast_iterator::AstIterator, from_ast::FromAstElementContent},
|
||||
value::Coords,
|
||||
};
|
||||
|
||||
use super::{widget_use::WidgetUse, window_definition::EnumParseError};
|
||||
use eww_shared_util::{AttrName, Span, VarName};
|
||||
use super::window_definition::EnumParseError;
|
||||
use eww_shared_util::Span;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, smart_default::SmartDefault, Serialize, Deserialize, strum::Display)]
|
||||
|
@ -120,7 +112,7 @@ pub struct WindowGeometry {
|
|||
impl FromAstElementContent for WindowGeometry {
|
||||
const ELEMENT_NAME: &'static str = "geometry";
|
||||
|
||||
fn from_tail<I: Iterator<Item = Ast>>(span: Span, mut iter: AstIterator<I>) -> DiagResult<Self> {
|
||||
fn from_tail<I: Iterator<Item = Ast>>(_span: Span, mut iter: AstIterator<I>) -> DiagResult<Self> {
|
||||
let mut attrs = iter.expect_key_values()?;
|
||||
iter.expect_done()
|
||||
.map_err(|e| e.to_diagnostic().with_notes(vec!["Check if you are missing a colon in front of a key".to_string()]))?;
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
use crate::{
|
||||
config::{attributes::AttrError, config::Include, validate::ValidationError},
|
||||
format_diagnostic::{lalrpop_error_to_diagnostic, DiagnosticExt, ToDiagnostic},
|
||||
gen_diagnostic,
|
||||
parser::{
|
||||
ast::{Ast, AstType},
|
||||
lexer, parse_error,
|
||||
},
|
||||
parser::{lexer, parse_error},
|
||||
};
|
||||
use codespan_reporting::{diagnostic, files};
|
||||
use eww_shared_util::{AttrName, Span, Spanned, VarName};
|
||||
use codespan_reporting::diagnostic;
|
||||
use eww_shared_util::{Span, Spanned};
|
||||
use simplexpr::dynval;
|
||||
use thiserror::Error;
|
||||
|
||||
|
@ -45,8 +40,8 @@ pub fn get_parse_error_span<T, E: Spanned>(file_id: usize, err: &lalrpop_util::P
|
|||
use lalrpop_util::ParseError::*;
|
||||
match err {
|
||||
InvalidToken { location } => Span(*location, *location, file_id),
|
||||
UnrecognizedEOF { location, expected } => Span(*location, *location, file_id),
|
||||
UnrecognizedToken { token, expected } => Span(token.0, token.2, file_id),
|
||||
UnrecognizedEOF { location, .. } => Span(*location, *location, file_id),
|
||||
UnrecognizedToken { token, .. } => Span(token.0, token.2, file_id),
|
||||
ExtraToken { token } => Span(token.0, token.2, file_id),
|
||||
User { error } => error.span(),
|
||||
}
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
use codespan_reporting::{diagnostic, files};
|
||||
use codespan_reporting::diagnostic;
|
||||
use itertools::Itertools;
|
||||
use simplexpr::dynval;
|
||||
|
||||
use diagnostic::*;
|
||||
|
||||
use crate::{
|
||||
config::{attributes::AttrError, config, validate::ValidationError},
|
||||
error::{get_parse_error_span, DiagError},
|
||||
};
|
||||
use crate::config::{attributes::AttrError, validate::ValidationError};
|
||||
|
||||
use super::parser::parse_error;
|
||||
use eww_shared_util::{AttrName, Span, Spanned, VarName};
|
||||
use eww_shared_util::{Span, Spanned};
|
||||
|
||||
pub fn span_to_primary_label(span: Span) -> Label<usize> {
|
||||
Label::primary(span.2, span.0..span.1)
|
||||
|
@ -103,7 +100,7 @@ impl ToDiagnostic for AttrError {
|
|||
AttrError::MissingRequiredAttr(span, attr_name) => {
|
||||
gen_diagnostic!(format!("Missing attribute `{}`", attr_name), span)
|
||||
}
|
||||
AttrError::EvaluationError(span, source) => source.to_diagnostic(),
|
||||
AttrError::EvaluationError(_span, source) => source.to_diagnostic(),
|
||||
AttrError::Other(span, source) => gen_diagnostic!(source, span),
|
||||
}
|
||||
}
|
||||
|
@ -145,7 +142,7 @@ impl ToDiagnostic for ValidationError {
|
|||
|
||||
diag.with_notes(extra_notes)
|
||||
}
|
||||
ValidationError::AccidentalBuiltinOverride(span, widget_name) => gen_diagnostic! {
|
||||
ValidationError::AccidentalBuiltinOverride(span, _widget_name) => gen_diagnostic! {
|
||||
msg = self,
|
||||
label = span => "Defined here",
|
||||
note = "Hint: Give your widget a different name. You could call it \"John\" for example. That's a cool name."
|
||||
|
@ -166,11 +163,11 @@ pub fn lalrpop_error_to_diagnostic<T: std::fmt::Display, E: Spanned + ToDiagnost
|
|||
use lalrpop_util::ParseError::*;
|
||||
match error {
|
||||
InvalidToken { location } => gen_diagnostic!("Invalid token", Span::point(*location, file_id)),
|
||||
UnrecognizedEOF { location, expected } => gen_diagnostic! {
|
||||
UnrecognizedEOF { location, expected: _ } => gen_diagnostic! {
|
||||
msg = "Input ended unexpectedly. Check if you have any unclosed delimiters",
|
||||
label = Span::point(*location, file_id),
|
||||
},
|
||||
UnrecognizedToken { token, expected } => gen_diagnostic! {
|
||||
UnrecognizedToken { token, expected: _ } => gen_diagnostic! {
|
||||
msg = format!("Unexpected token `{}` encountered", token.1),
|
||||
label = Span(token.0, token.2, file_id) => "Token unexpected",
|
||||
},
|
||||
|
@ -189,7 +186,7 @@ impl ToDiagnostic for simplexpr::eval::EvalError {
|
|||
fn to_diagnostic(&self) -> Diagnostic<usize> {
|
||||
use simplexpr::eval::EvalError;
|
||||
match self {
|
||||
EvalError::NoVariablesAllowed(name) => gen_diagnostic!(self),
|
||||
EvalError::NoVariablesAllowed(_name) => gen_diagnostic!(self),
|
||||
EvalError::UnknownVariable(name, similar) => {
|
||||
let mut notes = Vec::new();
|
||||
if similar.len() == 1 {
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#![allow(unused_imports)]
|
||||
#![allow(unused)]
|
||||
#![allow(clippy::comparison_chain)]
|
||||
#![feature(try_blocks, box_patterns)]
|
||||
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
use itertools::Itertools;
|
||||
use simplexpr::{ast::SimplExpr, dynval::DynVal};
|
||||
use std::collections::HashMap;
|
||||
use simplexpr::ast::SimplExpr;
|
||||
|
||||
use eww_shared_util::{Span, Spanned, VarName};
|
||||
use std::fmt::Display;
|
||||
|
||||
use super::{ast_iterator::AstIterator, from_ast::FromAst};
|
||||
use crate::{
|
||||
ast_error::AstError,
|
||||
config::attributes::{AttrEntry, Attributes},
|
||||
error::{DiagError, DiagResult},
|
||||
};
|
||||
use super::ast_iterator::AstIterator;
|
||||
use crate::ast_error::AstError;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub enum AstType {
|
||||
|
@ -92,7 +87,7 @@ impl Ast {
|
|||
// TODO do I do this?
|
||||
// Ast::Array(span, elements) => todo!()
|
||||
Ast::Symbol(span, x) => Ok(SimplExpr::VarRef(*span, VarName(x.clone()))),
|
||||
Ast::SimplExpr(span, x) => Ok(x.clone()),
|
||||
Ast::SimplExpr(_span, x) => Ok(x.clone()),
|
||||
_ => Err(AstError::WrongExprType(self.span(), AstType::IntoPrimitive, self.expr_type())),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,10 @@
|
|||
use itertools::Itertools;
|
||||
use simplexpr::{ast::SimplExpr, dynval::DynVal};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use std::fmt::Display;
|
||||
|
||||
use super::{
|
||||
ast::{Ast, AstType},
|
||||
from_ast::FromAst,
|
||||
};
|
||||
use super::ast::{Ast, AstType};
|
||||
use crate::{
|
||||
ast_error::AstError,
|
||||
config::attributes::{AttrEntry, Attributes},
|
||||
error::{DiagError, DiagResult},
|
||||
format_diagnostic::ToDiagnostic,
|
||||
gen_diagnostic,
|
||||
};
|
||||
use eww_shared_util::{AttrName, Span, Spanned, VarName};
|
||||
|
||||
|
|
|
@ -1,16 +1,8 @@
|
|||
use super::{
|
||||
ast::{Ast, AstType},
|
||||
ast_iterator::AstIterator,
|
||||
};
|
||||
use crate::{error::*, format_diagnostic::ToDiagnostic, gen_diagnostic, parser};
|
||||
use eww_shared_util::{AttrName, Span, Spanned, VarName};
|
||||
use itertools::Itertools;
|
||||
use simplexpr::{ast::SimplExpr, dynval::DynVal};
|
||||
use std::{
|
||||
collections::{HashMap, LinkedList},
|
||||
iter::FromIterator,
|
||||
str::FromStr,
|
||||
};
|
||||
use super::{ast::Ast, ast_iterator::AstIterator};
|
||||
use crate::{error::*, format_diagnostic::ToDiagnostic, gen_diagnostic};
|
||||
use eww_shared_util::{Span, Spanned};
|
||||
|
||||
use simplexpr::ast::SimplExpr;
|
||||
|
||||
pub trait FromAst: Sized {
|
||||
fn from_ast(e: Ast) -> DiagResult<Self>;
|
||||
|
@ -55,7 +47,7 @@ impl FromAst for SimplExpr {
|
|||
fn from_ast(e: Ast) -> DiagResult<Self> {
|
||||
match e {
|
||||
Ast::Symbol(span, x) => Ok(SimplExpr::var_ref(span, x)),
|
||||
Ast::SimplExpr(span, x) => Ok(x),
|
||||
Ast::SimplExpr(_span, x) => Ok(x),
|
||||
_ => Err(DiagError(gen_diagnostic! {
|
||||
msg = format!("Expected value, but got `{}`", e.expr_type()),
|
||||
label = e.span() => "Expected some value here",
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
use once_cell::sync::Lazy;
|
||||
use regex::{Regex, RegexSet};
|
||||
use simplexpr::parser::lexer::{STR_INTERPOLATION_END, STR_INTERPOLATION_START};
|
||||
|
||||
use super::parse_error;
|
||||
use eww_shared_util::{AttrName, Span, Spanned, VarName};
|
||||
use eww_shared_util::{Span, Spanned};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub enum Token {
|
||||
|
@ -54,8 +53,6 @@ macro_rules! regex_rules {
|
|||
}
|
||||
}
|
||||
|
||||
static ESCAPE_REPLACE_REGEX: Lazy<regex::Regex> = Lazy::new(|| Regex::new(r"\\(.)").unwrap());
|
||||
|
||||
regex_rules! {
|
||||
r"\(" => |_| Token::LPren,
|
||||
r"\)" => |_| Token::RPren,
|
||||
|
@ -100,7 +97,7 @@ impl Lexer {
|
|||
self.pos += 1;
|
||||
let mut simplexpr_lexer = simplexpr_lexer::Lexer::new(self.file_id, self.pos, &self.source[self.pos..]);
|
||||
let mut toks: Vec<(usize, _, usize)> = Vec::new();
|
||||
let mut end = self.pos;
|
||||
let mut end;
|
||||
let mut curly_nesting = 0;
|
||||
loop {
|
||||
match simplexpr_lexer.next_token()? {
|
||||
|
|
|
@ -6,10 +6,6 @@ use crate::gen_diagnostic;
|
|||
use super::error::{DiagError, DiagResult};
|
||||
use ast::Ast;
|
||||
|
||||
use std::{fmt::Display, ops::Deref};
|
||||
|
||||
use itertools::Itertools;
|
||||
|
||||
pub mod ast;
|
||||
pub mod ast_iterator;
|
||||
pub mod from_ast;
|
||||
|
@ -43,7 +39,7 @@ pub fn require_single_toplevel(span: Span, mut asts: Vec<Ast>) -> DiagResult<Ast
|
|||
msg = "Expected exactly one element, but got none",
|
||||
label = span
|
||||
})),
|
||||
n => Err(DiagError(gen_diagnostic! {
|
||||
_n => Err(DiagError(gen_diagnostic! {
|
||||
msg = "Expected exactly one element, but but got {n}",
|
||||
label = asts.get(1).unwrap().span().to(asts.last().unwrap().span()) => "these elements must not be here",
|
||||
note = "Consider wrapping the elements in some container element",
|
||||
|
@ -51,6 +47,9 @@ pub fn require_single_toplevel(span: Span, mut asts: Vec<Ast>) -> DiagResult<Ast
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
macro_rules! test_parser {
|
||||
($($text:literal),*) => {{
|
||||
let p = parser::AstParser::new();
|
||||
|
@ -87,3 +86,4 @@ fn test() {
|
|||
"\"h\\\"i\""
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use eww_shared_util::{AttrName, Span, Spanned, VarName};
|
||||
use eww_shared_util::{Span, Spanned};
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum ParseError {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use std::str::FromStr;
|
||||
use crate::parser::{lexer::Token, ast::Ast, parse_error};
|
||||
use eww_shared_util::Span;
|
||||
use simplexpr::ast::SimplExpr;
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
use derive_more::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub mod coords;
|
||||
pub use coords::*;
|
||||
|
|
Loading…
Add table
Reference in a new issue