Skip to content

Commit b1b6ed9

Browse files
committed
Clean up macros’ doc-comments.
1 parent ba6d943 commit b1b6ed9

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

macros/lib.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ extern crate syn;
1111
use std::ascii::AsciiExt;
1212

1313
define_proc_macros! {
14-
/// Panic if any string contains ASCII uppercase letters.
15-
/// Emit a `MAX_LENGTH` constant with the length of the longest string.
14+
/// Input: the arms of a `match` expression.
15+
///
16+
/// Output: a `MAX_LENGTH` constant with the length of the longest string pattern.
17+
///
18+
/// Panic if the arms contain non-string patterns,
19+
/// or string patterns that contains ASCII uppercase letters.
1620
#[allow(non_snake_case)]
1721
pub fn cssparser_internal__assert_ascii_lowercase__max_len(input: &str) -> String {
1822
let expr = syn::parse_expr(&format!("match x {{ {} }}", input)).unwrap();
@@ -45,17 +49,22 @@ define_proc_macros! {
4549
}))
4650
}
4751

48-
/// Emit a `MAX_LENGTH` constant with the length of the longest string.
52+
/// Input: string literals with no separator
53+
///
54+
/// Output: a `MAX_LENGTH` constant with the length of the longest string.
4955
#[allow(non_snake_case)]
5056
pub fn cssparser_internal__max_len(input: &str) -> String {
5157
max_len(syn::parse_token_trees(input).unwrap().iter().map(|tt| string_literal(tt).len()))
5258
}
5359

60+
/// Input: parsed as token trees. The first TT is a type. (Can be wrapped in parens.)
61+
/// following TTs are grouped in pairs, each pair being a key as a string literal
62+
/// and the corresponding value as a const expression.
63+
///
64+
/// Output: a rust-phf map, with keys ASCII-lowercased:
5465
/// ```
55-
/// static MAP: &'static ::phf::Map<&'static str, $ValueType> = …;
66+
/// static MAP: &'static ::cssparser::phf::Map<&'static str, $ValueType> = …;
5667
/// ```
57-
///
58-
/// Map keys are ASCII-lowercased.
5968
#[allow(non_snake_case)]
6069
pub fn cssparser_internal__phf_map(input: &str) -> String {
6170
let token_trees = syn::parse_token_trees(input).unwrap();

src/macros.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5+
/// See docs of the `procedural-masquarade` crate.
56
define_invoke_proc_macro!(cssparser_internal__invoke_proc_macro);
67

7-
/// Expands to an expression equivalent to a `match` with string patterns,
8-
/// but matching is case-insensitive in the ASCII range.
8+
/// Expands to a `match` expression with string patterns,
9+
/// matching case-insensitively in the ASCII range.
910
///
1011
/// The patterns must not contain ASCII upper case letters. (They must be already be lower-cased.)
1112
///
@@ -63,7 +64,7 @@ macro_rules! match_ignore_ascii_case {
6364
/// ```rust
6465
/// #[macro_use] extern crate cssparser;
6566
///
66-
/// # fn main() {} // Make doctest not wrap everythig in its own main
67+
/// # fn main() {} // Make doctest not wrap everything in its own main
6768
///
6869
/// fn color_rgb(input: &str) -> Option<(u8, u8, u8)> {
6970
/// ascii_case_insensitive_phf_map! {
@@ -99,18 +100,18 @@ macro_rules! ascii_case_insensitive_phf_map {
99100
///
100101
/// **This macro is not part of the public API. It can change or be removed between any versions.**
101102
///
102-
/// * Check at compile-time that none of the `$string`s contain ASCII uppercase letters
103-
/// * Define a local variable named `$output` to the result of calling `_internal__to_lowercase`
104-
/// with a stack-allocated buffer as long as the longest `$string`.
103+
/// Define a local variable named `$output`
104+
/// and assign it the result of calling `_internal__to_lowercase`
105+
/// with a stack-allocated buffer of length `$BUFFER_SIZE`.
105106
#[macro_export]
106107
#[doc(hidden)]
107108
macro_rules! cssparser_internal__to_lowercase {
108-
($input: expr, $MAX_LENGTH: expr => $output: ident) => {
109+
($input: expr, $BUFFER_SIZE: expr => $output: ident) => {
109110
// mem::uninitialized() is ok because `buffer` is only used in `_internal__to_lowercase`,
110111
// which initializes with `copy_from_slice` the part of the buffer it uses,
111112
// before it uses it.
112113
#[allow(unsafe_code)]
113-
let mut buffer: [u8; $MAX_LENGTH] = unsafe {
114+
let mut buffer: [u8; $BUFFER_SIZE] = unsafe {
114115
::std::mem::uninitialized()
115116
};
116117
let input: &str = $input;
@@ -122,8 +123,8 @@ macro_rules! cssparser_internal__to_lowercase {
122123
///
123124
/// **This function is not part of the public API. It can change or be removed between any verisons.**
124125
///
125-
/// Return `input`, lower-cased, unless larger than `buffer`
126-
/// which is used temporary space for lower-casing a copy of `input` if necessary.
126+
/// If `input` is larger than buffer, return `None`.
127+
/// Otherwise, return `input` ASCII-lowercased, using `buffer` as temporary space if necessary.
127128
#[doc(hidden)]
128129
#[allow(non_snake_case)]
129130
pub fn _internal__to_lowercase<'a>(buffer: &'a mut [u8], input: &'a str) -> Option<&'a str> {

0 commit comments

Comments
 (0)