Created
August 9, 2019 13:21
-
-
Save Tristramg/40f4aba693adaa9b0cafb3e17a122efe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro_rules! select_variables ( | |
() => {""}; | |
($head:ident $($tail:ident)*) => { | |
concat!(" ?", stringify!($head), select_variables!($($tail)*)); | |
}; | |
); | |
macro_rules! fmt( | |
($a:tt) => {stringify!($a)}; | |
(?$a:tt) => {concat!("?", stringify!($a))}; | |
($ns:ident : $val:ident) => {concat!(stringify!($ns), ":", stringify($val))} | |
); | |
macro_rules! opt_whitespace( | |
() => {""}; | |
(.$($tail:tt)*) => {concat!(".\n", next_token!($($tail)*))}; | |
($($tail:tt)*) => {concat!(" ", next_token!($($tail)*))}; | |
); | |
macro_rules! next_token( | |
() => {""}; | |
($ns:ident : $val:ident $($tail:tt)*) => {concat!(fmt!($ns : $val), opt_whitespace!($($tail)*))}; | |
(?$var:ident $($tail:tt)*) => {concat!(fmt!(?$var), opt_whitespace!($($tail)*))}; | |
($any:tt $($tail:tt)*) => {concat!(fmt!($any), opt_whitespace!($($tail)*))}; | |
); | |
macro_rules! select( | |
($($var:tt),* where $($statement:tt)*) => { | |
concat!( | |
"SELECT", | |
select_variables!($($var)*), | |
"\nWHERE\n", | |
next_token!($($statement)*), | |
"SERVICE wikibase:label { bd:serviceParam wikibase:language \"en\". }" | |
); | |
}; | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment