Skip to content

Rewrite procedural macro based on the enum discriminant trick #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Feb 28, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove requirements for users to import other crates.
  • Loading branch information
SimonSapin committed Feb 27, 2017
commit ba6d9430549a5cc4285837c5e8c5fd728443cf1d
3 changes: 2 additions & 1 deletion macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ define_proc_macros! {
}).collect();

let mut map = phf_codegen::Map::new();
map.phf_path("::cssparser::phf");
for &(ref key, ref value) in &pairs {
map.entry(&**key, &**value);
}

let mut tokens = quote! {
static MAP: ::phf::Map<&'static str, #value_type> =
static MAP: ::cssparser::phf::Map<&'static str, #value_type> =
};
let mut initializer_bytes = Vec::new();
map.build(&mut initializer_bytes).unwrap();
Expand Down
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ fn parse_border_spacing(_context: &ParserContext, input: &mut Parser)
#[macro_use] extern crate cssparser_macros;
#[macro_use] extern crate matches;
#[macro_use] extern crate procedural_masquarade;
extern crate phf;
pub extern crate phf;
#[cfg(test)] extern crate encoding_rs;
#[cfg(test)] extern crate tempdir;
#[cfg(test)] extern crate rustc_serialize;
#[cfg(feature = "serde")] extern crate serde;
#[cfg(feature = "heapsize")] #[macro_use] extern crate heapsize;

pub use cssparser_macros::*;

pub use tokenizer::{Token, NumericValue, PercentageValue, SourceLocation};
pub use rules_and_declarations::{parse_important};
pub use rules_and_declarations::{DeclarationParser, DeclarationListParser, parse_one_declaration};
Expand All @@ -90,8 +92,12 @@ pub use serializer::{ToCss, CssStringWriter, serialize_identifier, serialize_str
pub use parser::{Parser, Delimiter, Delimiters, SourcePosition};
pub use unicode_range::UnicodeRange;

// For macros
#[doc(hidden)] pub use macros::_internal__to_lowercase;

// For macros when used in this crate. Unsure how $crate works with procedural-masquarade.
mod cssparser { pub use phf; }

#[macro_use]
mod macros;

Expand Down
10 changes: 1 addition & 9 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ define_invoke_proc_macro!(cssparser_internal__invoke_proc_macro);
/// Expands to an expression equivalent to a `match` with string patterns,
/// but matching is case-insensitive in the ASCII range.
///
/// Requirements:
///
/// * The `cssparser_macros` crate must also be imported at the crate root
/// * The patterns must not contain ASCII upper case letters. (They must be already be lower-cased.)
/// The patterns must not contain ASCII upper case letters. (They must be already be lower-cased.)
///
/// # Example
///
/// ```rust
/// #[macro_use] extern crate cssparser;
/// #[macro_use] extern crate cssparser_macros;
///
/// # fn main() {} // Make doctest not wrap everythig in its own main
/// # fn dummy(function_name: &String) { let _ =
Expand Down Expand Up @@ -62,14 +58,10 @@ macro_rules! match_ignore_ascii_case {
/// and returns a reference to the corresponding value.
/// Matching is case-insensitive in the ASCII range.
///
/// The `phf` and `cssparser_macros` crates must also be imported at the crate root
///
/// ## Example:
///
/// ```rust
/// extern crate phf;
/// #[macro_use] extern crate cssparser;
/// #[macro_use] extern crate cssparser_macros;
///
/// # fn main() {} // Make doctest not wrap everythig in its own main
///
Expand Down