parent
592ebf6e3a
commit
cd494d0f76
@ -1 +1 @@
|
||||
/target
|
||||
target
|
||||
|
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "macros"
|
||||
version = "0.0.0"
|
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "macros"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
@ -0,0 +1,36 @@
|
||||
use proc_macro::{
|
||||
TokenStream,
|
||||
TokenTree::{self, Ident, Literal},
|
||||
};
|
||||
|
||||
fn next_pair<I: Iterator<Item=TokenTree>>(tokens: &mut I) -> Option<(TokenTree, TokenTree)> {
|
||||
match (tokens.next(), tokens.next()) {
|
||||
(Some(a), Some(b)) => Some((a, b)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
struct Escape {
|
||||
sequence: String,
|
||||
name: String,
|
||||
}
|
||||
|
||||
#[proc_macro]
|
||||
pub fn escapes(tokens: TokenStream) -> TokenStream {
|
||||
let mut it = tokens.into_iter();
|
||||
let mut pairs: Vec<Escape> = Vec::new();
|
||||
|
||||
while let Some(pair) = next_pair(&mut it) {
|
||||
match (pair.0, pair.1) {
|
||||
(Literal(seq), Ident(ident)) => {
|
||||
pairs.push(Escape{
|
||||
sequence: seq.to_string(),
|
||||
name: ident.to_string(),
|
||||
})
|
||||
},
|
||||
_ => panic!("bad escapes"),
|
||||
}
|
||||
}
|
||||
|
||||
TokenStream::new()
|
||||
}
|
Loading…
Reference in New Issue