1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! Code generation base library for v_escape
//!
//! This crate provides the core functionality for generating SIMD-optimized escape functions
//! from character mappings. It parses template files and generates the necessary code
//! for efficient string escaping operations.
use ;
use TokenStream;
/// Generate escape functions from a token stream template
///
/// This function takes a token stream representing character mappings and generates
/// the corresponding escape function implementations. It returns both the generated
/// code and metadata about the escape mappings.
///
/// # Arguments
///
/// * `tokens` - A token stream containing the character mappings in the format `new!(char -> "escape", ...)`
/// * `crate_name` - The name of the crate where the generated code will be used
///
/// # Returns
///
/// Returns a tuple containing:
/// * The generated code as a `TokenStream`
/// * A `Vec<(u8, String)>` of `(char_byte, replacement)` pairs, sorted by `char_byte`
/// ascending. Callers can derive convenience strings (such as the concatenation of
/// all source bytes or replacements) from this list as needed.
///
/// # Errors
///
/// Returns a `syn::Error` if the token stream cannot be parsed or if the character
/// mappings are invalid.