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
101
102
103
104
105
106
107
108
//! # Appy - Declarative UI Framework for Native Application
//!
//! This crate contains macros for [Appy](https://github.com/limikael/appy).
//!
//! It is published as a separate crate  due to technical reasons. See
//! this [stack overflow thread](https://stackoverflow.com/questions/56713877/why-do-proc-macros-have-to-be-defined-in-proc-macro-crate).
//!
//! If it is not the case any more that it needs to be separate, please let me know!
use proc_macro::{*};

/*#[proc_macro_derive(Props)]
pub fn derive_props(input: TokenStream) -> TokenStream {
	let ast=parse_macro_input!(input as DeriveInput);
	let name=ast.ident;

	TokenStream::from(quote!{
		impl Props for #name {}
	})
}*/

mod main_window;
#[proc_macro_attribute]
/// Application entry point.
///
/// The main window macro defines the main application entry point.
/// It should be placed on a function that returns Elements. In this
/// sense, it is similar to a [macro@function_component], but it
/// does not take any properties or children.
///
/// # Example
/// ```rust
/// use appy::*;
///
/// #[main_window]
/// pub fn app()->Elements {
///    apx!{
///        <bg col=0x800000/>
///        <text text="Hello World".to_string() align=Align::Center/>
///    }
/// }
/// ```
pub fn main_window(attr: TokenStream, input: TokenStream) -> TokenStream {
	main_window::main_window(attr,input)
}

mod function_component;
/// Create a function component.
///
/// A function component takes input in the form of props and children,
/// and return elements describing what should appear on the screen.
///
/// # Example
/// ```rust
/// pub struct FuncProps {
///   param1: i32,
///   param2: i32
/// }
///
/// #[function_component]
/// pub fn a_func(p:FuncProps, c:Elements)->Elements {
///   apx! {
///     <bg col=0x000000/>
///   }
/// }
/// ```
///
/// The function component declared above can be used together with the
/// apx macro:
/// ```rust
/// apx!{
///   <a_func param1=123 param2=456/>
///	}
/// ```
#[proc_macro_attribute]
pub fn function_component(attr: TokenStream, input: TokenStream) -> TokenStream {
	function_component::function_component(attr,input)
}

mod apx;
/// Process element fragment.
///
/// This macro takes XML, and produces an element fragment represented as
/// Elements. The node names in the XML refers to a [macro@function_component].
/// The attributes refers to the members to the function's props struct.
/// For example, the following APX snippet:
///
/// ```rust
/// apx!{
///   <a_func param1=123 param2=456/>
///	}
/// ```
///
/// Is intended to be used with a function component declared as:
///
/// ```rust
/// pub struct FuncProps {
///   param1: i32,
///   param2: i32
/// }
///
/// #[function_component]
/// pub fn a_func(p:FuncProps, c:Elements)->Elements {
///   // ...
///}
#[proc_macro]
pub fn apx(input: TokenStream) -> TokenStream {
	apx::apx(input)
}