feat: major grammar upgrade for SCL spec conformance (Phase 1)
Comprehensive grammar rewrite to conform to SCL specs. Improves parse success rate from 0% to 90% (187 of 208 reference project files). Case-insensitive keywords: - Add ci() helper for case-insensitive token matching - All keywords (TYPE, STRUCT, VAR, IF, etc.) now match any case - All type names (BOOL, Int, Dint, etc.) now match any case New grammar constructs: - RETURN statement - GOTO statement - AUTHOR/FAMILY/NAME block headers - VAR DB_SPECIFIC section - ARRAY[*] (variable-length arrays) - Multidimensional ARRAY[a..b, c..d] - REF_TO <type> - VARIANT type - Anonymous STRUCT...END_STRUCT as a type - Compound assignment operators (+=, -=, *=, /=, &=, |=, ^=) - Chained assignments (lvalue := lvalue := expression) - Bit access (lvalue.%X0) - Method calls (lvalue.field(...)) - Struct/array initializers ((TRUE, FALSE, ...), (name := value)) - END_STRUCT; (semicolon after END_STRUCT in UDTs) - Typed DB associated block name (DATA_BLOCK "Name" : "UDT") - BOM (Byte Order Mark) handling - TITLE as single-token statement (avoids keyword/identifier conflict) New type_builtin aliases: - LWORD, LINT, ULINT, UDINT, DATE, TIME_OF_DAY, DATE_AND_TIME - S5TIME, LTIME, DTL, LTOD, LDT, LTIME_OF_DAY, DATE_AND_LTIME New literal formats: - Binary (2#...), Octal (8#...) - BOOL#TRUE/FALSE - Typed integers (INT#, SINT#, DINT#, etc.) - Date/time literals (DATE#, TOD#, DT#, LTIME#, S5TIME#, DTL#) - WSTRING# and STRING# typed string literals - C# char literal - Time units with case-insensitive matching (T#1S, T#2s) Updated constructs: - CASE labels: comma-separated lists, string labels - Function call parameters: interleaved input (:=) and output (=>) params - FOR loop variable: accepts prefixed_identifier (#tempVar) - Array bounds: accept string/identifier constants (Array[0.."MAX"]) - Author/Family values: accept unquoted text with hyphens/slashes Known remaining issues (21 files, 10%): - Triple-nested parentheses in expressions - Some multi-line function call parameter patterns - END_REGION with trailing region name - Complex chained field access in assignments
This commit is contained in:
+2757
-1168
File diff suppressed because it is too large
Load Diff
+476
-18
@@ -18,6 +18,37 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "array_type",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "keyword",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "number",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "type",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "assignment",
|
||||
"named": true,
|
||||
@@ -36,6 +67,10 @@
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "chained_assignment",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
@@ -120,6 +155,25 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "bit_access",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "lvalue",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "number",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "case_item",
|
||||
"named": true,
|
||||
@@ -147,6 +201,10 @@
|
||||
{
|
||||
"type": "statement",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -178,6 +236,34 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "chained_assignment",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "chained_assignment",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "lvalue",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "char_literal",
|
||||
"named": true,
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "continue_statement",
|
||||
"named": true,
|
||||
@@ -197,6 +283,16 @@
|
||||
"type": "data_block",
|
||||
"named": true,
|
||||
"fields": {
|
||||
"associated": {
|
||||
"multiple": false,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "string",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"name": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
@@ -221,7 +317,7 @@
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"type": "author_value",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
@@ -240,6 +336,14 @@
|
||||
"type": "string",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "title_statement",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "var_db_specific_declaration",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "var_declaration",
|
||||
"named": true
|
||||
@@ -325,6 +429,26 @@
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_number",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "bit_access",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "bool_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "char_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "date_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
@@ -349,6 +473,10 @@
|
||||
"type": "number",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "octal_number",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "prefixed_identifier",
|
||||
"named": true
|
||||
@@ -361,9 +489,17 @@
|
||||
"type": "time_value",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "typed_int_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "wstring_literal",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -482,6 +618,10 @@
|
||||
"type": "keyword",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "prefixed_identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "statement",
|
||||
"named": true
|
||||
@@ -513,11 +653,11 @@
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "block_comment",
|
||||
"type": "author_value",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"type": "block_comment",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
@@ -536,6 +676,10 @@
|
||||
"type": "string",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "title_statement",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "type",
|
||||
"named": true
|
||||
@@ -587,7 +731,11 @@
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"type": "author_value",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "block_comment",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
@@ -606,9 +754,33 @@
|
||||
"type": "string",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "title_statement",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "var_constant_declaration",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "var_db_specific_declaration",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "var_declaration",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "var_non_retain_declaration",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "var_retain_declaration",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "var_temp_declaration",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -625,6 +797,10 @@
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "method_callee",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "parameter_list",
|
||||
"named": true
|
||||
@@ -651,6 +827,25 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "goto_statement",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "keyword",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "if_statement",
|
||||
"named": true,
|
||||
@@ -694,6 +889,10 @@
|
||||
"type": "array_access",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "bit_access",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "field_access",
|
||||
"named": true
|
||||
@@ -713,6 +912,25 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "method_callee",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "lvalue",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "organization_block",
|
||||
"named": true,
|
||||
@@ -737,7 +955,7 @@
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"type": "author_value",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
@@ -756,6 +974,10 @@
|
||||
"type": "string",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "title_statement",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "var_declaration",
|
||||
"named": true
|
||||
@@ -766,9 +988,20 @@
|
||||
{
|
||||
"type": "parameter",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"fields": {
|
||||
"name": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
@@ -832,19 +1065,19 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "region_name",
|
||||
"type": "ref_type",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "identifier",
|
||||
"type": "keyword",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"type": "type",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
@@ -896,6 +1129,21 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "return_statement",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "keyword",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "source_file",
|
||||
"named": true,
|
||||
@@ -905,6 +1153,10 @@
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "bom",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "data_block",
|
||||
"named": true
|
||||
@@ -972,6 +1224,10 @@
|
||||
"type": "function_call",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "goto_statement",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "if_statement",
|
||||
"named": true
|
||||
@@ -984,10 +1240,18 @@
|
||||
"type": "repeat_statement",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "return_statement",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "var_constant_declaration",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "var_db_specific_declaration",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "var_declaration",
|
||||
"named": true
|
||||
@@ -1017,7 +1281,7 @@
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "type",
|
||||
"type": "string_type",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
@@ -1025,7 +1289,56 @@
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "identifier",
|
||||
"type": "number",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "type_builtin",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "struct_initializer",
|
||||
"named": true,
|
||||
"fields": {
|
||||
"name": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "struct_initializer",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "struct_type",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "block_comment",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
@@ -1033,7 +1346,30 @@
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "number",
|
||||
"type": "var_item",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "type",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "array_type",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "ref_type",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
@@ -1041,9 +1377,28 @@
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "type",
|
||||
"type": "string_type",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "struct_type",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "type_builtin",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "type_builtin",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "type_builtin",
|
||||
"named": true
|
||||
@@ -1079,11 +1434,11 @@
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "block_comment",
|
||||
"type": "author_value",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"type": "block_comment",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
@@ -1098,6 +1453,10 @@
|
||||
"type": "string",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "title_statement",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "var_item",
|
||||
"named": true
|
||||
@@ -1147,6 +1506,29 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "var_db_specific_declaration",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "block_comment",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "keyword",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "var_item",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "var_declaration",
|
||||
"named": true,
|
||||
@@ -1206,6 +1588,10 @@
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "struct_initializer",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1310,6 +1696,14 @@
|
||||
"type": "\"\"",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "%",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "&=",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "'",
|
||||
"named": false
|
||||
@@ -1330,10 +1724,18 @@
|
||||
"type": "*",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "*=",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "+",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "+=",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ",",
|
||||
"named": false
|
||||
@@ -1342,6 +1744,10 @@
|
||||
"type": "-",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "-=",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ".",
|
||||
"named": false
|
||||
@@ -1354,6 +1760,10 @@
|
||||
"type": "/",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "/=",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ":",
|
||||
"named": false
|
||||
@@ -1394,6 +1804,10 @@
|
||||
"type": ">=",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "C#",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "[",
|
||||
"named": false
|
||||
@@ -1402,11 +1816,31 @@
|
||||
"type": "]",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "^=",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "author_value",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_number",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "block_comment",
|
||||
"named": true,
|
||||
"extra": true
|
||||
},
|
||||
{
|
||||
"type": "bom",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "bool_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "c_style_comment",
|
||||
"named": true,
|
||||
@@ -1416,6 +1850,10 @@
|
||||
"type": "constant",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "date_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "hex_number",
|
||||
"named": true
|
||||
@@ -1437,6 +1875,10 @@
|
||||
"type": "number",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "octal_number",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "operator",
|
||||
"named": true
|
||||
@@ -1445,18 +1887,34 @@
|
||||
"type": "prefix",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "region_name",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "time_value",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "type_builtin",
|
||||
"type": "title_statement",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "typed_int_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "wstring_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "{",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "|=",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "}",
|
||||
"named": false
|
||||
|
||||
+102187
-74102
File diff suppressed because it is too large
Load Diff
+20
-37
@@ -60,7 +60,13 @@ extern "C" {
|
||||
|
||||
/// Free any memory allocated for this array. Note that this does not free any
|
||||
/// memory allocated for the array's contents.
|
||||
#define array_delete(self) _array__delete((self), (void *)(self)->contents, sizeof(*self))
|
||||
#define array_delete(self) \
|
||||
do { \
|
||||
if ((self)->contents) ts_free((self)->contents); \
|
||||
(self)->contents = NULL; \
|
||||
(self)->size = 0; \
|
||||
(self)->capacity = 0; \
|
||||
} while (0)
|
||||
|
||||
/// Push a new `element` onto the end of the array.
|
||||
#define array_push(self, element) \
|
||||
@@ -130,12 +136,11 @@ extern "C" {
|
||||
/// Swap one array with another
|
||||
#define array_swap(self, other) \
|
||||
do { \
|
||||
struct Swap swapped_contents = _array__swap( \
|
||||
(void *)(self)->contents, &(self)->size, &(self)->capacity, \
|
||||
(void *)(other)->contents, &(other)->size, &(other)->capacity \
|
||||
); \
|
||||
(self)->contents = swapped_contents.self_contents; \
|
||||
(other)->contents = swapped_contents.other_contents; \
|
||||
void *_array_swap_tmp = (void *)(self)->contents; \
|
||||
(self)->contents = (other)->contents; \
|
||||
(other)->contents = _array_swap_tmp; \
|
||||
_array__swap(&(self)->size, &(self)->capacity, \
|
||||
&(other)->size, &(other)->capacity); \
|
||||
} while (0)
|
||||
|
||||
/// Get the size of the array contents
|
||||
@@ -188,12 +193,6 @@ extern "C" {
|
||||
// The `Array` type itself was not altered as a solution in order to avoid breakage
|
||||
// with existing consumers (in particular, parsers with external scanners).
|
||||
|
||||
/// This is not what you're looking for, see `array_delete`.
|
||||
static inline void _array__delete(void *self, void *contents, size_t self_size) {
|
||||
if (contents) ts_free(contents);
|
||||
if (self) memset(self, 0, self_size);
|
||||
}
|
||||
|
||||
/// This is not what you're looking for, see `array_erase`.
|
||||
static inline void _array__erase(void* self_contents, uint32_t *size,
|
||||
size_t element_size, uint32_t index) {
|
||||
@@ -228,31 +227,15 @@ static inline void *_array__assign(void* self_contents, uint32_t *self_size, uin
|
||||
return new_contents;
|
||||
}
|
||||
|
||||
struct Swap {
|
||||
void *self_contents;
|
||||
void *other_contents;
|
||||
};
|
||||
|
||||
/// This is not what you're looking for, see `array_swap`.
|
||||
// static inline void _array__swap(Array *self, Array *other) {
|
||||
static inline struct Swap _array__swap(void *self_contents, uint32_t *self_size, uint32_t *self_capacity,
|
||||
void *other_contents, uint32_t *other_size, uint32_t *other_capacity) {
|
||||
void *new_self_contents = other_contents;
|
||||
uint32_t new_self_size = *other_size;
|
||||
uint32_t new_self_capacity = *other_capacity;
|
||||
|
||||
void *new_other_contents = self_contents;
|
||||
*other_size = *self_size;
|
||||
*other_capacity = *self_capacity;
|
||||
|
||||
*self_size = new_self_size;
|
||||
*self_capacity = new_self_capacity;
|
||||
|
||||
struct Swap out = {
|
||||
.self_contents = new_self_contents,
|
||||
.other_contents = new_other_contents,
|
||||
};
|
||||
return out;
|
||||
static inline void _array__swap(uint32_t *self_size, uint32_t *self_capacity,
|
||||
uint32_t *other_size, uint32_t *other_capacity) {
|
||||
uint32_t tmp_size = *self_size;
|
||||
uint32_t tmp_capacity = *self_capacity;
|
||||
*self_size = *other_size;
|
||||
*self_capacity = *other_capacity;
|
||||
*other_size = tmp_size;
|
||||
*other_capacity = tmp_capacity;
|
||||
}
|
||||
|
||||
/// This is not what you're looking for, see `array_push` or `array_grow_by`.
|
||||
|
||||
Reference in New Issue
Block a user