unic_char_range/
macros.rs

1// Copyright 2017 The UNIC Project Developers.
2//
3// See the COPYRIGHT file at the top-level directory of this distribution.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11#[macro_export]
12/// Convenience macro for the initialization of `CharRange`s.
13///
14/// # Syntax
15///
16/// ```
17/// # #[macro_use] extern crate unic_char_range;
18/// # fn main() {
19/// chars!('a'..'z'); // The half open range including 'a' and excluding 'z'
20/// chars!('a'..='z'); // The closed range including 'a' and including 'z'
21/// chars!(..); // All characters
22/// # }
23/// ```
24///
25/// `chars!('a'..='z')` and `chars!(..)` are constant-time expressions, and can be used
26/// where such are required, such as in the initialization of constant data structures.
27///
28/// NOTE: Because an `expr` capture cannot be followed by a `..`/`..=`, this macro captures token
29/// trees. This means that if you want to pass more than one token, you must parenthesize it (e.g.
30/// `chars!('\0' ..= (char::MAX))`).
31macro_rules! chars {
32    ( $low:tt .. $high:tt ) => {
33        $crate::CharRange::open_right($low, $high)
34    };
35    ( $low:tt ..= $high:tt ) => {
36        $crate::CharRange {
37            low: $low,
38            high: $high,
39        }
40    };
41    ( .. ) => {
42        $crate::CharRange::all()
43    };
44}