esp-bool-parser Package
Tools for processing boolean statements based on ESP-IDF SOC capabilities and configurations.
Main Package Module
Tools for building ESP-IDF related apps.
- class esp_bool_parser.BoolStmt(t: ParseResults)
Bases:
Stmt
- get_value(target: str, config_name: str) Any
Lazy calculated. All subclasses of Stmt should implement this function.
- Parameters:
target – ESP-IDF target
config_name – config name
- Returns:
the value of the statement
- esp_bool_parser.parse_bool_expr(stmt: str) BoolStmt
Parse a boolean expression.
- Parameters:
stmt – A string containing the boolean expression.
- Returns:
A
BoolStmt
object representing the parsed expression.
Note
You can use this function to parse a boolean expression and evaluate its value based on the given context. For example:
stmt_string = 'IDF_TARGET == "esp32"' stmt: BoolStmt = parse_bool_expr(stmt_string) value = stmt.get_value("esp32", "config_name") print(value) # Output: True
- esp_bool_parser.register_addition_attribute(attr: str, action: Callable[[...], Any]) None
Register an additional attribute for ChipAttr.
- Parameters:
attr – The name of the additional attribute (string).
action – A callable that processes
**kwargs
. Thetarget
andconfig_name
parameters will be passed as kwargs when the attribute is detected.
Boolean Expression Parser
- class esp_bool_parser.bool_parser.Stmt
Bases:
object
Statement
- get_value(target: str, config_name: str) Any
Lazy calculated. All subclasses of Stmt should implement this function.
- Parameters:
target – ESP-IDF target
config_name – config name
- Returns:
the value of the statement
- class esp_bool_parser.bool_parser.ChipAttr(t: ParseResults)
Bases:
Stmt
Attributes defined in SOC Header Files and other keywords as followed:
IDF_TARGET: target
INCLUDE_DEFAULT: take the default build targets into account or not
IDF_VERSION_MAJOR: major version of ESP-IDF
IDF_VERSION_MINOR: minor version of ESP-IDF
IDF_VERSION_PATCH: patch version of ESP-IDF
CONFIG_NAME: config name defined in the config rules
- addition_attr: ClassVar[Dict[str, Callable]] = {}
- get_value(target: str, config_name: str) Any
Lazy calculated. All subclasses of Stmt should implement this function.
- Parameters:
target – ESP-IDF target
config_name – config name
- Returns:
the value of the statement
- class esp_bool_parser.bool_parser.Integer(t: ParseResults)
Bases:
Stmt
- get_value(target: str, config_name: str) Any
Lazy calculated. All subclasses of Stmt should implement this function.
- Parameters:
target – ESP-IDF target
config_name – config name
- Returns:
the value of the statement
- class esp_bool_parser.bool_parser.String(t: ParseResults)
Bases:
Stmt
- get_value(target: str, config_name: str) Any
Lazy calculated. All subclasses of Stmt should implement this function.
- Parameters:
target – ESP-IDF target
config_name – config name
- Returns:
the value of the statement
- class esp_bool_parser.bool_parser.List_(t: ParseResults)
Bases:
Stmt
- get_value(target: str, config_name: str) Any
Lazy calculated. All subclasses of Stmt should implement this function.
- Parameters:
target – ESP-IDF target
config_name – config name
- Returns:
the value of the statement
- class esp_bool_parser.bool_parser.BoolStmt(t: ParseResults)
Bases:
Stmt
- get_value(target: str, config_name: str) Any
Lazy calculated. All subclasses of Stmt should implement this function.
- Parameters:
target – ESP-IDF target
config_name – config name
- Returns:
the value of the statement
- class esp_bool_parser.bool_parser.BoolOr(res: ParseResults)
Bases:
BoolExpr
- get_value(target: str, config_name: str) Any
Lazy calculated. All subclasses of Stmt should implement this function.
- Parameters:
target – ESP-IDF target
config_name – config name
- Returns:
the value of the statement
- class esp_bool_parser.bool_parser.BoolAnd(res: ParseResults)
Bases:
BoolExpr
- get_value(target: str, config_name: str) Any
Lazy calculated. All subclasses of Stmt should implement this function.
- Parameters:
target – ESP-IDF target
config_name – config name
- Returns:
the value of the statement
- esp_bool_parser.bool_parser.register_addition_attribute(attr: str, action: Callable[[...], Any]) None
Register an additional attribute for ChipAttr.
- Parameters:
attr – The name of the additional attribute (string).
action – A callable that processes
**kwargs
. Thetarget
andconfig_name
parameters will be passed as kwargs when the attribute is detected.
- esp_bool_parser.bool_parser.parse_bool_expr(stmt: str) BoolStmt
Parse a boolean expression.
- Parameters:
stmt – A string containing the boolean expression.
- Returns:
A
BoolStmt
object representing the parsed expression.
Note
You can use this function to parse a boolean expression and evaluate its value based on the given context. For example:
stmt_string = 'IDF_TARGET == "esp32"' stmt: BoolStmt = parse_bool_expr(stmt_string) value = stmt.get_value("esp32", "config_name") print(value) # Output: True
Constants and IDF Information
SOC Header Parser
- esp_bool_parser.soc_header.get_defines(header_path: str) List[str]
- esp_bool_parser.soc_header.parse_define(define_line: str) ParseResults
Utility Functions
- esp_bool_parser.utils.lazy_load(base_module: ModuleType, name_obj_dict: Dict[str, Any], obj_module_dict: Dict[str, str]) Callable[[str], Any]
Use
__getattr__
in the__init__.py
file to lazy load some objects.- Parameters:
base_module – Base package module.
name_obj_dict – Dictionary mapping object names to real objects. Used to store real objects; no need to add lazy-load objects.
obj_module_dict – Dictionary mapping object names to module names.
- Returns:
The
__getattr__
function.
Note
Example usage in
__init__.py
:__getattr__ = lazy_load( importlib.import_module(__name__), { "IdfApp": IdfApp, "LinuxDut": LinuxDut, "LinuxSerial": LinuxSerial, "CaseTester": CaseTester, }, { "IdfSerial": ".serial", "IdfDut": ".dut", }, )
- exception esp_bool_parser.utils.InvalidInput
Bases:
SystemExit
Invalid input from user
- exception esp_bool_parser.utils.InvalidIfClause
Bases:
SystemExit
Invalid if clause in manifest file
- esp_bool_parser.utils.to_version(s: Any) Version