ligen_python_parser/parser/
config.rs1use ligen::parser::{ParserConfigSet, ParserConfigGet, ParserConfig};
2
3use crate::prelude::*;
4
5#[derive(Shrinkwrap, Clone)]
6#[shrinkwrap(mutable)]
7pub struct PythonParserConfig<T> {
8 pub config: T
9}
10
11impl<T> From<T> for PythonParserConfig<T> {
12 fn from(config: T) -> Self {
13 Self { config }
14 }
15}
16
17impl Default for PythonParserConfig<ParserConfig> {
18 fn default() -> Self {
19 let config = Default::default();
20 let mut config = Self { config };
21 config.set_class_variables_as_properties(false);
22 config
23 }
24}
25
26impl From<PythonParserConfig<ParserConfig>> for ParserConfig {
27 fn from(config: PythonParserConfig<ParserConfig>) -> Self {
28 config.config
29 }
30}
31
32impl PythonParserConfig<ParserConfig> {
33 pub fn new() -> PythonParserConfig<ParserConfig> {
34 Default::default()
35 }
36}
37
38impl<T> PythonParserConfig<T> {
39 pub fn set_class_variables_as_properties(&mut self, value: bool)
40 where T: ParserConfigSet
41 {
42 self.config.set("ligen::python::class_variables_as_properties", value);
43 }
44
45 pub fn get_class_variables_as_properties(&self) -> bool
46 where T: ParserConfigGet
47 {
48 self.config
49 .get("ligen::python::class_variables_as_properties")
50 .and_then(|literal| literal.as_boolean())
51 .cloned()
52 .unwrap_or(false)
53 }
54}