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