flux_syntax/
symbols.rs

1use flux_macros::symbols;
2use rustc_span::{Symbol, edition::Edition};
3
4symbols! {
5    Keywords {
6        Bitvec: "bitvec",
7        Exists: "exists",
8        Forall: "forall",
9        Hrn: "hrn",
10        Hdl: "hdl",
11        Requires: "requires",
12        Ensures: "ensures",
13        Property: "property",
14        Qualifier: "qualifier",
15        Sort: "sort",
16        Strg: "strg",
17        Trusted: "trusted",
18        Reft: "reft",
19        Invariant: "invariant",
20        RefinedBy: "refined_by",
21    }
22
23    Symbols {
24        Map,
25        Set,
26        int,
27        no_panic,
28        no_panic_if,
29        ptr_size,
30        real,
31    }
32}
33
34/// All Rust keywords plus extra Flux keywords.
35pub mod kw {
36    #![allow(non_upper_case_globals)]
37
38    use rustc_span::Symbol;
39    pub use rustc_span::symbol::kw::*;
40
41    pub use super::kw_generated::*;
42
43    // Predefined symbols in rustc that are not Rust keywords but are Flux keywords.
44    // Update this in tandem with `is_flux_reserved`
45    pub const Opaque: Symbol = rustc_span::symbol::sym::opaque;
46    pub const Local: Symbol = rustc_span::symbol::sym::local;
47}
48
49pub mod sym {
50    pub use rustc_span::sym::*;
51
52    pub use super::sym_generated::*;
53}
54
55pub fn is_reserved(sym: Symbol, edition: Edition) -> bool {
56    // FIXME: We should treat these as reserved and adjust the parser to be consistent with Rust.
57    if sym == kw::SelfLower || sym == kw::SelfUpper || sym == kw::Crate || sym == kw::Super {
58        return false;
59    }
60    sym.is_reserved(|| edition) || is_flux_reserved(sym)
61}
62
63// Update in tandem with predefined non-keyword symbols in `kw`
64fn is_flux_reserved(sym: Symbol) -> bool {
65    (kw::Bitvec <= sym && sym <= kw::Strg) || sym == kw::Opaque || sym == kw::Local
66}