#ast #proc-macro #lustre #syntax #analysis #static-analysis #syn

nightly chandeliers-syn

Syntax of the Lustre language, to be parsed by procedural macros

21 releases (1 stable)

1.0.0 Jan 5, 2024
0.6.1 Jan 4, 2024
0.5.2 Dec 29, 2023
0.5.0 Nov 24, 2023
0.2.6 Oct 27, 2023

#523 in Procedural macros

Download history 6/week @ 2023-12-24 24/week @ 2023-12-31 1/week @ 2024-01-07 7/week @ 2024-02-18 13/week @ 2024-02-25 90/week @ 2024-03-31

90 downloads per month
Used in chandeliers-lus

MIT/Apache

410KB
8K SLoC

Chandeliers-Syn

Syntax of Lustre.


In this crate we describe the parsing AST of Lustre programs. This AST is not meant to be used directly, instead it should be translated into one that is more convenient for static analysis.

How to obtain a parsing AST and what to do with it

All types of the module ast implement syn::parse::Parse, so they can be parsed from any stream of tokens that conforms to the structure expected by syn.

The typical usage inside a proc macro would be like:

use chandeliers_syn::ast::Prog;
use proc_macro::TokenStream;

#[proc_macro]
pub fn get_and_handle_ast(input: TokenStream) -> TokenStream {
    let prog: Prog = syn::parse_macro_input!(input as Prog);
    // now you have a `Prog`, you can e.g.
    // `Prog::translate` it to get something that can be used by
    // Chandeliers' sanitizer.
}

lib.rs:

Common entry point for the proc macros of the Chandeliers suite, provides parsing for all Lustre constructs and translation to the analysable AST of chandeliers-san

The structure of the AST is not stable because the grammar of the parseable fragment of Lustre could very well be extended later.

Dependencies

~0.5–1MB
~21K SLoC