diff options
author | Lars Wirzenius <liw@liw.fi> | 2023-02-06 17:37:21 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-02-06 17:37:21 +0000 |
commit | 87b6778163210748e1c80368cd5ca91afa4a07b9 (patch) | |
tree | c6d11dae11801085e029c634e9026200748d9db0 | |
parent | 5107dc741bba0114012beefd09d0a46cc9989d67 (diff) | |
parent | dbef527278c9beebfdeaa7b36c036aaff3ca114d (diff) | |
download | riki-87b6778163210748e1c80368cd5ca91afa4a07b9.tar.gz |
Merge branch 'liw/map' into 'main'
allow my journal to be parsed
See merge request larswirzenius/riki!74
-rw-r--r-- | src/directive/brokenlinks.rs | 26 | ||||
-rw-r--r-- | src/directive/map.rs | 6 | ||||
-rw-r--r-- | src/directive/mod.rs | 14 | ||||
-rw-r--r-- | src/directive/pagestats.rs | 9 | ||||
-rw-r--r-- | src/pagespec.lalrpop | 3 | ||||
-rw-r--r-- | src/pagespec.rs | 13 |
6 files changed, 63 insertions, 8 deletions
diff --git a/src/directive/brokenlinks.rs b/src/directive/brokenlinks.rs new file mode 100644 index 0000000..b95c0aa --- /dev/null +++ b/src/directive/brokenlinks.rs @@ -0,0 +1,26 @@ +use crate::directive::{DirectiveError, DirectiveImplementation, Processed}; +use crate::page::PageMeta; +use crate::site::Site; +use crate::wikitext::ParsedDirective; +use log::warn; + +#[derive(Debug, Default, Eq, PartialEq)] +pub struct Brokenlinks {} + +impl DirectiveImplementation for Brokenlinks { + const REQUIRED: &'static [&'static str] = &["pages"]; + const ALLOWED: &'static [&'static str] = &[]; + const ALLOW_ANY_UNNAMED: bool = false; + + fn from_parsed(_: &ParsedDirective) -> Self { + Self::default() + } + + fn process(&self, _site: &Site, meta: &mut PageMeta) -> Result<Processed, DirectiveError> { + warn!( + "page {} uses unimplemented brokenlinks", + meta.path().display() + ); + Ok(Processed::Markdown("\n".into())) + } +} diff --git a/src/directive/map.rs b/src/directive/map.rs index 5d784ab..b4e4c59 100644 --- a/src/directive/map.rs +++ b/src/directive/map.rs @@ -2,6 +2,7 @@ use crate::directive::{DirectiveError, DirectiveImplementation, Processed}; use crate::page::PageMeta; use crate::site::Site; use crate::wikitext::ParsedDirective; +use log::warn; #[derive(Debug, Default, Eq, PartialEq)] pub struct Map {} @@ -15,7 +16,8 @@ impl DirectiveImplementation for Map { Self::default() } - fn process(&self, _site: &Site, _meta: &mut PageMeta) -> Result<Processed, DirectiveError> { - Err(DirectiveError::UnimplementedDirective("map".into())) + fn process(&self, _site: &Site, meta: &mut PageMeta) -> Result<Processed, DirectiveError> { + warn!("page {} uses unimplemented map", meta.path().display()); + Ok(Processed::Markdown("\n".into())) } } diff --git a/src/directive/mod.rs b/src/directive/mod.rs index 4efde55..a5f6b77 100644 --- a/src/directive/mod.rs +++ b/src/directive/mod.rs @@ -61,6 +61,7 @@ pub enum Directive { QuotedArg, MultilineArg, + Brokenlinks(Brokenlinks), Calendar(Calendar), Format(Format), Graph(Graph), @@ -111,6 +112,15 @@ impl TryFrom<&ParsedDirective> for Directive { Directive::MultilineArg } + "brokenlinks" => { + Self::check_args( + p, + Brokenlinks::REQUIRED, + Brokenlinks::ALLOWED, + Brokenlinks::ALLOW_ANY_UNNAMED, + )?; + Directive::Brokenlinks(Brokenlinks::from_parsed(p)) + } "calendar" => { Self::check_args( p, @@ -264,6 +274,7 @@ impl Directive { | Self::MultilineArg => { panic!("directive {:?} may only be used in parsing tests", self) } + Self::Brokenlinks(x) => x.process(site, meta), Self::Calendar(x) => x.process(site, meta), Self::Format(x) => x.process(site, meta), Self::Graph(x) => x.process(site, meta), @@ -323,3 +334,6 @@ use calendar::Calendar; mod sidebar; use sidebar::Sidebar; + +mod brokenlinks; +use brokenlinks::Brokenlinks; diff --git a/src/directive/pagestats.rs b/src/directive/pagestats.rs index eb3b595..c2afd9b 100644 --- a/src/directive/pagestats.rs +++ b/src/directive/pagestats.rs @@ -2,6 +2,7 @@ use crate::directive::{DirectiveError, DirectiveImplementation, Processed}; use crate::page::PageMeta; use crate::site::Site; use crate::wikitext::ParsedDirective; +use log::warn; #[derive(Debug, Default, Eq, PartialEq)] pub struct PageStats {} @@ -15,7 +16,11 @@ impl DirectiveImplementation for PageStats { Self::default() } - fn process(&self, _site: &Site, _meta: &mut PageMeta) -> Result<Processed, DirectiveError> { - Err(DirectiveError::UnimplementedDirective("pagestat".into())) + fn process(&self, _site: &Site, meta: &mut PageMeta) -> Result<Processed, DirectiveError> { + warn!( + "page {} uses unimplemented pagestats", + meta.path().display() + ); + Ok(Processed::Markdown("\n".into())) } } diff --git a/src/pagespec.lalrpop b/src/pagespec.lalrpop index bc07744..191ff47 100644 --- a/src/pagespec.lalrpop +++ b/src/pagespec.lalrpop @@ -9,8 +9,9 @@ pub Expr: Box<Expr> = { Term: Box<Expr> = { Glob => Box::new(Expr::Glob(<>)), - "link" "(" "." ")" => Box::new(Expr::LinksHereFunc), + "link" "(" <g:Glob> ")" => Box::new(Expr::LinksHereFunc(<>)), "page" "(" <g:Glob> ")" => Box::new(Expr::PageFunc(<>)), + "tagged" "(" <g:Glob> ")" => Box::new(Expr::TaggedFunc(<>)), "!" <t:Term> => Box::new(Expr::Negate(t)), "(" <e:Expr> ")" => e, } diff --git a/src/pagespec.rs b/src/pagespec.rs index e3f617d..8d12440 100644 --- a/src/pagespec.rs +++ b/src/pagespec.rs @@ -64,8 +64,9 @@ pub enum PageSpecError { #[derive(Debug)] pub enum Expr { Glob(String), - LinksHereFunc, + LinksHereFunc(String), PageFunc(String), + TaggedFunc(String), Negate(Box<Expr>), Op(Box<Expr>, OpCode, Box<Expr>), } @@ -75,8 +76,9 @@ impl Expr { trace!("Expr::matches: path={:?} self={:?}", path, self); match self { Self::Glob(glob) => glob_matches(glob, path), - Self::LinksHereFunc => links_here(site, container, path), // FIXME: check its page + Self::LinksHereFunc(glob) => links_here(site, container, path, glob), Self::PageFunc(glob) => page_matches(site, container, glob, path), // FIXME: check its page + Self::TaggedFunc(glob) => tagged(site, container, glob, path), Self::Negate(expr) => !expr.matches(site, container, path), Self::Op(left, op, right) => match op { OpCode::And => { @@ -148,7 +150,7 @@ fn glob_matches_helper(mut glob: &[char], mut path: &[char]) -> bool { glob.is_empty() && path.is_empty() } -fn links_here(site: &Site, container: &Path, path: &str) -> bool { +fn links_here(site: &Site, container: &Path, path: &str, _glob: &str) -> bool { trace!( "links_here: container={} path={:?}", container.display(), @@ -169,6 +171,11 @@ fn links_here(site: &Site, container: &Path, path: &str) -> bool { false } +fn tagged(_site: &Site, container: &Path, path: &str, _glob: &str) -> bool { + trace!("tagged: container={} path={:?}", container.display(), path); + false +} + fn page_matches(site: &Site, container: &Path, glob: &str, path: &str) -> bool { if glob_matches(glob, path) { let full_path = container.join(path); |