Skip to content

Commit

Permalink
Clean and create ast_layout_type_attributes_values
Browse files Browse the repository at this point in the history
  • Loading branch information
BaseMax committed Dec 26, 2024
1 parent 49365e3 commit db1e9d3
Show file tree
Hide file tree
Showing 20 changed files with 276 additions and 162 deletions.
2 changes: 1 addition & 1 deletion config/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

این دستور فرزند است.

<h2 id="none">دستور <code>صفحه</code></h2>
<h2 id="layout">دستور <code>صفحه</code></h2>

این دستور فرزند است.

Expand Down
2 changes: 1 addition & 1 deletion config/json/layout/type.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"descriptions": "",
"examples": "",
"generate_name": "",
"id": "AST_LAYOUT_TYPE_NONE",
"id": "AST_LAYOUT_TYPE_LAYOUT",
"is_mother": false,
"text": {
"en": [
Expand Down
2 changes: 1 addition & 1 deletion config/layout/type.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ items:
- descriptions: ''
examples: ''
generate_name: ''
id: AST_LAYOUT_TYPE_NONE
id: AST_LAYOUT_TYPE_LAYOUT
is_mother: false
text:
en:
Expand Down
52 changes: 41 additions & 11 deletions config/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def prettify_layout_attribute_style_state_type(
)


def prettify_layout_type_attributes(item: Dict[str, Any], group: Dict[str, Any]) -> str:
def prettify_layout_type_attributes_values(item: Dict[str, Any], group: Dict[str, Any]) -> str:
"""
Generates a formatted string for a layout type definition.
Expand All @@ -351,24 +351,49 @@ def prettify_layout_type_attributes(item: Dict[str, Any], group: Dict[str, Any])
attributes = []

if "generate_name" in item:
result = ""
itemid = item["id"]
itemid_lower = itemid.replace("AST_LAYOUT_TYPE_", "").lower()

result = ""

result += "else if (attribute->parent_node_type == " + str(itemid) + ") {\n"
var_attrs = f"valid_attributes_{itemid_lower}"
var_attrs_length = f"valid_attributes_{itemid_lower}_length"

if len(attributes) > 0:
result += " ast_layout_attribute_type_t valid_attributes[] = {\n"
result += f"ast_layout_attribute_type_t {var_attrs}[] = " + "{\n"
for attr in attributes:
result += " " + attr + ",\n"
result += " };\n"
result += " " + attr + ",\n"
result += "};\n"
result += f"const size_t {var_attrs_length} = sizeof({var_attrs}) / sizeof({var_attrs}[0]);\n"

return result
else:
return ""

def prettify_layout_type_attributes(item: Dict[str, Any], group: Dict[str, Any]) -> str:
"""
Generates a formatted string for a layout type definition.
:param item: A dictionary representing the layout type item.
:param group: A dictionary representing the group the item belongs to.
:return: A formatted string for the layout type.
"""

attributes = item.get("attributes", [])
if attributes is None:
attributes = []

result += " const size_t valid_attributes_length = sizeof(valid_attributes) / sizeof(valid_attributes[0]);\n"
if "generate_name" in item:
itemid = item["id"]
itemid_lower = itemid.replace("AST_LAYOUT_TYPE_", "").lower()

result += " if (is_attribute_type_in_array(attribute_key_type, valid_attributes, valid_attributes_length)) {\n"
# result += " if (attribute->final_key != NULL) {\n"
# result += " memory_destroy(attribute->final_key);\n"
# result += " }\n"
result = f"if (attribute->parent_node_type == {itemid}) " + "{\n"

var_attrs = f"valid_attributes_{itemid_lower}"
var_attrs_length = f"valid_attributes_{itemid_lower}_length"

if len(attributes) > 0:
result += f" if (is_attribute_type_in_array(attribute_key_type, {var_attrs}, {var_attrs_length})) " + "{\n"
result += " return true;\n"
result += " }\n"

Expand Down Expand Up @@ -447,6 +472,11 @@ def prettify_layout_type(item: Dict[str, Any], group: Dict[str, Any]) -> str:
"output": "ast_layout_type_attributes.h",
"prettify": prettify_layout_type_attributes,
},
{
"input": "layout/type.yaml",
"output": "ast_layout_type_attributes_values.h",
"prettify": prettify_layout_type_attributes_values,
},
{
"input": "layout/attribute/type.yaml",
"output": "ast_layout_attribute_type.h",
Expand Down
2 changes: 1 addition & 1 deletion example/input.salam
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
صفحه:

جهت = «راست به چپ»
رنگ پس زمینه = «قرمز»
اندازه قلم = ۴۰
محتوا = "r"
Expand Down
2 changes: 1 addition & 1 deletion src/ast_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ ast_layout_t *ast_layout_create() {
ast_layout_t *node = memory_allocate(sizeof(ast_layout_t));

node->block =
ast_layout_block_create(AST_TYPE_LAYOUT, AST_LAYOUT_TYPE_NONE);
ast_layout_block_create(AST_TYPE_LAYOUT, AST_LAYOUT_TYPE_LAYOUT);

node->print = cast(void (*)(void *), ast_layout_print);
node->destroy = cast(void (*)(void *), ast_layout_destroy);
Expand Down
7 changes: 7 additions & 0 deletions src/generated-config/ast_block_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ ADD_BLOCK_TYPE(AST_BLOCK_TYPE_ERROR, "ERROR", "error")










6 changes: 6 additions & 0 deletions src/generated-config/ast_layout_attribute_style_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ ADD_LAYOUT_ATTRIBUTE_STYLE_GLOBAL_VALUE(unset, "حذف شده")









6 changes: 6 additions & 0 deletions src/generated-config/ast_layout_attribute_style_state_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,9 @@ ADD_LAYOUT_ATTRIBUTE_STYLE_STATE_TYPE(AST_LAYOUT_ATTRIBUTE_STYLE_STATE_TYPE_EMPT









6 changes: 6 additions & 0 deletions src/generated-config/ast_layout_attribute_style_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -573,3 +573,9 @@ ADD_LAYOUT_ATTRIBUTE_STYLE_TYPE_HIDE(AST_LAYOUT_ATTRIBUTE_STYLE_TYPE_ERROR, "ERR









6 changes: 6 additions & 0 deletions src/generated-config/ast_layout_attribute_style_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -1477,3 +1477,9 @@ const ast_layout_attribute_style_pair_t ast_layout_allowed_style_list_zoom[] = {









6 changes: 6 additions & 0 deletions src/generated-config/ast_layout_attribute_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@ ADD_LAYOUT_ATTRIBUTE_TYPE(AST_LAYOUT_ATTRIBUTE_TYPE_RESPONSIVE_MIN_HEIGHT, "RESP









6 changes: 6 additions & 0 deletions src/generated-config/ast_layout_attribute_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ const ast_layout_attribute_pair_t ast_layout_allowed_lang[] = {









9 changes: 8 additions & 1 deletion src/generated-config/ast_layout_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ADD_LAYOUT_TYPE(AST_LAYOUT_TYPE_INCLUDE, "INCLUDE", "include", "", "بارگیر

ADD_LAYOUT_TYPE(AST_LAYOUT_TYPE_ERROR, "ERROR", "error", "", "خطا", false)

ADD_LAYOUT_TYPE(AST_LAYOUT_TYPE_NONE, "NONE", "none", "", "صفحه", false)
ADD_LAYOUT_TYPE(AST_LAYOUT_TYPE_LAYOUT, "LAYOUT", "layout", "", "صفحه", false)

ADD_LAYOUT_TYPE(AST_LAYOUT_TYPE_DIV, "DIV", "div", "div", "جعبه", false)

Expand Down Expand Up @@ -131,3 +131,10 @@ ADD_LAYOUT_TYPE_REPEAT(AST_LAYOUT_TYPE_MEDIA, "MEDIA", "media", "@media", "وا










Loading

0 comments on commit db1e9d3

Please sign in to comment.