formally_support_macros/lib.rs
1//
2// ::formally - the open-source formal methods toolchain
3//
4// Copyright (c) 2025 Nicola Gigante
5//
6// Permission is hereby granted, free of charge, to any person obtaining a copy
7// of this software and associated documentation files (the "Software"), to deal
8// in the Software without restriction, including without limitation the rights
9// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10// copies of the Software, and to permit persons to whom the Software is
11// furnished to do so, subject to the following conditions:
12//
13// The above copyright notice and this permission notice shall be included in
14// all copies or substantial portions of the Software.
15//
16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22// SOFTWARE.
23//
24
25//! Procedural macros exported by the `formally::support` subcrate.
26#![doc = ""]
27#![cfg_attr(
28 not(feature = "__subcratedoc"),
29 doc = "**WARNING: This crate is not supposed to be used directly.**"
30)]
31#![doc = ""]
32#![cfg_attr(
33 not(feature = "__subcratedoc"),
34 doc = "**Use instead the `formally::support` module of the main `formally` crate.**"
35)]
36#![doc = ""]
37
38extern crate proc_macro;
39
40mod locatable;
41mod located;
42
43use proc_macro::TokenStream;
44
45/// Procedural macro to derive the `Located` trait.
46///
47/// To be able to derive `Located`, a `struct` must contain a field named `span` of type
48/// `Option<Span>`.
49///
50/// For `enum`s, only variants with no fields or with a single field are supported at the moment.
51/// In the first case, the derived `Located` implementation returns `None`, while in the second case
52/// the type contained in the variant must in turn be `Located`, so that its `span()` method is
53/// used.
54///
55/// Example:
56/// ```ignore
57/// # mod formally {
58/// # pub use formally_support as support;
59/// # }
60/// # use formally::support::*;
61/// #
62/// #[derive(Located, Locatable)]
63/// struct Identifier {
64/// name: String,
65/// span: Option<Span>
66/// }
67/// ```
68#[proc_macro_derive(Located)]
69pub fn derive_located(item: TokenStream) -> TokenStream {
70 located::derive(item)
71}
72
73/// Procedural macro to derive the `Locatable` trait.
74///
75/// To be able to derive `Locatable`, a `struct` must contain a field named `span` of type
76/// `Option<Span>`.
77///
78/// For `enum`s, only variants with no fields or with a single field are supported at the moment.
79/// In the first case, the derived `Locatable` returns the same variant as is, while in the second
80/// case the type contained in the variant must in turn be `Locatable`, so that its `over()` method
81/// is used.
82///
83/// Example:
84/// ```ignore
85/// # mod formally {
86/// # pub use formally_support as support;
87/// # }
88/// # use formally::support::*;
89/// #
90/// #[derive(Located, Locatable)]
91/// struct Identifier {
92/// name: String,
93/// span: Option<Span>
94/// }
95/// ```
96#[proc_macro_derive(Locatable)]
97pub fn derive_locatable(item: TokenStream) -> TokenStream {
98 locatable::derive(item)
99}