From 81d6e21a002b5a2b628485c777d0e7c743cfafd3 Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Thu, 25 Sep 2025 08:09:27 +1000 Subject: [PATCH] Deprecate *list syntax, use &direct refs instead --- docs/syntax.md | 16 +++---- src/main.cpp | 115 ++++++++++++++++++++++------------------------- tests/lists.grnd | 2 +- 3 files changed, 59 insertions(+), 74 deletions(-) diff --git a/docs/syntax.md b/docs/syntax.md index 62b66f0..f4f817a 100644 --- a/docs/syntax.md +++ b/docs/syntax.md @@ -44,12 +44,6 @@ and jump to that (setting labels will be discussed below): jump %myLabel ``` -Reference a list (a list reference) with an asterisk: - -``` - setlist *myList $value1 $value2 # and so on -``` - Add comments with a `#`: ``` @@ -128,31 +122,31 @@ Note: You can also replace &var1 with a list or line reference to check if it al Allows you to initialize a list. -Usage: `setlist *list $value1 $value2 $value3...` +Usage: `setlist &list $value1 $value2 $value3...` #### setlistat Sets a list item at an index. The item at the index must already exist. Lists are index 0. -Usage: `setlistat *list $intvalue $value` +Usage: `setlistat &list $intvalue $value` #### getlistat Gets a list item at an index, and puts it in the variable provided. The item at the index must already exist. Lists are index 0. -Usage: `getlistat *list $intvalue &var` +Usage: `getlistat &list $intvalue &var` #### getlistsize Gets the size of a list and puts it in the variable provided. -Usage: `getlistsize *list &var` +Usage: `getlistsize &list &var` #### listappend Appends an item to a list. -Usage: `listappend *list $var` +Usage: `listappend &list $var` ### String Operations diff --git a/src/main.cpp b/src/main.cpp index add124a..6e58de9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -833,12 +833,8 @@ Literal exec(vector in, bool executingFunction) { else if (holds_alternative(get(l.args[0]).val)) { cout << get(get(l.args[0]).val); } - else { - return error("Couldn't print that", "printError"); - } - } else if (holds_alternative(l.args[0])) { - if (variables.find(get(l.args[0]).listName) != variables.end()) { - List list = get(variables[get(l.args[0]).listName].val); + else if (holds_alternative(get(l.args[0]).val)) { + List list = get(get(l.args[0]).val); cout << "["; for (int l = 0; l < list.val.size(); l++) { if (holds_alternative(list.val[l].val)) { @@ -867,9 +863,10 @@ Literal exec(vector in, bool executingFunction) { cout << ", "; } } - cout << "]"; - } else { - return error("Couldn't find list named " + get(l.args[0]).listName); + cout << "]" << endl; + } + else { + return error("Couldn't print that", "printError"); } } else { return error("Argument of stdlnout must be a value (literal or a value reference)"); @@ -904,12 +901,8 @@ Literal exec(vector in, bool executingFunction) { else if (holds_alternative(get(l.args[0]).val)) { cout << get(get(l.args[0]).val) << endl; } - else { - return error("Couldn't print that", "printError"); - } - } else if (holds_alternative(l.args[0])) { - if (variables.find(get(l.args[0]).listName) != variables.end()) { - List list = get(variables[get(l.args[0]).listName].val); + else if (holds_alternative(get(l.args[0]).val)) { + List list = get(get(l.args[0]).val); cout << "["; for (int l = 0; l < list.val.size(); l++) { if (holds_alternative(list.val[l].val)) { @@ -939,8 +932,9 @@ Literal exec(vector in, bool executingFunction) { } } cout << "]" << endl; - } else { - return error("Couldn't find list named " + get(l.args[0]).listName); + } + else { + return error("Couldn't print that", "printError"); } } else { return error("Argument of stdlnout must be a value (literal or a value reference) or a list reference"); @@ -1096,8 +1090,8 @@ Literal exec(vector in, bool executingFunction) { string listName; List listContents; - if (holds_alternative(l.args[0])) { - listName = get(l.args[0]).listName; + if (holds_alternative(l.args[0])) { + listName = get(l.args[0]).varName; } else { return error("First argument of setlist must be a list reference"); } @@ -1126,12 +1120,12 @@ Literal exec(vector in, bool executingFunction) { return error("Could not find all arguments required for Getlistat inbuilt"); } { - ListRef listref; + string listref; int ref; Direct var; - if (holds_alternative(l.args[0])) { - listref = get(l.args[0]); + if (holds_alternative(l.args[0])) { + listref = get(l.args[0]).varName; } else { return error("First argument of getlistat must be a list reference"); } @@ -1152,19 +1146,19 @@ Literal exec(vector in, bool executingFunction) { return error("Third argument of getlistat must be a direct reference"); } - if (variables.find(listref.listName) != variables.end()) { - if (holds_alternative(variables[listref.listName].val)) { - if (get(variables[listref.listName].val).val.size() > ref) { + if (variables.find(listref) != variables.end()) { + if (holds_alternative(variables[listref].val)) { + if (get(variables[listref].val).val.size() > ref) { bool existed = variables.count(var.varName) > 0; - setVal(var.varName, get(variables[listref.listName].val).val[ref]); + setVal(var.varName, get(variables[listref].val).val[ref]); } else { - return error("Index " + to_string(ref) + " out of range of list " + listref.listName, "rangeError"); + return error("Index " + to_string(ref) + " out of range of list " + listref, "rangeError"); } } else { - return error("Found a normal variable in place of a list"); + return error("Variable " + listref + " is not a list"); } } else { - return error("Unknown list: " + listref.listName); + return error("Unknown list: " + listref); } } break; @@ -1227,12 +1221,12 @@ Literal exec(vector in, bool executingFunction) { return error("Could not find all arguments required for Setlistat inbuilt"); } { - ListRef listref; + string listref; int ref; Literal value; - if (holds_alternative(l.args[0])) { - listref = get(l.args[0]); + if (holds_alternative(l.args[0])) { + listref = get(l.args[0]).varName; } else { return error("First argument of setlistat must be a list reference"); } @@ -1252,20 +1246,22 @@ Literal exec(vector in, bool executingFunction) { } else { return error("Third argument of setlistat must be a direct reference"); } - if (variables.find(listref.listName) != variables.end()) { - if (holds_alternative(variables[listref.listName].val)) { - if (get(variables[listref.listName].val).val.size() > ref) { - List tmpList = get(variables[listref.listName].val); + if (variables.find(listref) != variables.end()) { + if (holds_alternative(variables[listref].val)) { + if (get(variables[listref].val).val.size() > ref) { + List tmpList = get(variables[listref].val); tmpList.val[ref] = value; Literal tmpLit; tmpLit.val = tmpList; - setVal(listref.listName, tmpLit); + setVal(listref, tmpLit); } else { - return error("Index " + to_string(ref) + " out of range of list " + listref.listName, "rangeError"); + return error("Index " + to_string(ref) + " out of range of list " + listref, "rangeError"); } + } else { + return error("Variable " + listref + " is not a list"); } } else { - return error("Unknown list: " + listref.listName); + return error("Unknown list: " + listref); } } break; @@ -1278,11 +1274,11 @@ Literal exec(vector in, bool executingFunction) { return error("Could not find all arguments required for Listappend inbuilt"); } { - ListRef listref; + string listref; Literal value; - if (holds_alternative(l.args[0])) { - listref = get(l.args[0]); + if (holds_alternative(l.args[0])) { + listref = get(l.args[0]).varName; } else { return error("First argument of listappend must be a list reference"); } @@ -1293,17 +1289,17 @@ Literal exec(vector in, bool executingFunction) { return error("Second argument of listappend must be a direct reference"); } - if (variables.find(listref.listName) != variables.end()) { - if (!holds_alternative(variables[listref.listName].val)) { - return error("Variable " + listref.listName + "is not a list"); + if (variables.find(listref) != variables.end()) { + if (!holds_alternative(variables[listref].val)) { + return error("Variable " + listref + "is not a list"); } - List tmpList = get(variables[listref.listName].val); + List tmpList = get(variables[listref].val); tmpList.val.push_back(value); Literal tmpLit; tmpLit.val = tmpList; - setVal(listref.listName, tmpLit); + setVal(listref, tmpLit); } else { - return error("Unknown list: " + listref.listName); + return error("Unknown list: " + listref); } } break; @@ -1316,11 +1312,11 @@ Literal exec(vector in, bool executingFunction) { return error("Could not find all arguments required for Getlistsize inbuilt"); } { - ListRef ref; + string ref; Direct var; - if (holds_alternative(l.args[0])) { - ref = get(l.args[0]); + if (holds_alternative(l.args[0])) { + ref = get(l.args[0]).varName; } else { return error("First argument of getlistsize must be a list reference"); } @@ -1332,12 +1328,12 @@ Literal exec(vector in, bool executingFunction) { } Literal newLit; - if (variables.find(ref.listName) != variables.end()) { - newLit.val = int(get(variables[ref.listName].val).val.size()); + if (variables.find(ref) != variables.end()) { + newLit.val = int(get(variables[ref].val).val.size()); bool existed = variables.count(var.varName) > 0; setVal(var.varName, newLit); } else { - return error("Couldn't find the list " + ref.listName); + return error("Couldn't find the list " + ref); } break; @@ -2125,10 +2121,6 @@ Literal exec(vector in, bool executingFunction) { if (variables.find(get(l.args[0]).varName) != variables.end()) { exists = true; } - } else if (holds_alternative(l.args[0])) { - if (variables.find(get(l.args[0]).listName) != variables.end() && holds_alternative(variables[get(l.args[0]).listName].val)) { - exists = true; - } } else if (holds_alternative(l.args[0])) { Line line = get(l.args[0]); if (line.isLabel) { @@ -2236,8 +2228,6 @@ Literal exec(vector in, bool executingFunction) { } if (holds_alternative(l.args[0])) { return get(l.args[0]); - } else if (holds_alternative(l.args[0])) { - return variables[get(l.args[0]).listName]; } else { return error("First argument of return must be a literal value/value reference"); } @@ -2861,8 +2851,9 @@ vector parser(vector> in) { break; case Types::ListRef: { - ListRef newLR; - newLR.listName = i.substr(1); + cout << "Note: List References are no longer supported and will be removed in future. Please reference lists using a direct reference (&) instead. Converting to a Direct reference." << endl; + Direct newLR; + newLR.varName = i.substr(1); newInst.args.push_back(newLR); } break; diff --git a/tests/lists.grnd b/tests/lists.grnd index 9f11630..7c6ac21 100644 --- a/tests/lists.grnd +++ b/tests/lists.grnd @@ -1,6 +1,6 @@ # A cool list setlist *favWords "hello" "there" "general" "kenobi" -stdlnout *favWords +stdlnout $favWords set &count 0 set &passedThrough true