From db1e9d30fca6080c737b953dbbc4d8407f9dde8f Mon Sep 17 00:00:00 2001 From: "ALI Mohammadiyeh (Max Base)" Date: Thu, 26 Dec 2024 08:39:29 +0100 Subject: [PATCH] Clean and create ast_layout_type_attributes_values --- config/docs.md | 2 +- config/json/layout/type.json | 2 +- config/layout/type.yaml | 2 +- config/sync.py | 52 ++++-- example/input.salam | 2 +- src/ast_layout.c | 2 +- src/generated-config/ast_block_type.h | 7 + .../ast_layout_attribute_style_global.h | 6 + .../ast_layout_attribute_style_state_type.h | 6 + .../ast_layout_attribute_style_type.h | 6 + .../ast_layout_attribute_style_value.h | 6 + .../ast_layout_attribute_type.h | 6 + .../ast_layout_attribute_value.h | 6 + src/generated-config/ast_layout_type.h | 9 +- .../ast_layout_type_attributes.h | 171 +++++++----------- .../ast_layout_type_attributes_values.h | 101 +++++++++++ src/generated-config/ast_type.h | 7 + src/generator_layout.c | 4 + src/parser_layout.c | 2 +- src/validator.c | 39 +--- 20 files changed, 276 insertions(+), 162 deletions(-) create mode 100644 src/generated-config/ast_layout_type_attributes_values.h diff --git a/config/docs.md b/config/docs.md index 34c36f49..9a3ea6d1 100644 --- a/config/docs.md +++ b/config/docs.md @@ -16,7 +16,7 @@ این دستور فرزند است. -

دستور صفحه

+

دستور صفحه

این دستور فرزند است. diff --git a/config/json/layout/type.json b/config/json/layout/type.json index 824cf2ae..a39f079f 100644 --- a/config/json/layout/type.json +++ b/config/json/layout/type.json @@ -38,7 +38,7 @@ "descriptions": "", "examples": "", "generate_name": "", - "id": "AST_LAYOUT_TYPE_NONE", + "id": "AST_LAYOUT_TYPE_LAYOUT", "is_mother": false, "text": { "en": [ diff --git a/config/layout/type.yaml b/config/layout/type.yaml index 3720fea4..f0e58951 100644 --- a/config/layout/type.yaml +++ b/config/layout/type.yaml @@ -25,7 +25,7 @@ items: - descriptions: '' examples: '' generate_name: '' - id: AST_LAYOUT_TYPE_NONE + id: AST_LAYOUT_TYPE_LAYOUT is_mother: false text: en: diff --git a/config/sync.py b/config/sync.py index 56ccd8f6..5e8cb165 100644 --- a/config/sync.py +++ b/config/sync.py @@ -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. @@ -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" @@ -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", diff --git a/example/input.salam b/example/input.salam index 0ed868fe..5c9879ef 100644 --- a/example/input.salam +++ b/example/input.salam @@ -1,5 +1,5 @@ صفحه: - + جهت = «راست به چپ» رنگ پس زمینه = «قرمز» اندازه قلم = ۴۰ محتوا = "r" diff --git a/src/ast_layout.c b/src/ast_layout.c index 2c24d0c6..623150bb 100644 --- a/src/ast_layout.c +++ b/src/ast_layout.c @@ -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); diff --git a/src/generated-config/ast_block_type.h b/src/generated-config/ast_block_type.h index 947f8644..6b3e541a 100644 --- a/src/generated-config/ast_block_type.h +++ b/src/generated-config/ast_block_type.h @@ -14,3 +14,10 @@ ADD_BLOCK_TYPE(AST_BLOCK_TYPE_ERROR, "ERROR", "error") + + + + + + + diff --git a/src/generated-config/ast_layout_attribute_style_global.h b/src/generated-config/ast_layout_attribute_style_global.h index 83250cee..816ec319 100644 --- a/src/generated-config/ast_layout_attribute_style_global.h +++ b/src/generated-config/ast_layout_attribute_style_global.h @@ -14,3 +14,9 @@ ADD_LAYOUT_ATTRIBUTE_STYLE_GLOBAL_VALUE(unset, "حذف شده") + + + + + + diff --git a/src/generated-config/ast_layout_attribute_style_state_type.h b/src/generated-config/ast_layout_attribute_style_state_type.h index f8a721bf..62c82d6e 100644 --- a/src/generated-config/ast_layout_attribute_style_state_type.h +++ b/src/generated-config/ast_layout_attribute_style_state_type.h @@ -74,3 +74,9 @@ ADD_LAYOUT_ATTRIBUTE_STYLE_STATE_TYPE(AST_LAYOUT_ATTRIBUTE_STYLE_STATE_TYPE_EMPT + + + + + + diff --git a/src/generated-config/ast_layout_attribute_style_type.h b/src/generated-config/ast_layout_attribute_style_type.h index 96d99cd5..fffef857 100644 --- a/src/generated-config/ast_layout_attribute_style_type.h +++ b/src/generated-config/ast_layout_attribute_style_type.h @@ -573,3 +573,9 @@ ADD_LAYOUT_ATTRIBUTE_STYLE_TYPE_HIDE(AST_LAYOUT_ATTRIBUTE_STYLE_TYPE_ERROR, "ERR + + + + + + diff --git a/src/generated-config/ast_layout_attribute_style_value.h b/src/generated-config/ast_layout_attribute_style_value.h index fae320ad..9cde09de 100644 --- a/src/generated-config/ast_layout_attribute_style_value.h +++ b/src/generated-config/ast_layout_attribute_style_value.h @@ -1477,3 +1477,9 @@ const ast_layout_attribute_style_pair_t ast_layout_allowed_style_list_zoom[] = { + + + + + + diff --git a/src/generated-config/ast_layout_attribute_type.h b/src/generated-config/ast_layout_attribute_type.h index b1804a08..1c05a47c 100644 --- a/src/generated-config/ast_layout_attribute_type.h +++ b/src/generated-config/ast_layout_attribute_type.h @@ -62,3 +62,9 @@ ADD_LAYOUT_ATTRIBUTE_TYPE(AST_LAYOUT_ATTRIBUTE_TYPE_RESPONSIVE_MIN_HEIGHT, "RESP + + + + + + diff --git a/src/generated-config/ast_layout_attribute_value.h b/src/generated-config/ast_layout_attribute_value.h index 80cab6c6..b05fd3c0 100644 --- a/src/generated-config/ast_layout_attribute_value.h +++ b/src/generated-config/ast_layout_attribute_value.h @@ -44,3 +44,9 @@ const ast_layout_attribute_pair_t ast_layout_allowed_lang[] = { + + + + + + diff --git a/src/generated-config/ast_layout_type.h b/src/generated-config/ast_layout_type.h index cbc25353..e4ffccfe 100644 --- a/src/generated-config/ast_layout_type.h +++ b/src/generated-config/ast_layout_type.h @@ -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) @@ -131,3 +131,10 @@ ADD_LAYOUT_TYPE_REPEAT(AST_LAYOUT_TYPE_MEDIA, "MEDIA", "media", "@media", "وا + + + + + + + diff --git a/src/generated-config/ast_layout_type_attributes.h b/src/generated-config/ast_layout_type_attributes.h index 18f8c734..1b65d91b 100644 --- a/src/generated-config/ast_layout_type_attributes.h +++ b/src/generated-config/ast_layout_type_attributes.h @@ -1,180 +1,135 @@ // ----------- BEGIN AUTO GENERATED ----------- // -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_INCLUDE) { - ast_layout_attribute_type_t valid_attributes[] = { - AST_LAYOUT_ATTRIBUTE_TYPE_SRC, - }; - const size_t valid_attributes_length = sizeof(valid_attributes) / sizeof(valid_attributes[0]); - if (is_attribute_type_in_array(attribute_key_type, valid_attributes, valid_attributes_length)) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_INCLUDE) { + if (is_attribute_type_in_array(attribute_key_type, valid_attributes_include, valid_attributes_include_length)) { return true; } } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_ERROR) { -} -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_NONE) { - ast_layout_attribute_type_t valid_attributes[] = { - AST_LAYOUT_ATTRIBUTE_TYPE_TITLE, - AST_LAYOUT_ATTRIBUTE_TYPE_LANG, - AST_LAYOUT_ATTRIBUTE_TYPE_DIR, - AST_LAYOUT_ATTRIBUTE_TYPE_AUTHOR, - AST_LAYOUT_ATTRIBUTE_TYPE_DESCRIPTION, - AST_LAYOUT_ATTRIBUTE_TYPE_KEYWORDS, - AST_LAYOUT_ATTRIBUTE_TYPE_ICON, - AST_LAYOUT_ATTRIBUTE_TYPE_CHARSET, - AST_LAYOUT_ATTRIBUTE_TYPE_REFRESH, - AST_LAYOUT_ATTRIBUTE_TYPE_VIEWPORT, - }; - const size_t valid_attributes_length = sizeof(valid_attributes) / sizeof(valid_attributes[0]); - if (is_attribute_type_in_array(attribute_key_type, valid_attributes, valid_attributes_length)) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_ERROR) { +} +if (attribute->parent_node_type == AST_LAYOUT_TYPE_LAYOUT) { + if (is_attribute_type_in_array(attribute_key_type, valid_attributes_layout, valid_attributes_layout_length)) { return true; } } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_DIV) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_DIV) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_PARAGRAPH) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_PARAGRAPH) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_BUTTON) { - ast_layout_attribute_type_t valid_attributes[] = { - AST_LAYOUT_ATTRIBUTE_TYPE_NAME, - }; - const size_t valid_attributes_length = sizeof(valid_attributes) / sizeof(valid_attributes[0]); - if (is_attribute_type_in_array(attribute_key_type, valid_attributes, valid_attributes_length)) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_BUTTON) { + if (is_attribute_type_in_array(attribute_key_type, valid_attributes_button, valid_attributes_button_length)) { return true; } } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_TEXTAREA) { - ast_layout_attribute_type_t valid_attributes[] = { - AST_LAYOUT_ATTRIBUTE_TYPE_NAME, - AST_LAYOUT_ATTRIBUTE_TYPE_CONTENT, - AST_LAYOUT_ATTRIBUTE_TYPE_PLACEHOLDER, - }; - const size_t valid_attributes_length = sizeof(valid_attributes) / sizeof(valid_attributes[0]); - if (is_attribute_type_in_array(attribute_key_type, valid_attributes, valid_attributes_length)) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_TEXTAREA) { + if (is_attribute_type_in_array(attribute_key_type, valid_attributes_textarea, valid_attributes_textarea_length)) { return true; } } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_LABEL) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_LABEL) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_SELECT) { - ast_layout_attribute_type_t valid_attributes[] = { - AST_LAYOUT_ATTRIBUTE_TYPE_NAME, - }; - const size_t valid_attributes_length = sizeof(valid_attributes) / sizeof(valid_attributes[0]); - if (is_attribute_type_in_array(attribute_key_type, valid_attributes, valid_attributes_length)) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_SELECT) { + if (is_attribute_type_in_array(attribute_key_type, valid_attributes_select, valid_attributes_select_length)) { return true; } } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_FIELDSET) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_FIELDSET) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_LEGEND) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_LEGEND) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_FORM) { - ast_layout_attribute_type_t valid_attributes[] = { - AST_LAYOUT_ATTRIBUTE_TYPE_SRC, - AST_LAYOUT_ATTRIBUTE_TYPE_TYPE, - AST_LAYOUT_ATTRIBUTE_TYPE_KIND, - }; - const size_t valid_attributes_length = sizeof(valid_attributes) / sizeof(valid_attributes[0]); - if (is_attribute_type_in_array(attribute_key_type, valid_attributes, valid_attributes_length)) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_FORM) { + if (is_attribute_type_in_array(attribute_key_type, valid_attributes_form, valid_attributes_form_length)) { return true; } } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_OPTGROUP) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_OPTGROUP) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_DATALIST) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_DATALIST) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_SPAN) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_SPAN) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_STRONG) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_STRONG) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_EM) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_EM) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_ITALIC) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_ITALIC) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_BOLD) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_BOLD) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_UNDERLINE) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_UNDERLINE) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_SUB) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_SUB) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_SUP) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_SUP) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_S) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_S) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_HEADER) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_HEADER) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_FOOTER) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_FOOTER) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_NAV) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_NAV) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_SECTION) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_SECTION) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_ARTICLE) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_ARTICLE) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_ASIDE) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_ASIDE) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_MAIN) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_MAIN) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_FIGURE) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_FIGURE) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_FIGCAPTION) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_FIGCAPTION) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_VIDEO) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_VIDEO) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_AUDIO) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_AUDIO) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_IFRAME) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_IFRAME) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_CANVAS) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_CANVAS) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_UL) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_UL) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_LINK) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_LINK) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_OL) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_OL) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_OPTION) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_OPTION) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_LI) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_LI) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_TABLE) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_TABLE) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_TABLE_HEADER) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_TABLE_HEADER) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_TABLE_FOOTER) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_TABLE_FOOTER) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_TABLE_TR) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_TABLE_TR) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_TABLE_TD) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_TABLE_TD) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_TABLE_TH) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_TABLE_TH) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_CAPTION) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_CAPTION) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_COL) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_COL) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_BR) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_BR) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_HR) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_HR) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_INPUT) { - ast_layout_attribute_type_t valid_attributes[] = { - AST_LAYOUT_ATTRIBUTE_TYPE_VALUE, - AST_LAYOUT_ATTRIBUTE_TYPE_NAME, - AST_LAYOUT_ATTRIBUTE_TYPE_PLACEHOLDER, - }; - const size_t valid_attributes_length = sizeof(valid_attributes) / sizeof(valid_attributes[0]); - if (is_attribute_type_in_array(attribute_key_type, valid_attributes, valid_attributes_length)) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_INPUT) { + if (is_attribute_type_in_array(attribute_key_type, valid_attributes_input, valid_attributes_input_length)) { return true; } } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_IMG) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_IMG) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_FONT) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_FONT) { } -else if (attribute->parent_node_type == AST_LAYOUT_TYPE_MEDIA) { +if (attribute->parent_node_type == AST_LAYOUT_TYPE_MEDIA) { } // ----------- END AUTO GENERATED ----------- // - - diff --git a/src/generated-config/ast_layout_type_attributes_values.h b/src/generated-config/ast_layout_type_attributes_values.h new file mode 100644 index 00000000..121d2e43 --- /dev/null +++ b/src/generated-config/ast_layout_type_attributes_values.h @@ -0,0 +1,101 @@ +// ----------- BEGIN AUTO GENERATED ----------- // +ast_layout_attribute_type_t valid_attributes_include[] = { + AST_LAYOUT_ATTRIBUTE_TYPE_SRC, +}; +const size_t valid_attributes_include_length = sizeof(valid_attributes_include) / sizeof(valid_attributes_include[0]); + + +ast_layout_attribute_type_t valid_attributes_layout[] = { + AST_LAYOUT_ATTRIBUTE_TYPE_TITLE, + AST_LAYOUT_ATTRIBUTE_TYPE_LANG, + AST_LAYOUT_ATTRIBUTE_TYPE_DIR, + AST_LAYOUT_ATTRIBUTE_TYPE_AUTHOR, + AST_LAYOUT_ATTRIBUTE_TYPE_DESCRIPTION, + AST_LAYOUT_ATTRIBUTE_TYPE_KEYWORDS, + AST_LAYOUT_ATTRIBUTE_TYPE_ICON, + AST_LAYOUT_ATTRIBUTE_TYPE_CHARSET, + AST_LAYOUT_ATTRIBUTE_TYPE_REFRESH, + AST_LAYOUT_ATTRIBUTE_TYPE_VIEWPORT, +}; +const size_t valid_attributes_layout_length = sizeof(valid_attributes_layout) / sizeof(valid_attributes_layout[0]); + + + +ast_layout_attribute_type_t valid_attributes_button[] = { + AST_LAYOUT_ATTRIBUTE_TYPE_NAME, +}; +const size_t valid_attributes_button_length = sizeof(valid_attributes_button) / sizeof(valid_attributes_button[0]); + +ast_layout_attribute_type_t valid_attributes_textarea[] = { + AST_LAYOUT_ATTRIBUTE_TYPE_NAME, + AST_LAYOUT_ATTRIBUTE_TYPE_CONTENT, + AST_LAYOUT_ATTRIBUTE_TYPE_PLACEHOLDER, +}; +const size_t valid_attributes_textarea_length = sizeof(valid_attributes_textarea) / sizeof(valid_attributes_textarea[0]); + + +ast_layout_attribute_type_t valid_attributes_select[] = { + AST_LAYOUT_ATTRIBUTE_TYPE_NAME, +}; +const size_t valid_attributes_select_length = sizeof(valid_attributes_select) / sizeof(valid_attributes_select[0]); + + + +ast_layout_attribute_type_t valid_attributes_form[] = { + AST_LAYOUT_ATTRIBUTE_TYPE_SRC, + AST_LAYOUT_ATTRIBUTE_TYPE_TYPE, + AST_LAYOUT_ATTRIBUTE_TYPE_KIND, +}; +const size_t valid_attributes_form_length = sizeof(valid_attributes_form) / sizeof(valid_attributes_form[0]); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +ast_layout_attribute_type_t valid_attributes_input[] = { + AST_LAYOUT_ATTRIBUTE_TYPE_VALUE, + AST_LAYOUT_ATTRIBUTE_TYPE_NAME, + AST_LAYOUT_ATTRIBUTE_TYPE_PLACEHOLDER, +}; +const size_t valid_attributes_input_length = sizeof(valid_attributes_input) / sizeof(valid_attributes_input[0]); + + + + +// ----------- END AUTO GENERATED ----------- // + diff --git a/src/generated-config/ast_type.h b/src/generated-config/ast_type.h index d8edc6ff..17779eb3 100644 --- a/src/generated-config/ast_type.h +++ b/src/generated-config/ast_type.h @@ -22,3 +22,10 @@ ADD_TYPE(AST_TYPE_ERROR, "ERROR", "error") + + + + + + + diff --git a/src/generator_layout.c b/src/generator_layout.c index c36fef0f..02eb774f 100644 --- a/src/generator_layout.c +++ b/src/generator_layout.c @@ -668,6 +668,10 @@ void generator_code_layout_html(ast_layout_block_t *layout_block, memory_destroy(values); } } + + printf("DIR--->%s\n", html_dir_value); + printf("LANG--->%s\n", html_lang_value); + if (html_dir_value == NULL || strcmp(html_dir_value, "") == 0) { string_append_str(html, "rtl"); } else if (strcmp(html_dir_value, "ltr") == 0) { diff --git a/src/parser_layout.c b/src/parser_layout.c index 60132b20..886da923 100644 --- a/src/parser_layout.c +++ b/src/parser_layout.c @@ -191,7 +191,7 @@ void parser_parse_layout_block_children(ast_layout_block_t *block, } if (node->type == AST_LAYOUT_TYPE_FONT) { - if (block->parent_node_type != AST_LAYOUT_TYPE_NONE) { + if (block->parent_node_type != AST_LAYOUT_TYPE_LAYOUT) { error_parser(2, "Font node is not allowed in the '%s' block at " "line %d, column %d", diff --git a/src/validator.c b/src/validator.c index 8304bb5e..7fda8c0a 100644 --- a/src/validator.c +++ b/src/validator.c @@ -25,38 +25,7 @@ #include "validator_style.h" -// #include "generated-config/ast_layout_attribute_value.h" -// #include "generated-config/ast_layout_attribute_style_value.h" - -extern const ast_layout_attribute_style_pair_t - ast_layout_allowed_style_list_font_display[]; -extern const ast_layout_attribute_style_pair_t - ast_layout_allowed_style_list_font_style[]; -extern const ast_layout_attribute_style_pair_t - ast_layout_allowed_style_list_font_weight[]; - -/** - * - * @var valid_layout_attributes - * @brief Valid layout attributes - * @type {ast_layout_attribute_type_t[]} - */ -ast_layout_attribute_type_t valid_layout_attributes[] = { - AST_LAYOUT_ATTRIBUTE_TYPE_TITLE, AST_LAYOUT_ATTRIBUTE_TYPE_DESCRIPTION, - AST_LAYOUT_ATTRIBUTE_TYPE_AUTHOR, AST_LAYOUT_ATTRIBUTE_TYPE_KEYWORDS, - AST_LAYOUT_ATTRIBUTE_TYPE_ICON, AST_LAYOUT_ATTRIBUTE_TYPE_CHARSET, - AST_LAYOUT_ATTRIBUTE_TYPE_DIR, AST_LAYOUT_ATTRIBUTE_TYPE_LANG, - AST_LAYOUT_ATTRIBUTE_TYPE_VIEWPORT, AST_LAYOUT_ATTRIBUTE_TYPE_REFRESH, -}; - -/** - * - * @var valid_layout_attributes_length - * @brief Valid layout attributes length - * @type {size_t} - */ -size_t valid_layout_attributes_length = - sizeof(valid_layout_attributes) / sizeof(valid_layout_attributes[0]); +#include "generated-config/ast_layout_type_attributes_values.h" /** * @@ -142,8 +111,8 @@ void validate_layout_mainbody(ast_layout_block_t *block) { ast_layout_attribute_t *attribute_value = entry->value; if (is_attribute_type_in_array( - attribute_key_type, valid_layout_attributes, - valid_layout_attributes_length)) { + attribute_key_type, valid_attributes_layout, + valid_attributes_layout_length)) { attribute_value->ignoreMe = true; } @@ -190,8 +159,6 @@ bool token_belongs_to_ast_layout_node( return true; } - if (false) { - } #include "generated-config/ast_layout_type_attributes.h" if (attribute_key_type == AST_LAYOUT_ATTRIBUTE_TYPE_CONTENT) {