summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-09-02 20:14:28 +0300
committerLars Wirzenius <liw@liw.fi>2022-09-02 20:14:28 +0300
commitf2592c364c89924ab8bdd7bce2de6f79eed9dac7 (patch)
treef899ecb2f3aaca59f0042e35d3ec46820cb19893
parent703168d41baab74ea81e2459e67694181255558a (diff)
downloadriki-f2592c364c89924ab8bdd7bce2de6f79eed9dac7.tar.gz
fix: placeholder directives other fixes to process all test sties
Sponsored-by: author
-rw-r--r--src/directive/calendar.rs35
-rw-r--r--src/directive/calendars.rs35
-rw-r--r--src/directive/format.rs27
-rw-r--r--src/directive/img.rs5
-rw-r--r--src/directive/inline.rs2
-rw-r--r--src/directive/mod.rs35
-rw-r--r--src/directive/pagestats.rs2
-rw-r--r--src/directive/sidebar.rs27
-rw-r--r--src/error.rs3
-rw-r--r--src/parser.rs12
10 files changed, 178 insertions, 5 deletions
diff --git a/src/directive/calendar.rs b/src/directive/calendar.rs
new file mode 100644
index 0000000..1c02e16
--- /dev/null
+++ b/src/directive/calendar.rs
@@ -0,0 +1,35 @@
+use crate::error::SiteError;
+use crate::page::PageMeta;
+use crate::site::Site;
+use crate::wikitext::ParsedDirective;
+
+#[derive(Debug, Eq, PartialEq)]
+pub struct Calendar {}
+
+impl Calendar {
+ pub const REQUIRED: &'static [&'static str] = &[];
+ pub const ALLOWED: &'static [&'static str] = &[
+ "type",
+ "pages",
+ "year",
+ "month",
+ "week_start_day",
+ "months_per_row",
+ "archivebase",
+ ];
+ pub const ALLOW_ANY_UNNAMED: bool = true;
+
+ pub fn new() -> Self {
+ Self {}
+ }
+
+ pub fn process(&self, _site: &Site, _meta: &mut PageMeta) -> Result<String, SiteError> {
+ Ok("FIXME:graph".into())
+ }
+}
+
+impl From<&ParsedDirective> for Calendar {
+ fn from(_: &ParsedDirective) -> Self {
+ Calendar::new()
+ }
+}
diff --git a/src/directive/calendars.rs b/src/directive/calendars.rs
new file mode 100644
index 0000000..1c02e16
--- /dev/null
+++ b/src/directive/calendars.rs
@@ -0,0 +1,35 @@
+use crate::error::SiteError;
+use crate::page::PageMeta;
+use crate::site::Site;
+use crate::wikitext::ParsedDirective;
+
+#[derive(Debug, Eq, PartialEq)]
+pub struct Calendar {}
+
+impl Calendar {
+ pub const REQUIRED: &'static [&'static str] = &[];
+ pub const ALLOWED: &'static [&'static str] = &[
+ "type",
+ "pages",
+ "year",
+ "month",
+ "week_start_day",
+ "months_per_row",
+ "archivebase",
+ ];
+ pub const ALLOW_ANY_UNNAMED: bool = true;
+
+ pub fn new() -> Self {
+ Self {}
+ }
+
+ pub fn process(&self, _site: &Site, _meta: &mut PageMeta) -> Result<String, SiteError> {
+ Ok("FIXME:graph".into())
+ }
+}
+
+impl From<&ParsedDirective> for Calendar {
+ fn from(_: &ParsedDirective) -> Self {
+ Calendar::new()
+ }
+}
diff --git a/src/directive/format.rs b/src/directive/format.rs
new file mode 100644
index 0000000..6483310
--- /dev/null
+++ b/src/directive/format.rs
@@ -0,0 +1,27 @@
+use crate::error::SiteError;
+use crate::page::PageMeta;
+use crate::site::Site;
+use crate::wikitext::ParsedDirective;
+
+#[derive(Debug, Eq, PartialEq)]
+pub struct Format {}
+
+impl Format {
+ pub const REQUIRED: &'static [&'static str] = &[];
+ pub const ALLOWED: &'static [&'static str] = &[];
+ pub const ALLOW_ANY_UNNAMED: bool = true;
+
+ pub fn new() -> Self {
+ Self {}
+ }
+
+ pub fn process(&self, _site: &Site, _meta: &mut PageMeta) -> Result<String, SiteError> {
+ Ok("FIXME:format".into())
+ }
+}
+
+impl From<&ParsedDirective> for Format {
+ fn from(_: &ParsedDirective) -> Self {
+ Format::new()
+ }
+}
diff --git a/src/directive/img.rs b/src/directive/img.rs
index d3de868..be165f8 100644
--- a/src/directive/img.rs
+++ b/src/directive/img.rs
@@ -12,8 +12,9 @@ pub struct Img {
impl Img {
pub const REQUIRED: &'static [&'static str] = &[];
- pub const ALLOWED: &'static [&'static str] =
- &["alt", "caption", "class", "height", "link", "width"];
+ pub const ALLOWED: &'static [&'static str] = &[
+ "alt", "caption", "class", "height", "link", "width", "size", "align",
+ ];
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
index c946abd..6bc0d1b 100644
--- a/src/directive/inline.rs
+++ b/src/directive/inline.rs
@@ -16,7 +16,9 @@ impl Inline {
"feeds",
"feedshow",
"limit",
+ "quick",
"reverse",
+ "rootpage",
"show",
"sort",
"template",
diff --git a/src/directive/mod.rs b/src/directive/mod.rs
index 7e49337..261de36 100644
--- a/src/directive/mod.rs
+++ b/src/directive/mod.rs
@@ -3,7 +3,7 @@ use crate::page::PageMeta;
use crate::site::Site;
use crate::wikitext::ParsedDirective;
-use log::trace;
+use log::{debug, trace};
use std::collections::HashSet;
#[derive(Debug, Eq, PartialEq)]
@@ -15,6 +15,8 @@ pub enum Directive {
MultilineArg,
BrokenLinks(BrokenLinks),
+ Calendar(Calendar),
+ Format(Format),
Graph(Graph),
Img(Img),
Inline(Inline),
@@ -22,6 +24,7 @@ pub enum Directive {
Meta(Meta),
PageStats(PageStats),
Shortcut(Shortcut),
+ Sidebar(Sidebar),
Table(Table),
Tag(Tag),
Toc(Toc),
@@ -66,6 +69,14 @@ impl TryFrom<&ParsedDirective> for Directive {
Self::check_args(p, BrokenLinks::REQUIRED, BrokenLinks::ALLOWED, BrokenLinks::ALLOW_ANY_UNNAMED)?;
Directive::BrokenLinks(BrokenLinks::from(p))
}
+ "calendar" => {
+ Self::check_args(p, Calendar::REQUIRED, Calendar::ALLOWED, Calendar::ALLOW_ANY_UNNAMED)?;
+ Directive::Calendar(Calendar::from(p))
+ }
+ "format" => {
+ Self::check_args(p, Format::REQUIRED, Format::ALLOWED, Format::ALLOW_ANY_UNNAMED)?;
+ Directive::Format(Format::from(p))
+ }
"graph" => {
Self::check_args(p, Graph::REQUIRED, Graph::ALLOWED, Graph::ALLOW_ANY_UNNAMED)?;
Directive::Graph(Graph::from(p))
@@ -104,6 +115,10 @@ impl TryFrom<&ParsedDirective> for Directive {
Self::check_args(p, Shortcut::REQUIRED, Shortcut::ALLOWED, Shortcut::ALLOW_ANY_UNNAMED)?;
Directive::Shortcut(Shortcut::from(p))
}
+ "sidebar" => {
+ Self::check_args(p, Sidebar::REQUIRED, Sidebar::ALLOWED, Sidebar::ALLOW_ANY_UNNAMED)?;
+ Directive::Sidebar(Sidebar::from(p))
+ }
"tag" => {
Self::check_args(p, Tag::REQUIRED, Tag::ALLOWED, Tag::ALLOW_ANY_UNNAMED)?;
Directive::Tag(Tag::from(p))
@@ -146,8 +161,12 @@ impl Directive {
let allowed: HashSet<String> = allowed.iter().map(|arg| arg.to_string()).collect();
let allowed: HashSet<String> = required.union(&allowed).cloned().collect();
for (arg, value) in p.args().iter() {
- if allow_any_unnamed && value.is_empty() {
+ if value.is_empty() {
+ if !allow_any_unnamed {
+ return Err(SiteError::UnknownArgsNotAllowed(p.name().into()));
+ }
} else if !allowed.contains(*arg) {
+ debug!("parsed directive {:?}", p);
return Err(SiteError::DirectiveUnknownArg(
p.name().into(),
arg.to_string(),
@@ -175,6 +194,8 @@ impl Directive {
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),
Self::Img(x) => x.process(site, meta),
Self::Inline(x) => x.process(site, meta),
@@ -182,6 +203,7 @@ impl Directive {
Self::Meta(x) => x.process(site, meta),
Self::PageStats(x) => x.process(site, meta),
Self::Shortcut(x) => x.process(site, meta),
+ Self::Sidebar(x) => x.process(site, meta),
Self::Table(x) => x.process(site, meta),
Self::Tag(x) => x.process(site, meta),
Self::Toc(x) => x.process(site, meta),
@@ -193,6 +215,9 @@ impl Directive {
mod brokenlinks;
use brokenlinks::BrokenLinks;
+mod format;
+use format::Format;
+
mod meta;
use meta::Meta;
@@ -225,3 +250,9 @@ use toc::Toc;
mod traillink;
use traillink::TrailLink;
+
+mod calendar;
+use calendar::Calendar;
+
+mod sidebar;
+use sidebar::Sidebar;
diff --git a/src/directive/pagestats.rs b/src/directive/pagestats.rs
index 164ac9c..52e6997 100644
--- a/src/directive/pagestats.rs
+++ b/src/directive/pagestats.rs
@@ -8,7 +8,7 @@ pub struct PageStats {}
impl PageStats {
pub const REQUIRED: &'static [&'static str] = &["pages"];
- pub const ALLOWED: &'static [&'static str] = &["style"];
+ pub const ALLOWED: &'static [&'static str] = &["among", "style"];
pub const ALLOW_ANY_UNNAMED: bool = true;
pub fn new() -> Self {
diff --git a/src/directive/sidebar.rs b/src/directive/sidebar.rs
new file mode 100644
index 0000000..d68f9be
--- /dev/null
+++ b/src/directive/sidebar.rs
@@ -0,0 +1,27 @@
+use crate::error::SiteError;
+use crate::page::PageMeta;
+use crate::site::Site;
+use crate::wikitext::ParsedDirective;
+
+#[derive(Debug, Eq, PartialEq)]
+pub struct Sidebar {}
+
+impl Sidebar {
+ pub const REQUIRED: &'static [&'static str] = &[];
+ pub const ALLOWED: &'static [&'static str] = &["content"];
+ pub const ALLOW_ANY_UNNAMED: bool = true;
+
+ pub fn new() -> Self {
+ Self {}
+ }
+
+ pub fn process(&self, _site: &Site, _meta: &mut PageMeta) -> Result<String, SiteError> {
+ Ok("FIXME:sidebar".into())
+ }
+}
+
+impl From<&ParsedDirective> for Sidebar {
+ fn from(_: &ParsedDirective) -> Self {
+ Sidebar::new()
+ }
+}
diff --git a/src/error.rs b/src/error.rs
index e361a06..528be33 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -38,6 +38,9 @@ pub enum SiteError {
#[error("unknown directive {0}")]
UnknownDirective(String),
+ #[error("directive {0} does not allow unnamed arguments")]
+ UnknownArgsNotAllowed(String),
+
#[error("directive {0} has more than one unnamed argument")]
TooManyUnnamedArgs(String),
diff --git a/src/parser.rs b/src/parser.rs
index 5b0c121..8058aeb 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -90,35 +90,47 @@ impl WikitextParser {
Snippet::WikiLink(wikilink)
}
[Token::OpenBrackets, Token::Bang, Token::Word(name), ..] => {
+ trace!("match [[!{:?}", name);
let name = name.to_string();
let mut args = HashMap::new();
self.tokens.drain(..3);
loop {
match &self.tokens[..] {
[Token::Spaces(_), ..] => {
+ trace!("match spaces");
self.tokens.drain(..1);
}
[Token::CloseBrackets, ..] => {
+ trace!("match ]]");
self.tokens.drain(..1);
break;
}
[Token::Word(word), Token::Spaces(_), ..] => {
+ trace!("match {:?} spaces", word);
args.insert(word.to_string(), "".to_string());
self.tokens.drain(..2);
}
[Token::Word(word), Token::CloseBrackets, ..] => {
+ trace!("match {:?}]]", word);
args.insert(word.to_string(), "".to_string());
self.tokens.drain(..2);
break;
}
[Token::Word(name), Token::Equals, Token::Word(value), ..] => {
+ trace!("match {:?}={:?}", name, value);
args.insert(name.to_string(), value.to_string());
self.tokens.drain(..3);
}
[Token::Word(name), Token::Equals, Token::QuotedValue(value), ..] => {
+ trace!("match {:?}={:?}", name, value);
args.insert(name.to_string(), value.to_string());
self.tokens.drain(..3);
}
+ [Token::QuotedValue(value), ..] => {
+ trace!("match {:?}", value);
+ args.insert(value.to_string(), "".to_string());
+ self.tokens.drain(..1);
+ }
_ => panic!("can't parse: {:?}", &self.tokens[..5]),
}
}