hexput_ast_api/
feature_flags.rs

1use serde::Serialize;
2
3
4#[derive(Debug, Clone, Copy, Serialize)]
5pub struct FeatureFlags {
6    pub allow_variable_declaration: bool,
7    pub allow_conditionals: bool,
8    pub allow_loops: bool,
9    pub allow_callbacks: bool,
10    pub allow_return_statements: bool,
11    pub allow_loop_control: bool,
12    pub allow_assignments: bool,
13    pub allow_object_navigation: bool,
14    pub allow_array_constructions: bool,
15    pub allow_object_constructions: bool,
16    pub allow_object_keys: bool,
17}
18
19impl Default for FeatureFlags {
20    fn default() -> Self {
21        
22        Self {
23            allow_variable_declaration: true,
24            allow_conditionals: true,
25            allow_loops: true,
26            allow_callbacks: true,
27            allow_return_statements: true,
28            allow_loop_control: true,
29            allow_assignments: true,          
30            allow_object_navigation: true,    
31            allow_array_constructions: true,
32            allow_object_constructions: true,
33            allow_object_keys: true,
34        }
35    }
36}
37
38impl FeatureFlags {
39    pub fn all_enabled() -> Self {
40        Self::default()
41    }
42    
43    
44    pub fn all_disabled() -> Self {
45        Self {
46            allow_variable_declaration: false,
47            allow_conditionals: false,
48            allow_loops: false,
49            allow_callbacks: false,
50            allow_return_statements: false,
51            allow_loop_control: false,
52            allow_assignments: false,
53            allow_object_navigation: false,
54            allow_array_constructions: false,
55            allow_object_constructions: false,
56            allow_object_keys: false,
57        }
58    }
59    
60    
61    pub fn expressions_only() -> Self {
62        let mut flags = Self::all_disabled();
63        flags.allow_assignments = true;
64        flags.allow_object_navigation = true;
65        flags
66    }
67
68}