diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-08-06 04:59:36 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-08-06 04:59:36 +0000 |
commit | 454368dfbf11dad54567f004b94db90118bfc0b2 (patch) | |
tree | 14136e465198ea574f85d696698067aab0dc7a90 | |
parent | 97b2307e4ae2223fb2f9020bfa49e0e8924a268f (diff) | |
parent | be85bae2e516ce3b2b7874e94e5bb4fea6c30754 (diff) | |
download | riki-454368dfbf11dad54567f004b94db90118bfc0b2.tar.gz |
Merge branch 'dummy-directives' into 'main'
fix: single-quoted values may also contain newlines
See merge request larswirzenius/riki!37
-rw-r--r-- | src/directive/brokenlinks.rs | 27 | ||||
-rw-r--r-- | src/directive/img.rs | 2 | ||||
-rw-r--r-- | src/directive/inline.rs | 38 | ||||
-rw-r--r-- | src/directive/mod.rs | 58 | ||||
-rw-r--r-- | src/directive/pagestats.rs | 27 | ||||
-rw-r--r-- | src/directive/shortcut.rs | 27 | ||||
-rw-r--r-- | src/directive/toc.rs | 27 | ||||
-rw-r--r-- | src/token.rs | 4 |
8 files changed, 206 insertions, 4 deletions
diff --git a/src/directive/brokenlinks.rs b/src/directive/brokenlinks.rs new file mode 100644 index 0000000..c6364a4 --- /dev/null +++ b/src/directive/brokenlinks.rs @@ -0,0 +1,27 @@ +use crate::error::SiteError; +use crate::page::PageMeta; +use crate::site::Site; +use crate::wikitext::ParsedDirective; + +#[derive(Debug, Default, Eq, PartialEq)] +pub struct BrokenLinks {} + +impl BrokenLinks { + pub const REQUIRED: &'static [&'static str] = &["pages"]; + pub const ALLOWED: &'static [&'static str] = &[]; + pub const ALLOW_ANY_UNNAMED: bool = false; + + pub fn new() -> Self { + Self::default() + } + + pub fn process(&self, _site: &Site, _meta: &mut PageMeta) -> Result<String, SiteError> { + Ok("FIXME:inline".into()) + } +} + +impl From<ParsedDirective> for BrokenLinks { + fn from(_p: ParsedDirective) -> Self { + Self::new() + } +} diff --git a/src/directive/img.rs b/src/directive/img.rs index e10851e..dea2625 100644 --- a/src/directive/img.rs +++ b/src/directive/img.rs @@ -12,7 +12,7 @@ pub struct Img { impl Img { pub const REQUIRED: &'static [&'static str] = &[]; - pub const ALLOWED: &'static [&'static str] = &["class"]; + pub const ALLOWED: &'static [&'static str] = &["alt", "class", "link"]; pub const ALLOW_ANY_UNNAMED: bool = true; pub fn new(src: String) -> Self { diff --git a/src/directive/inline.rs b/src/directive/inline.rs new file mode 100644 index 0000000..efaf7ee --- /dev/null +++ b/src/directive/inline.rs @@ -0,0 +1,38 @@ +use crate::error::SiteError; +use crate::page::PageMeta; +use crate::site::Site; +use crate::wikitext::ParsedDirective; + +#[derive(Debug, Default, Eq, PartialEq)] +pub struct Inline {} + +impl Inline { + pub const REQUIRED: &'static [&'static str] = &["pages"]; + pub const ALLOWED: &'static [&'static str] = &[ + "actions", + "archive", + "description", + "feedlimit", + "feeds", + "feedshow", + "limit", + "sort", + "template", + "trail", + ]; + pub const ALLOW_ANY_UNNAMED: bool = true; + + pub fn new() -> Self { + Self::default() + } + + pub fn process(&self, _site: &Site, _meta: &mut PageMeta) -> Result<String, SiteError> { + Ok("FIXME:inline".into()) + } +} + +impl From<ParsedDirective> for Inline { + fn from(_p: ParsedDirective) -> Self { + Inline::new() + } +} diff --git a/src/directive/mod.rs b/src/directive/mod.rs index 38fb0d3..ee96bfc 100644 --- a/src/directive/mod.rs +++ b/src/directive/mod.rs @@ -12,9 +12,14 @@ pub enum Directive { QuotedArg, MultilineArg, - Meta(Meta), + BrokenLinks(BrokenLinks), Img(Img), + Inline(Inline), + Meta(Meta), + PageStats(PageStats), + Shortcut(Shortcut), Tag(Tag), + Toc(Toc), } impl TryFrom<ParsedDirective> for Directive { @@ -42,18 +47,49 @@ impl TryFrom<ParsedDirective> for Directive { Self::check_args(&p, &["yo"], &["then", "else"], false)?; Directive::MultilineArg } + + "brokenlinks" => { + Self::check_args(&p, BrokenLinks::REQUIRED, BrokenLinks::ALLOWED, BrokenLinks::ALLOW_ANY_UNNAMED)?; + Directive::BrokenLinks(BrokenLinks::from(p)) + } "img" => { Self::check_args(&p, Img::REQUIRED, Img::ALLOWED, Img::ALLOW_ANY_UNNAMED)?; Directive::Img(Img::from(p)) } + "inline" => { + Self::check_args( + &p, + Inline::REQUIRED, + Inline::ALLOWED, + Inline::ALLOW_ANY_UNNAMED, + )?; + Directive::Inline(Inline::from(p)) + } "meta" => { Self::check_args(&p, Meta::REQUIRED, Meta::ALLOWED, Meta::ALLOW_ANY_UNNAMED)?; Directive::Meta(Meta::from(p)) } + "pagestats" => { + Self::check_args( + &p, + PageStats::REQUIRED, + PageStats::ALLOWED, + PageStats::ALLOW_ANY_UNNAMED, + )?; + Directive::PageStats(PageStats::from(p)) + } + "shortcut" => { + Self::check_args(&p, Shortcut::REQUIRED, Shortcut::ALLOWED, Shortcut::ALLOW_ANY_UNNAMED)?; + Directive::Shortcut(Shortcut::from(p)) + } "tag" => { Self::check_args(&p, Tag::REQUIRED, Tag::ALLOWED, Tag::ALLOW_ANY_UNNAMED)?; Directive::Tag(Tag::from(p)) } + "toc" => { + Self::check_args(&p, Toc::REQUIRED, Toc::ALLOWED, Toc::ALLOW_ANY_UNNAMED)?; + Directive::Toc(Toc::from(p)) + } _ => return Err(SiteError::UnknownDirective(p.name().into())), }; Ok(d) @@ -100,18 +136,38 @@ impl Directive { | Self::MultilineArg => { panic!("directive {:?} may only be used in parsing tests", self) } + Self::BrokenLinks(x) => x.process(site, meta), Self::Img(x) => x.process(site, meta), + Self::Inline(x) => x.process(site, meta), Self::Meta(x) => x.process(site, meta), + Self::PageStats(x) => x.process(site, meta), + Self::Shortcut(x) => x.process(site, meta), Self::Tag(x) => x.process(site, meta), + Self::Toc(x) => x.process(site, meta), } } } +mod brokenlinks; +use brokenlinks::BrokenLinks; + mod meta; use meta::Meta; mod img; pub use img::Img; +mod inline; +pub use inline::Inline; + +mod pagestats; +pub use pagestats::PageStats; + +mod shortcut; +pub use shortcut::Shortcut; + mod tag; use tag::Tag; + +mod toc; +use toc::Toc; diff --git a/src/directive/pagestats.rs b/src/directive/pagestats.rs new file mode 100644 index 0000000..1a6f811 --- /dev/null +++ b/src/directive/pagestats.rs @@ -0,0 +1,27 @@ +use crate::error::SiteError; +use crate::page::PageMeta; +use crate::site::Site; +use crate::wikitext::ParsedDirective; + +#[derive(Debug, Default, Eq, PartialEq)] +pub struct PageStats {} + +impl PageStats { + pub const REQUIRED: &'static [&'static str] = &["pages"]; + pub const ALLOWED: &'static [&'static str] = &["style"]; + pub const ALLOW_ANY_UNNAMED: bool = true; + + pub fn new() -> Self { + Self::default() + } + + pub fn process(&self, _site: &Site, _meta: &mut PageMeta) -> Result<String, SiteError> { + Ok("FIXME:inline".into()) + } +} + +impl From<ParsedDirective> for PageStats { + fn from(_p: ParsedDirective) -> Self { + Self::new() + } +} diff --git a/src/directive/shortcut.rs b/src/directive/shortcut.rs new file mode 100644 index 0000000..03fd648 --- /dev/null +++ b/src/directive/shortcut.rs @@ -0,0 +1,27 @@ +use crate::error::SiteError; +use crate::page::PageMeta; +use crate::site::Site; +use crate::wikitext::ParsedDirective; + +#[derive(Debug, Default, Eq, PartialEq)] +pub struct Shortcut {} + +impl Shortcut { + pub const REQUIRED: &'static [&'static str] = &["desc", "name", "url"]; + pub const ALLOWED: &'static [&'static str] = &[]; + pub const ALLOW_ANY_UNNAMED: bool = true; + + pub fn new() -> Self { + Self::default() + } + + pub fn process(&self, _site: &Site, _meta: &mut PageMeta) -> Result<String, SiteError> { + Ok("FIXME:inline".into()) + } +} + +impl From<ParsedDirective> for Shortcut { + fn from(_p: ParsedDirective) -> Self { + Self::new() + } +} diff --git a/src/directive/toc.rs b/src/directive/toc.rs new file mode 100644 index 0000000..6db46d2 --- /dev/null +++ b/src/directive/toc.rs @@ -0,0 +1,27 @@ +use crate::error::SiteError; +use crate::page::PageMeta; +use crate::site::Site; +use crate::wikitext::ParsedDirective; + +#[derive(Debug, Default, Eq, PartialEq)] +pub struct Toc {} + +impl Toc { + pub const REQUIRED: &'static [&'static str] = &[]; + pub const ALLOWED: &'static [&'static str] = &["levels"]; + pub const ALLOW_ANY_UNNAMED: bool = true; + + pub fn new() -> Self { + Self::default() + } + + pub fn process(&self, _site: &Site, _meta: &mut PageMeta) -> Result<String, SiteError> { + Ok("FIXME:inline".into()) + } +} + +impl From<ParsedDirective> for Toc { + fn from(_p: ParsedDirective) -> Self { + Self::new() + } +} diff --git a/src/token.rs b/src/token.rs index 76cd7b4..5109ce1 100644 --- a/src/token.rs +++ b/src/token.rs @@ -33,9 +33,9 @@ impl Default for TokenPatterns { fn default() -> Self { Self { plain: Regex::new(r#"(?P<value>[^\[]+)"#).unwrap(), - word: Regex::new(r#"[-._/[:alpha:][:digit:]]+"#).unwrap(), + word: Regex::new(r#"[-.:_/[:alpha:][:digit:]]+"#).unwrap(), spaces: Regex::new(r#"([[:space:]]|\n)+"#).unwrap(), - single_quoted: Regex::new(r#""(?P<value>.*?)""#).unwrap(), + single_quoted: Regex::new(r#""(?P<value>(.|\n)*?)""#).unwrap(), triple_quoted: Regex::new(r#""""(?P<value>(.|\n)*?)""""#).unwrap(), } } |