hyperactor_mesh_macros/
lib.rs

1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8
9// Clippy can't see through quote! to use of proc-macro2
10#![allow(unused_crate_dependencies)]
11
12extern crate proc_macro;
13
14use proc_macro::TokenStream;
15use quote::quote;
16
17/// Parse a compact selection expression into a [`Selection`]. See
18/// [`selection::parse`] for syntax documentation.
19#[proc_macro]
20pub fn sel(input: TokenStream) -> TokenStream {
21    match ndslice::selection::token_parser::parse_tokens(input.into()) {
22        Ok(selection) => {
23            let tokens = ndslice::selection::token_parser::selection_to_tokens(&selection);
24            quote!(#tokens).into()
25        }
26        Err(e) => {
27            let msg = format!("sel! parse failed: {}", e);
28            quote!(compile_error!(#msg)).into()
29        }
30    }
31}