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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//use syn::parse::{Parse, ParseStream};
// trait Parse {
// fn parse(input: ParseStream) -> syn::Result<Self>;
// }
// // start = { product_entity | rust } ;
// #[cfg_attr(features = "debug_parser", derive(Debug))]
// enum Start {
// // ProductEntity(ProductEntity),
// // Rust(RustCode),
// }
//
// impl Parse for Start {
// fn parse(input: ParseStream) -> syn::Result<Self> {
// // if input.peek(syn::token::Dollar) {
// // input.parse().map(Start::ProductEntity)
// // } else {
// // input.parse().map(Start::Rust)
// // }
// todo!()
// }
// }
//
// #[test]
// fn test_start() {
// let input = quote::quote! {
// $ { }
// $ ( )
// $ [ ]
// $ rust ;
// };
// let start: Start = syn::parse2(input).unwrap();
// // match start {
// // Start::ProductEntity(_) => {}
// // Start::Rust(_) => {}
// // }
// }
// // rust = ?any_valid_rust_token? ;
// struct RustCode {
// code: Vec<Token>,
// }
//
// impl Parse for RustCode {
// fn parse(input: ParseStream) -> syn::Result<Self> {
// input.parse().map(|code| RustCode { code })
// }
// }
// // product_entity = "$" ( scope | definition | reference ) ;
// enum ProductEntity {
// Scope(Scope),
// Definition(Definition),
// Reference(Reference),
// }
//
// impl Parse for ProductEntity {
// fn parse(input: ParseStream) -> syn::Result<Self> {
// input.parse::<syn::token::Dollar>()?;
// if input.peek(syn::token::Brace) {
// input.parse().map(ProductEntity::Scope)
// } else if input.peek(syn::token::Paren) {
// input.parse().map(ProductEntity::Definition)
// } else {
// input.parse().map(ProductEntity::Reference)
// }
// }
// }
// scope = product_scope | linear_scope ;
// product_scope = "{" { product_entity | rust } "}" ;
// linear_scope = "[" { product_entity | rust } "]" ;
// definition = "(" ( table_definition | normal_definition ) ")" ;
// normal_definition = [ "$"? name ":" ] ( items | item );
// table_definition = "[" headers items "]" ;
// headers = ( name ":" )+ ;
// items = ( "(" { rust } ")" )+ ;
// item = { rust } ;
// name = ?identifier? ;
// reference = ( ?number? | ?identifier? ) ;
/*
// product_entity = "$" ( scope | definition | product_reference | rust ) ;
// the last 'rust' catches the escaped '$$' as '$'.
fn parse_product_entity(&self) -> bool {
self.parse_product_char()
&& (self.parse_scope()
|| self.parse_definition()
|| self.parse_product_reference()
|| self.parse_rust())
}
*/