diff --git a/flamapy/metamodels/fm_metamodel/transformations/clafer_writer.py b/flamapy/metamodels/fm_metamodel/transformations/clafer_writer.py index ab331d1..1591980 100644 --- a/flamapy/metamodels/fm_metamodel/transformations/clafer_writer.py +++ b/flamapy/metamodels/fm_metamodel/transformations/clafer_writer.py @@ -1,4 +1,5 @@ import re +import string from enum import Enum from typing import Any, Optional @@ -152,4 +153,8 @@ def parse_type_value(value: Any) -> str: def safename(name: str) -> str: - return f'"{name}"' if ' ' in name else name + return f'"{name}"' if any(char in name for char in safecharacters()) else name + + +def safecharacters() -> str: + return string.ascii_letters + string.digits + '_' diff --git a/flamapy/metamodels/fm_metamodel/transformations/featureide_writer.py b/flamapy/metamodels/fm_metamodel/transformations/featureide_writer.py index 94dbdcd..9f9f1d2 100644 --- a/flamapy/metamodels/fm_metamodel/transformations/featureide_writer.py +++ b/flamapy/metamodels/fm_metamodel/transformations/featureide_writer.py @@ -1,3 +1,4 @@ +import string from xml.etree import ElementTree from xml.etree.ElementTree import Element from xml.dom import minidom @@ -139,4 +140,8 @@ def prettify(xml: str) -> bytes: def safename(name: str) -> str: - return f'"{name}"' if ' ' in name else name + return f'"{name}"' if any(char in name for char in safecharacters()) else name + + +def safecharacters() -> str: + return string.ascii_letters + string.digits + '_' diff --git a/flamapy/metamodels/fm_metamodel/transformations/glencoe_writer.py b/flamapy/metamodels/fm_metamodel/transformations/glencoe_writer.py index 5f7450d..247b11b 100644 --- a/flamapy/metamodels/fm_metamodel/transformations/glencoe_writer.py +++ b/flamapy/metamodels/fm_metamodel/transformations/glencoe_writer.py @@ -1,4 +1,5 @@ import json +import string from typing import Any from flamapy.core.models.ast import Node, ASTOperation @@ -106,4 +107,8 @@ def _get_ctc_info(ast_node: Node) -> dict[str, Any]: def safename(name: str) -> str: - return f'"{name}"' if ' ' in name else name + return f'"{name}"' if any(char in name for char in safecharacters()) else name + + +def safecharacters() -> str: + return string.ascii_letters + string.digits + '_' diff --git a/flamapy/metamodels/fm_metamodel/transformations/json_writer.py b/flamapy/metamodels/fm_metamodel/transformations/json_writer.py index 8e5ea5e..3392e22 100644 --- a/flamapy/metamodels/fm_metamodel/transformations/json_writer.py +++ b/flamapy/metamodels/fm_metamodel/transformations/json_writer.py @@ -1,4 +1,5 @@ import json +import string from enum import Enum from typing import Any, Dict, List @@ -126,4 +127,8 @@ def get_ctc_info(ast_node: Node) -> Dict[str, Any]: def safename(name: str) -> str: - return f'"{name}"' if ' ' in name else name \ No newline at end of file + return f'"{name}"' if any(char in name for char in safecharacters()) else name + + +def safecharacters() -> str: + return string.ascii_letters + string.digits + '_' diff --git a/flamapy/metamodels/fm_metamodel/transformations/splot_writer.py b/flamapy/metamodels/fm_metamodel/transformations/splot_writer.py index e3133d3..448f619 100644 --- a/flamapy/metamodels/fm_metamodel/transformations/splot_writer.py +++ b/flamapy/metamodels/fm_metamodel/transformations/splot_writer.py @@ -1,3 +1,5 @@ +import string + from flamapy.core.transformations import ModelToText from flamapy.metamodels.fm_metamodel.models import ( FeatureModel, @@ -83,4 +85,8 @@ def add_constraints(constraints: list[Constraint]) -> list[str]: def safename(name: str) -> str: - return f'"{name}"' if ' ' in name else name + return f'"{name}"' if any(char in name for char in safecharacters()) else name + + +def safecharacters() -> str: + return string.ascii_letters + string.digits + '_' diff --git a/flamapy/metamodels/fm_metamodel/transformations/uvl_reader.py b/flamapy/metamodels/fm_metamodel/transformations/uvl_reader.py index 51c6a06..020b985 100644 --- a/flamapy/metamodels/fm_metamodel/transformations/uvl_reader.py +++ b/flamapy/metamodels/fm_metamodel/transformations/uvl_reader.py @@ -83,7 +83,7 @@ def process_attributes( constraint_attribute = attribute_context.constraintAttribute() if value_attribute: - key = value_attribute.key().getText() + key = value_attribute.key().getText().replace('"', '') if value_attribute.value(): value = self.process_value(value_attribute.value()) else: @@ -96,7 +96,7 @@ def process_attributes( else: # Handle unexpected case raise ValueError( - f"Unknown attribute type for: {attribute_context.getText()}" + f"Unknown attribute type for: {attribute_context.getText().replace('"', '')}" ) attributes_dict[key] = value diff --git a/flamapy/metamodels/fm_metamodel/transformations/uvl_writer.py b/flamapy/metamodels/fm_metamodel/transformations/uvl_writer.py index bb586e1..18203e2 100644 --- a/flamapy/metamodels/fm_metamodel/transformations/uvl_writer.py +++ b/flamapy/metamodels/fm_metamodel/transformations/uvl_writer.py @@ -1,4 +1,5 @@ import re +import string from flamapy.core.models.ast import ASTOperation from flamapy.core.transformations import ModelToText @@ -135,4 +136,8 @@ def serialize_constraint(ctc: Constraint) -> str: def safename(name: str) -> str: - return f'"{name}"' if ' ' in name else name + return f'"{name}"' if any(char in name for char in safecharacters()) else name + + +def safecharacters() -> str: + return string.ascii_letters + string.digits + '_'