data_query_lexical/
lib.rs1mod lexer;
2pub(crate) mod lexer_constants;
3
4pub use lexer::*;
5use std::collections::LinkedList;
6
7mod lexical;
8
9pub trait MacroFormat {
10 fn macro_fmt(&self) -> String;
11}
12
13impl MacroFormat for lexer::Slicer {
14 fn macro_fmt(&self) -> String {
15 match self {
16 Slicer::Index(i) => format!("::data_query_lexical::Slicer::Index({})", i),
17 Slicer::Slice(f, t) => format!("::data_query_lexical::Slicer::Slice({},{})", f, t),
18 Slicer::Ident(i) => {
19 format!("::data_query_lexical::Slicer::Ident(\"{}\".into())", i)
20 }
21 }
22 }
23}
24
25impl MacroFormat for LinkedList<lexer::LexOperator> {
26 fn macro_fmt(&self) -> String {
27 format!(
28 "::std::collections::LinkedList::from([{}])",
29 self.iter()
30 .map(|t| t.macro_fmt())
31 .collect::<Vec<String>>()
32 .join(",")
33 )
34 }
35}
36
37impl MacroFormat for lexer::LexOperator {
38 fn macro_fmt(&self) -> String {
39 match self {
40 LexOperator::Identifier(i) => {
41 format!(
42 "::data_query_lexical::LexOperator::Identifier(\"{}\".into())",
43 i
44 )
45 }
46 LexOperator::Pipe(p) => p.macro_fmt(),
47 LexOperator::Generic(g) => format!(
48 "::data_query_lexical::LexOperator::Generic({})",
49 g.macro_fmt()
50 ),
51 }
52 }
53}
54
55impl MacroFormat for lexer::GenericObjectIndex {
56 fn macro_fmt(&self) -> String {
57 match self {
58 GenericObjectIndex::Wildcard => {
59 format!("::data_query_lexical::GenericObjectIndex::Wildcard")
60 }
61 GenericObjectIndex::Slice(s) => format!(
62 "::data_query_lexical::GenericObjectIndex::Slice(::std::collections::LinkedList::from([{}]))",
63 s.iter()
64 .map(|s| s.macro_fmt())
65 .collect::<Vec<String>>()
66 .join(",")
67 ),
68 }
69 }
70}