From 939f0c6f51f0a2414ad5912e21aa6ac058d5af7d Mon Sep 17 00:00:00 2001 From: Udayshankar Ravikumar Date: Mon, 20 Mar 2023 22:28:37 +0530 Subject: [PATCH 1/4] ezrSquared prerelease-1.4.0.0.0 --- Changelog.txt | 41 +---- Classes/Nodes.cs | 6 +- Classes/Values.cs | 35 ++-- Constants.cs | 4 +- Libraries/Random.cs | 52 ------ Libraries/{ => io}/IO.cs | 12 +- Libraries/io/io.csproj | 19 +++ Libraries/{ => std}/STD.cs | 46 +++++- Libraries/std/std.csproj | 20 +++ docs/index.markdown | 41 +---- ezr.cs | 328 ++++++++++++++++++------------------- ezrSquared.csproj | 17 ++ ezrSquared.sln | 18 ++ 13 files changed, 321 insertions(+), 318 deletions(-) delete mode 100644 Libraries/Random.cs rename Libraries/{ => io}/IO.cs (99%) create mode 100644 Libraries/io/io.csproj rename Libraries/{ => std}/STD.cs (73%) create mode 100644 Libraries/std/std.csproj diff --git a/Changelog.txt b/Changelog.txt index f0928ac..631888e 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,38 +1,7 @@ CHANGELOG - What's new? -* prerelease-1.3.3.0.1 - [17-03-23] - * Fixed bug: Objects now update internalContext when updating main context - -* prerelease-1.3.3.0.0 - [05-03-23] - * New `console` module for IO library - * New `simple_show` builtin function - * Fixed predefined function execution - * Better error messages - * Added changes for Linux version of builtin function `clear` - -* prerelease-1.3.2.0.0 - [15-02-23] - * New runtimeRunError error class! - -* prerelease-1.3.1.0.0 - [14-02-23] - * Fixed a count loop error message - * Better error message for else if statements - -* prerelease-1.3.0.0.3 - [12-02-23] - * Better `undefined` error message for special functions - -* prerelease-1.3.0.0.2 - [11-02-23] - * Fixed object definition QuickSyntax - -* prerelease-1.3.0.0.1 - [07-02-23] - * Fixed `in` expression - * character_list `remove` operation now returns the removed character - -* prerelease-1.3.0.0.0 - [03-02-23] - * ezr² now searches for name of DLL file as the main class in CSAELs - * Error tags now correspond to their errors - * New error tag `length-error` - * Error tag `overflow` now `overflow-error` - * New global variable for error tag `overflow` - * Global variables `err_illop` and `err_undef` are now `err_illegalop` and `err_undefined` - * Functions `insert`, `remove` in character_list now support string / character_list values of length > 1 - * Other new errors - check the commits \ No newline at end of file +* prerelease-1.4.0.0.0 - [20-03-23] + * Overhaul of module/library system, including `include` expression + * Merged STD and Random libraries + * Error tags in `error` statements are now expressions + * Added character_list support for some built-in string functions \ No newline at end of file diff --git a/Classes/Nodes.cs b/Classes/Nodes.cs index 3a559ab..1f8fa5e 100644 --- a/Classes/Nodes.cs +++ b/Classes/Nodes.cs @@ -234,12 +234,12 @@ public callNode(node nodeToCall, node[] argNodes, position startPos, position en public class includeNode : node { - public token nameToken; + public node fileNode; public token? nicknameToken; - public includeNode(token nameToken, token? nicknameToken, position startPos, position endPos) : base(startPos, endPos) + public includeNode(node fileNode, token? nicknameToken, position startPos, position endPos) : base(startPos, endPos) { - this.nameToken = nameToken; + this.fileNode = fileNode; this.nicknameToken = nicknameToken; } } diff --git a/Classes/Values.cs b/Classes/Values.cs index 817cdf4..3771747 100644 --- a/Classes/Values.cs +++ b/Classes/Values.cs @@ -1002,9 +1002,10 @@ private runtimeResult stringInsert(context context, position[] positions) if (start is not integer) return result.failure(new runtimeError(positions[0], positions[1], RT_TYPE, "Index must be an integer", context)); - else if (substring is not @string) - return result.failure(new runtimeError(positions[0], positions[1], RT_TYPE, "Substring must be a string", context)); + else if (substring is not @string && substring is not character_list) + return result.failure(new runtimeError(positions[0], positions[1], RT_TYPE, "Substring must be a string or character_list", context)); + string subString = (substring is @string) ? ((@string)substring).storedValue : string.Join("", ((character_list)substring).storedValue); int startAsInt = ((integer)start).storedValue; if (startAsInt < 0) @@ -1012,7 +1013,7 @@ private runtimeResult stringInsert(context context, position[] positions) else if (startAsInt > storedValue.ToString().Length) return result.failure(new runtimeError(positions[0], positions[1], RT_INDEX, "Index cannot be greater than length of string", context)); - return result.success(new @string(storedValue.ToString().Insert(startAsInt, ((@string)substring).storedValue.ToString()))); + return result.success(new @string(storedValue.ToString().Insert(startAsInt, subString))); } private runtimeResult stringReplace(context context, position[] positions) @@ -1021,11 +1022,14 @@ private runtimeResult stringReplace(context context, position[] positions) item old = context.symbolTable.get("old"); item new_ = context.symbolTable.get("new"); - if (old is not @string) - return result.failure(new runtimeError(positions[0], positions[1], RT_TYPE, "Old must be a string", context)); - if (new_ is not @string) - return result.failure(new runtimeError(positions[0], positions[1], RT_TYPE, "New must be a string", context)); - return result.success(new @string(storedValue.ToString().Replace(((@string)old).storedValue.ToString(), ((@string)new_).storedValue.ToString()))); + if (old is not @string && old is not character_list) + return result.failure(new runtimeError(positions[0], positions[1], RT_TYPE, "Old must be a string or character_list", context)); + if (new_ is not @string && new_ is not character_list) + return result.failure(new runtimeError(positions[0], positions[1], RT_TYPE, "New must be a string or character_list", context)); + string oldString = (old is @string) ? ((@string)old).storedValue : string.Join("", ((character_list)old).storedValue); + string newString = (new_ is @string) ? ((@string)new_).storedValue : string.Join("", ((character_list)new_).storedValue); + + return result.success(new @string(storedValue.ToString().Replace(oldString, newString))); } private runtimeResult stringSplit(context context, position[] positions) @@ -1033,9 +1037,11 @@ private runtimeResult stringSplit(context context, position[] positions) runtimeResult result = new runtimeResult(); item substring = context.symbolTable.get("substring"); - if (substring is not @string) - return result.failure(new runtimeError(positions[0], positions[1], RT_TYPE, "Substring must be a string", context)); - string[] split = storedValue.ToString().Split(((@string)substring).storedValue.ToString()); + if (substring is not @string && substring is not character_list) + return result.failure(new runtimeError(positions[0], positions[1], RT_TYPE, "Substring must be a string or character_list", context)); + + string subString = (substring is @string) ? ((@string)substring).storedValue : string.Join("", ((character_list)substring).storedValue); + string[] split = storedValue.ToString().Split(subString); item[] elements = new item[split.Length]; for (int i = 0; i < split.Length; i++) @@ -1058,7 +1064,12 @@ private runtimeResult stringJoin(context context, position[] positions) string[] arrayAsString = new string[items.Length]; for (int i = 0; i < items.Length; i++) - arrayAsString[i] = items[i].ToString(); + { + if (items[i] is @string || items[i] is character_list) + arrayAsString[i] = (items[i] is @string) ? ((@string)items[i]).storedValue : string.Join("", ((character_list)items[i]).storedValue); + else + arrayAsString[i] = items[i].ToString(); + } return result.success(new @string(string.Join(storedValue.ToString(), arrayAsString))); } diff --git a/Constants.cs b/Constants.cs index 1c5cd85..638b320 100644 --- a/Constants.cs +++ b/Constants.cs @@ -4,8 +4,8 @@ namespace ezrSquared.Constants { public static class constants { - public const string VERSION = "prerelease-1.3.3.0.1"; - public const string VERSION_DATE = "17.03.2023"; + public const string VERSION = "prerelease-1.4.0.0.0"; + public const string VERSION_DATE = "20.03.2023"; public static readonly string[] KEYWORDS = { "item", "and", "or", "invert", "if", "else", "do", "count", "from", "as", "to", "step", "while", "function", "special", "with", "end", "return", "skip", "stop", "try", "error", "in", "object", "global", "include" }; public static readonly string[] QEYWORDS = { "f", "l", "e", "c", "t", "n", "w", "fd", "sd", "od", "i", "s", "d", "g", "v" }; diff --git a/Libraries/Random.cs b/Libraries/Random.cs deleted file mode 100644 index 87009e0..0000000 --- a/Libraries/Random.cs +++ /dev/null @@ -1,52 +0,0 @@ -using ezrSquared.Values; -using ezrSquared.Helpers; -using ezrSquared.Errors; -using ezrSquared.General; -using static ezrSquared.Constants.constants; - -namespace ezrSquared.Libraries.Random -{ - public class random : baseFunction - { - public override bool UPDATEONACCESS => true; - - private System.Random random_; - public random() : base(">") - { random_ = new System.Random(); } - - public override runtimeResult execute(item[] args) - { - context internalContext = base.generateContext(); - internalContext.symbolTable.set("get", new predefined_function("random_get", randomNumber, new string[0])); - internalContext.symbolTable.set("get_limited", new predefined_function("random_get_limited", randomNumberLimited, new string[2] { "minimum", "maximum" })); - internalContext.symbolTable.set("get_float", new predefined_function("random_get_float", randomNumberFloat, new string[0])); - - return new runtimeResult().success(new @object(name, internalContext).setPosition(startPos, endPos).setContext(context)); - } - - private runtimeResult randomNumber(context context, position[] positions) { return new runtimeResult().success(new integer(random_.Next())); } - - private runtimeResult randomNumberLimited(context context, position[] positions) - { - runtimeResult result = new runtimeResult(); - item minimum = context.symbolTable.get("minimum"); - item maximum = context.symbolTable.get("maximum"); - - if (minimum is not integer && minimum is not @float) - return result.failure(new runtimeError(positions[0], positions[1], RT_TYPE, "Minimum must be an integer or float", context)); - if (maximum is not integer && maximum is not @float) - return result.failure(new runtimeError(positions[0], positions[1], RT_TYPE, "Maximum must be an integer or float", context)); - - int min = (minimum is integer) ? ((integer)minimum).storedValue : (int)((@float)minimum).storedValue; - int max = (maximum is integer) ? ((integer)maximum).storedValue : (int)((@float)maximum).storedValue; - return result.success(new integer(random_.Next(min, max))); - } - - private runtimeResult randomNumberFloat(context context, position[] positions) { return new runtimeResult().success(new @float(random_.NextSingle())); } - - public override item copy() { return new random().setPosition(startPos, endPos).setContext(context); } - - public override string ToString() { return $""; } - public override bool ItemEquals(item obj, out error? error) { error = null; return obj is random; } - } -} diff --git a/Libraries/IO.cs b/Libraries/io/IO.cs similarity index 99% rename from Libraries/IO.cs rename to Libraries/io/IO.cs index e6684ca..e265d60 100644 --- a/Libraries/IO.cs +++ b/Libraries/io/IO.cs @@ -352,7 +352,7 @@ public class console : baseFunction public override runtimeResult execute(item[] args) { context internalContext = base.generateContext(); - internalContext.symbolTable.set("is_key_pressed", new predefined_function("console_is_key_pressed", keyPressed, new string[4] { "key", "shift_pressed", "control_pressed", "alt_pressed" })); + internalContext.symbolTable.set("is_key_pressed", new predefined_function("console_is_key_pressed", keyPressed, new string[4] { "key", "shift_pressed", "control_pressed", "alt_pressed" })); internalContext.symbolTable.set("current_key_pressed", new predefined_function("console_current_key_pressed", anyKeyPressed, new string[0])); internalContext.symbolTable.set("is_numberlocked", new predefined_function("console_is_numberlocked", numberLocked, new string[0])); internalContext.symbolTable.set("is_capslocked", new predefined_function("console_is_capslocked", capsLocked, new string[0])); @@ -363,15 +363,18 @@ public override runtimeResult execute(item[] args) internalContext.symbolTable.set("reset_colors", new predefined_function("console_reset_colors", consoleResetColors, new string[0])); internalContext.symbolTable.set("get_cursor_position", new predefined_function("console_get_cursor_position", getCursorPosition, new string[0])); internalContext.symbolTable.set("set_cursor_position", new predefined_function("console_set_cursor_position", setCursorPosition, new string[1] { "position" })); +#if WINDOWS internalContext.symbolTable.set("get_cursor_size", new predefined_function("console_get_cursor_size", getCursorSize, new string[0])); internalContext.symbolTable.set("set_cursor_size", new predefined_function("console_set_cursor_size", setCursorSize, new string[1] { "size" })); internalContext.symbolTable.set("get_cursor_visibility", new predefined_function("console_get_cursor_visibility", getCursorVisibility, new string[0])); internalContext.symbolTable.set("set_cursor_visibility", new predefined_function("console_set_cursor_visibility", setCursorVisibility, new string[1] { "visibility" })); +#endif internalContext.symbolTable.set("exit", new predefined_function("console_exit", stopApplication, new string[0])); return new runtimeResult().success(new @object(name, internalContext).setPosition(startPos, endPos).setContext(context)); } +#if WINDOWS private runtimeResult getCursorVisibility(context context, position[] positions) { return new runtimeResult().success(new boolean(Console.CursorVisible)); @@ -409,6 +412,7 @@ private runtimeResult setCursorSize(context context, position[] positions) Console.CursorSize = sizeValue; return result.success(new nothing()); } +#endif private runtimeResult getCursorPosition(context context, position[] positions) { @@ -527,8 +531,8 @@ private runtimeResult keyPressed(context context, position[] positions) ConsoleKeyInfo keyPress = Console.ReadKey(true); bool shiftPress = (((value)shift).storedValue) ? (keyPress.Modifiers & ConsoleModifiers.Shift) != 0 : true; - bool controlPress = (((value)control).storedValue) ? (keyPress.Modifiers & ConsoleModifiers.Control) != 0 : true; - bool altPress = (((value)alt).storedValue) ? (keyPress.Modifiers & ConsoleModifiers.Alt) != 0 : true; + bool controlPress = (((value)control).storedValue) ? (keyPress.Modifiers & ConsoleModifiers.Control) != 0 : true; + bool altPress = (((value)alt).storedValue) ? (keyPress.Modifiers & ConsoleModifiers.Alt) != 0 : true; return result.success(new boolean(keyPress.Key == stringToKeyLookup[keyCode] && shiftPress && controlPress && altPress)); } @@ -891,7 +895,7 @@ private runtimeResult subFolders(context context, position[] positions) subDirectoriesAsString[i] = new @string(subDirectories[i]).setPosition(positions[0], positions[1]).setContext(context); return result.success(new array(subDirectoriesAsString)); } - + private runtimeResult filesInFolder(context context, position[] positions) { runtimeResult result = new runtimeResult(); diff --git a/Libraries/io/io.csproj b/Libraries/io/io.csproj new file mode 100644 index 0000000..b05a190 --- /dev/null +++ b/Libraries/io/io.csproj @@ -0,0 +1,19 @@ + + + + net7.0 + disable + enable + + + + + ..\..\bin\Release\net7.0\win-x86\ezrSquared.dll + + + + + false + false + + diff --git a/Libraries/STD.cs b/Libraries/std/STD.cs similarity index 73% rename from Libraries/STD.cs rename to Libraries/std/STD.cs index fe891e4..3924491 100644 --- a/Libraries/STD.cs +++ b/Libraries/std/STD.cs @@ -47,7 +47,7 @@ public override runtimeResult execute(item[] args) internalContext.symbolTable.set("pi", new @float(MathF.PI)); internalContext.symbolTable.set("tau", new @float(MathF.Tau)); internalContext.symbolTable.set("e", new @float(MathF.E)); - + return new runtimeResult().success(new @object(name, internalContext).setPosition(startPos, endPos).setContext(context)); } @@ -139,4 +139,48 @@ private runtimeResult concatenate(context context, position[] positions) public override string ToString() { return $""; } public override bool ItemEquals(item obj, out error? error) { error = null; return obj is character_list_class; } } + + public class random : baseFunction + { + public override bool UPDATEONACCESS => true; + + private Random random_; + public random() : base(">") + { random_ = new Random(); } + + public override runtimeResult execute(item[] args) + { + context internalContext = base.generateContext(); + internalContext.symbolTable.set("get", new predefined_function("random_get", randomNumber, new string[0])); + internalContext.symbolTable.set("get_limited", new predefined_function("random_get_limited", randomNumberLimited, new string[2] { "minimum", "maximum" })); + internalContext.symbolTable.set("get_float", new predefined_function("random_get_float", randomNumberFloat, new string[0])); + + return new runtimeResult().success(new @object(name, internalContext).setPosition(startPos, endPos).setContext(context)); + } + + private runtimeResult randomNumber(context context, position[] positions) { return new runtimeResult().success(new integer(random_.Next())); } + + private runtimeResult randomNumberLimited(context context, position[] positions) + { + runtimeResult result = new runtimeResult(); + item minimum = context.symbolTable.get("minimum"); + item maximum = context.symbolTable.get("maximum"); + + if (minimum is not integer && minimum is not @float) + return result.failure(new runtimeError(positions[0], positions[1], RT_TYPE, "Minimum must be an integer or float", context)); + if (maximum is not integer && maximum is not @float) + return result.failure(new runtimeError(positions[0], positions[1], RT_TYPE, "Maximum must be an integer or float", context)); + + int min = (minimum is integer) ? ((integer)minimum).storedValue : (int)((@float)minimum).storedValue; + int max = (maximum is integer) ? ((integer)maximum).storedValue : (int)((@float)maximum).storedValue; + return result.success(new integer(random_.Next(min, max))); + } + + private runtimeResult randomNumberFloat(context context, position[] positions) { return new runtimeResult().success(new @float(random_.NextSingle())); } + + public override item copy() { return new random().setPosition(startPos, endPos).setContext(context); } + + public override string ToString() { return $""; } + public override bool ItemEquals(item obj, out error? error) { error = null; return obj is random; } + } } diff --git a/Libraries/std/std.csproj b/Libraries/std/std.csproj new file mode 100644 index 0000000..73d8b54 --- /dev/null +++ b/Libraries/std/std.csproj @@ -0,0 +1,20 @@ + + + + net7.0 + disable + enable + + + + + ..\..\bin\Release\net7.0\win-x86\ezrSquared.dll + + + + + false + false + + + diff --git a/docs/index.markdown b/docs/index.markdown index 37070b1..02a0dd1 100644 --- a/docs/index.markdown +++ b/docs/index.markdown @@ -97,42 +97,11 @@ Meanwhile, check out some example programs in [***GitHub***](https://github.com/ ## Latest Updates **For those confused by the versioning: 1st place -> Major; 2nd place -> Feature; 3rd place -> Quality of Life; 4th place -> Library; 5th place -> Patch**. I plan to switch to [***Semantic Versioning 2.0.0***](https://semver.org/) for the first stable release. -* **prerelease-1.3.3.0.1** - [17-03-23] - * Fixed bug: Objects now update internalContext when updating main context - -* **prerelease-1.3.3.0.0** - [05-03-23] - * New `console` module for IO library - * New `simple_show` builtin function - * Fixed predefined function execution - * Better error messages - * Added changes for Linux version of builtin function `clear` - -* **prerelease-1.3.2.0.0** - [15-02-23] - * New runtimeRunError error class! - -* **prerelease-1.3.1.0.0** - [14-02-23] - * Fixed a count loop error message - * Better error message for else if statements - -* **prerelease-1.3.0.0.3** - [12-02-23] - * Better `undefined` error message for special functions - -* **prerelease-1.3.0.0.2** - [11-02-23] - * Fixed object definition QuickSyntax - -* **prerelease-1.3.0.0.1** - [07-02-23] - * Fixed `in` expression - * character_list `remove` operation now returns the removed character - -* **prerelease-1.3.0.0.0** - [03-02-23] - * ezr² now searches for name of DLL file as the main class in CSAELs - * Error tags now correspond to their errors - * New error tag `length-error` - * Error tag `overflow` now `overflow-error` - * New global variable for error tag `overflow` - * Global variables `err_illop` and `err_undef` are now `err_illegalop` and `err_undefined` - * Functions `insert`, `remove` in character_list now support string / character_list values of length > 1 - * Other new errors - check the commits +* **prerelease-1.4.0.0.0** - [20-03-23] + * Overhaul of module/library system, including `include` expression + * Merged STD and Random libraries + * Error tags in `error` statements are now expressions + * Added character_list support for some built-in string functions ## Contributing ezr² is an open source project and welcomes contributions from anyone who wants to improve it. diff --git a/ezr.cs b/ezr.cs index fb0375f..ca4296a 100644 --- a/ezr.cs +++ b/ezr.cs @@ -10,10 +10,6 @@ using System.IO; using System; -using ezrSquared.Libraries.IO; -using ezrSquared.Libraries.STD; -using ezrSquared.Libraries.Random; - namespace ezrSquared.Main { public class ezr @@ -1473,22 +1469,11 @@ private parseResult tryExpression() result.registerAdvance(); advance(); - token? error = null; - token? varName = null; - if (currentToken.type == TOKENTYPE.STRING || currentToken.type == TOKENTYPE.CHARLIST) - { - error = currentToken; - result.registerAdvance(); - advance(); - } - else if (currentToken.type == TOKENTYPE.ID || currentToken.type == TOKENTYPE.QEY) - { - error = currentToken; - error.type = TOKENTYPE.ID; - result.registerAdvance(); - advance(); - } + node? error = result.tryRegister(this.expression()); + if (error == null) + reverse(result.reverseCount); + token? varName = null; if (currentToken.matchString(TOKENTYPE.KEY, "as")) { result.registerAdvance(); @@ -1505,7 +1490,7 @@ private parseResult tryExpression() if (!currentToken.matchString(TOKENTYPE.KEY, "do")) { if (error == null && varName == null) - return result.failure(new invalidGrammarError("Expected [STRING], [CHARACTER-LIST], [IDENTIFIER], 'as' or 'do'", currentToken.startPos, currentToken.endPos)); + return result.failure(new invalidGrammarError("Expected Expected [INT], [FLOAT], [STRING], [CHARACTER-LIST], [IDENTIFIER], 'if', 'count', 'while', 'try', 'function', 'special', 'object', 'include', 'invert', 'global', 'item', '!', '(', '[', '{', '+', '-', '~', 'as' or 'do'", currentToken.startPos, currentToken.endPos)); else if (varName == null) return result.failure(new invalidGrammarError("Expected 'as' or 'do'", currentToken.startPos, currentToken.endPos)); return result.failure(new invalidGrammarError("Expected 'do'", currentToken.startPos, currentToken.endPos)); @@ -1552,22 +1537,11 @@ private parseResult tryExpression() result.registerAdvance(); advance(); - token? error = null; - token? varName = null; - if (currentToken.type == TOKENTYPE.STRING || currentToken.type == TOKENTYPE.CHARLIST) - { - error = currentToken; - result.registerAdvance(); - advance(); - } - else if (currentToken.type == TOKENTYPE.ID || currentToken.type == TOKENTYPE.QEY) - { - error = currentToken; - error.type = TOKENTYPE.ID; - result.registerAdvance(); - advance(); - } + node? error = result.tryRegister(this.expression()); + if (error == null) + reverse(result.reverseCount); + token? varName = null; if (currentToken.matchString(TOKENTYPE.KEY, "as")) { result.registerAdvance(); @@ -1584,7 +1558,7 @@ private parseResult tryExpression() if (!currentToken.matchString(TOKENTYPE.KEY, "do")) { if (error == null && varName == null) - return result.failure(new invalidGrammarError("Expected [STRING], [CHARACTER-LIST], [IDENTIFIER], 'as' or 'do'", currentToken.startPos, currentToken.endPos)); + return result.failure(new invalidGrammarError("Expected Expected [INT], [FLOAT], [STRING], [CHARACTER-LIST], [IDENTIFIER], 'if', 'count', 'while', 'try', 'function', 'special', 'object', 'include', 'invert', 'global', 'item', '!', '(', '[', '{', '+', '-', '~', 'as' or 'do'", currentToken.startPos, currentToken.endPos)); else if (varName == null) return result.failure(new invalidGrammarError("Expected 'as' or 'do'", currentToken.startPos, currentToken.endPos)); return result.failure(new invalidGrammarError("Expected 'do'", currentToken.startPos, currentToken.endPos)); @@ -1830,18 +1804,8 @@ private parseResult includeExpression() result.registerAdvance(); advance(); - token file; - if (currentToken.type == TOKENTYPE.STRING || currentToken.type == TOKENTYPE.CHARLIST) - file = currentToken; - else if (currentToken.type == TOKENTYPE.ID || currentToken.type == TOKENTYPE.QEY) - { - file = currentToken; - file.type = TOKENTYPE.ID; - } - else - return result.failure(new invalidGrammarError("Expected [STRING], [CHARACTER-LIST] or [IDENTIFIER]", currentToken.startPos, currentToken.endPos)); - result.registerAdvance(); - advance(); + node file = result.register(expression()); + if (result.error != null) return result; token? nickname = null; if (currentToken.matchString(TOKENTYPE.KEY, "as")) @@ -1849,15 +1813,13 @@ private parseResult includeExpression() result.registerAdvance(); advance(); - if (currentToken.type == TOKENTYPE.STRING || currentToken.type == TOKENTYPE.CHARLIST) - nickname = currentToken; - else if (currentToken.type == TOKENTYPE.ID || currentToken.type == TOKENTYPE.QEY) + if (currentToken.type == TOKENTYPE.ID || currentToken.type == TOKENTYPE.QEY) { nickname = currentToken; nickname.type = TOKENTYPE.ID; } else - return result.failure(new invalidGrammarError("Expected [STRING], [CHARACTER-LIST] or [IDENTIFIER]", currentToken.startPos, currentToken.endPos)); + return result.failure(new invalidGrammarError("Expected [IDENTIFIER]", currentToken.startPos, currentToken.endPos)); result.registerAdvance(); advance(); } @@ -2211,22 +2173,11 @@ private parseResult quickTryExpression() result.registerAdvance(); advance(); - token? error = null; - token? varName = null; - if (currentToken.type == TOKENTYPE.STRING || currentToken.type == TOKENTYPE.CHARLIST) - { - error = currentToken; - result.registerAdvance(); - advance(); - } - else if (currentToken.type == TOKENTYPE.ID || currentToken.type == TOKENTYPE.QEY) - { - error = currentToken; - error.type = TOKENTYPE.ID; - result.registerAdvance(); - advance(); - } + node? error = result.tryRegister(this.expression()); + if (error == null) + reverse(result.reverseCount); + token? varName = null; if (currentToken.type == TOKENTYPE.ARROW) { result.registerAdvance(); @@ -2243,7 +2194,7 @@ private parseResult quickTryExpression() if (currentToken.type != TOKENTYPE.COLON) { if (error == null && varName == null) - return result.failure(new invalidGrammarError("Expected [STRING], [CHARACTER-LIST], [IDENTIFIER], '->' or ':'", currentToken.startPos, currentToken.endPos)); + return result.failure(new invalidGrammarError("Expected Expected [INT], [FLOAT], [STRING], [CHARACTER-LIST], [IDENTIFIER], 'if', 'count', 'while', 'try', 'function', 'special', 'object', 'include', 'invert', 'global', 'item', '!', '(', '[', '{', '+', '-', '~', '->' or ':'", currentToken.startPos, currentToken.endPos)); else if (varName == null) return result.failure(new invalidGrammarError("Expected '->' or ':'", currentToken.startPos, currentToken.endPos)); return result.failure(new invalidGrammarError("Expected ':'", currentToken.startPos, currentToken.endPos)); @@ -2289,22 +2240,11 @@ private parseResult quickTryExpression() result.registerAdvance(); advance(); - token? error = null; - token? varName = null; - if (currentToken.type == TOKENTYPE.STRING || currentToken.type == TOKENTYPE.CHARLIST) - { - error = currentToken; - result.registerAdvance(); - advance(); - } - else if (currentToken.type == TOKENTYPE.ID || currentToken.type == TOKENTYPE.QEY) - { - error = currentToken; - error.type = TOKENTYPE.ID; - result.registerAdvance(); - advance(); - } + node? error = result.tryRegister(this.expression()); + if (error == null) + reverse(result.reverseCount); + token? varName = null; if (currentToken.type == TOKENTYPE.ARROW) { result.registerAdvance(); @@ -2321,7 +2261,7 @@ private parseResult quickTryExpression() if (currentToken.type != TOKENTYPE.COLON) { if (error == null && varName == null) - return result.failure(new invalidGrammarError("Expected [STRING], [CHARACTER-LIST], [IDENTIFIER], '->' or ':'", currentToken.startPos, currentToken.endPos)); + return result.failure(new invalidGrammarError("Expected Expected [INT], [FLOAT], [STRING], [CHARACTER-LIST], [IDENTIFIER], 'if', 'count', 'while', 'try', 'function', 'special', 'object', 'include', 'invert', 'global', 'item', '!', '(', '[', '{', '+', '-', '~', '->' or ':'", currentToken.startPos, currentToken.endPos)); else if (varName == null) return result.failure(new invalidGrammarError("Expected '->' or ':'", currentToken.startPos, currentToken.endPos)); return result.failure(new invalidGrammarError("Expected ':'", currentToken.startPos, currentToken.endPos)); @@ -2588,34 +2528,22 @@ private parseResult quickIncludeExpression() result.registerAdvance(); advance(); - token file; - if (currentToken.type == TOKENTYPE.STRING || currentToken.type == TOKENTYPE.CHARLIST) - file = currentToken; - else if (currentToken.type == TOKENTYPE.ID || currentToken.type == TOKENTYPE.QEY) - { - file = currentToken; - file.type = TOKENTYPE.ID; - } - else - return result.failure(new invalidGrammarError("Expected [STRING], [CHARACTER-LIST] or [IDENTIFIER]", currentToken.startPos, currentToken.endPos)); - result.registerAdvance(); - advance(); + node file = result.register(expression()); + if (result.error != null) return result; token? nickname = null; if (currentToken.matchString(TOKENTYPE.QEY, "n")) { result.registerAdvance(); advance(); - - if (currentToken.type == TOKENTYPE.STRING || currentToken.type == TOKENTYPE.CHARLIST) - nickname = currentToken; - else if (currentToken.type == TOKENTYPE.ID || currentToken.type == TOKENTYPE.QEY) + + if (currentToken.type == TOKENTYPE.ID || currentToken.type == TOKENTYPE.QEY) { nickname = currentToken; nickname.type = TOKENTYPE.ID; } else - return result.failure(new invalidGrammarError("Expected [STRING], [CHARACTER-LIST] or [IDENTIFIER]", currentToken.startPos, currentToken.endPos)); + return result.failure(new invalidGrammarError("Expected [IDENTIFIER]", currentToken.startPos, currentToken.endPos)); result.registerAdvance(); advance(); } @@ -3156,19 +3084,13 @@ private runtimeResult visit_tryNode(tryNode node, context context) } else { - token catchTagToken = (token)node.catches[i][0]; - string catchTag = string.Empty; - if (catchTagToken.type == TOKENTYPE.ID) - { - item? tag_ = context.symbolTable.get(catchTagToken.value.ToString()); - if (tag_ == null) - return result.failure(new runtimeError(catchTagToken.startPos, catchTagToken.endPos, RT_UNDEFINED, $"\"{catchTagToken.value}\" is not defined", context)); - else if (tag_ is not @string) - return result.failure(new runtimeError(catchTagToken.startPos, catchTagToken.endPos, RT_TYPE, $"Error tag must be a string", context)); - catchTag = ((@string)tag_).storedValue; - } - else - catchTag = catchTagToken.value.ToString(); + node errorNode = (node)node.catches[i][0]; + item errorTag = result.register(visit(errorNode, context)); + if (result.shouldReturn()) return result; + + if (errorTag is not @string && errorTag is not character_list) + return result.failure(new runtimeError(errorNode.startPos, errorNode.endPos, RT_TYPE, $"Error tag must be a string or character_list", context)); + string catchTag = (errorTag is @string) ? ((@string)errorTag).storedValue : string.Join("", ((character_list)errorTag).storedValue); if (catchTag == tag || catchTag == RT_DEFAULT) { @@ -3297,58 +3219,82 @@ private runtimeResult visit_includeNode(includeNode node, context context) { runtimeResult result = new runtimeResult(); - string file = node.nameToken.value.ToString(); + item file = result.register(visit(node.fileNode, context)); + if (result.shouldReturn()) return result; + + if (file is not @string && file is not character_list) + return result.failure(new runtimeError(node.fileNode.startPos, node.fileNode.endPos, RT_TYPE, $"Filepath must be a string or character_list", context)); + string filepath = (file is @string) ? ((@string)file).storedValue : string.Join("", ((character_list)file).storedValue); + + string[] localLibPaths = new string[LOCALLIBPATHS.Count]; + for (int i = 0; i < LOCALLIBPATHS.Count; i++) + localLibPaths[i] = Path.Join(LOCALLIBPATHS[i], filepath); - string? realFilepath = null; - if (File.Exists(file)) - realFilepath = file; + if (!Path.HasExtension(filepath)) + { + string dllLibPath = Path.Join(STATICLIBPATH, $"{filepath}.dll"); + string ezr2LibPath = Path.Join(STATICLIBPATH, $"{filepath}.ezr2"); + + string dllPath = $"{filepath}.dll"; + string ezr2Path = $"{filepath}.ezr2"; + + if (Path.Exists(dllLibPath)) + filepath = dllLibPath; + else if (Path.Exists(ezr2LibPath)) + filepath = ezr2LibPath; + else if (Path.Exists(dllPath)) + filepath = dllPath; + else if (Path.Exists(ezr2Path)) + filepath = ezr2Path; + else + { + for (int i = 0; i < localLibPaths.Length; i++) + { + string dllLocalPath = $"{localLibPaths[i]}.dll"; + string ezr2LocalPath = $"{localLibPaths[i]}.ezr2"; + + if (Path.Exists(dllLocalPath)) + { + filepath = dllLocalPath; + break; + } + else if (Path.Exists(ezr2LocalPath)) + { + filepath = ezr2LocalPath; + break; + } + } + } + } else { - for (int i = 0; i < LOCALLIBPATHS.Count; i++) + for (int i = 0; i < localLibPaths.Length; i++) { - string path = Path.Join(LOCALLIBPATHS[i], file); - if (File.Exists(path)) + if (File.Exists(localLibPaths[i])) { - realFilepath = path; + filepath = localLibPaths[i]; break; } } } - if (realFilepath == null) + if (!File.Exists(filepath)) return result.failure(new runtimeError(node.startPos, node.endPos, RT_IO, $"Script \"{file}\" was not found", context)); string name; + string nickname_ = string.Empty; if (node.nicknameToken != null) { - if (node.nicknameToken.type == TOKENTYPE.STRING || node.nicknameToken.type == TOKENTYPE.CHARLIST) - name = node.nicknameToken.value.ToString(); - else - { - item? nickname = context.symbolTable.get(node.nicknameToken.value.ToString()); - if (nickname == null) - return result.failure(new runtimeError(node.nicknameToken.startPos, node.nicknameToken.endPos, RT_UNDEFINED, $"\"{node.nicknameToken.value}\" is not defined", context)); - else if (nickname is not @string) - return result.failure(new runtimeError(node.nicknameToken.startPos, node.nicknameToken.endPos, RT_TYPE, $"Nickname must be a string", context)); - name = ((@string)nickname).storedValue; - } + nickname_ = node.nicknameToken.value.ToString(); + name = nickname_; } else { - string? filenameWithoutExtension = Path.GetFileNameWithoutExtension(file); - name = (filenameWithoutExtension != null) ? filenameWithoutExtension : file; + string? filenameWithoutExtension = Path.GetFileNameWithoutExtension(filepath); + name = (filenameWithoutExtension != null) ? filenameWithoutExtension : filepath; } - string formattedFileName = ""; - for (int i = 0; i < name.Length; i++) - { - if (!ALPHANUM_UNDERSCORE.Contains(name[i])) - formattedFileName += '_'; - else - formattedFileName += name[i]; - } - - string? extension = Path.GetExtension(file); + string? extension = Path.GetExtension(filepath); item value; if (extension == ".dll") @@ -3356,7 +3302,7 @@ private runtimeResult visit_includeNode(includeNode node, context context) Assembly DLL; try { - DLL = Assembly.LoadFile(file); + DLL = Assembly.LoadFile(filepath); } catch (Exception exception) { @@ -3365,19 +3311,60 @@ private runtimeResult visit_includeNode(includeNode node, context context) try { - Type? mainLibClass = DLL.GetType(formattedFileName); - if (mainLibClass == null) - return result.failure(new runtimeError(node.startPos, node.endPos, RT_UNDEFINED, $"Main library class in script \"{file}\" is not defined", context)); + Type[] foundTypes = DLL.GetExportedTypes(); - dynamic? val = Activator.CreateInstance(mainLibClass); - - if (val is item) + if (foundTypes.Length < 1) + return result.failure(new runtimeError(node.startPos, node.endPos, RT_IO, $"Could not find any classes in script \"{file}\"", context)); + else if (foundTypes.Length == 1) { - value = result.register(val.setPosition(node.startPos, node.endPos).setContext(context).execute(new item[0])); - if (result.shouldReturn()) return result; + if (typeof(item).IsAssignableFrom(foundTypes[0]) && !foundTypes[0].IsAbstract) + { + dynamic? val; + try + { + val = Activator.CreateInstance(foundTypes[0]); + } + catch + { + return result.failure(new runtimeError(node.startPos, node.endPos, RT_IO, $"Could not find suitable classes in script \"{file}\"", context)); + } + + value = result.register(val.setPosition(node.startPos, node.endPos).setContext(context).execute(new item[0])); + if (result.shouldReturn()) return result; + + context.symbolTable.set((!string.IsNullOrEmpty(nickname_)) ? nickname_ : foundTypes[0].Name, value); + } + else + return result.failure(new runtimeError(node.startPos, node.endPos, RT_IO, $"Could not find suitable classes in script \"{file}\"", context)); } else - return result.failure(new runtimeError(node.startPos, node.endPos, RT_UNDEFINED, $"Main library class in script \"{file}\" is not defined", context)); + { + int foundClasses = 0; + for (int i = 0; i < foundTypes.Length; i++) + { + if (typeof(item).IsAssignableFrom(foundTypes[i]) && !foundTypes[i].IsAbstract) + { + dynamic? val; + try + { + val = Activator.CreateInstance(foundTypes[i]); + } + catch + { + continue; + } + + value = result.register(val.setPosition(node.startPos, node.endPos).setContext(context).execute(new item[0])); + if (result.shouldReturn()) return result; + + context.symbolTable.set(foundTypes[i].Name, value); + foundClasses++; + } + } + + if (foundClasses == 0) + return result.failure(new runtimeError(node.startPos, node.endPos, RT_IO, $"Could not find suitable classes in script \"{file}\"", context)); + } } catch (Exception exception) { @@ -3386,17 +3373,26 @@ private runtimeResult visit_includeNode(includeNode node, context context) } else { + string formattedFileName = LETTERS_UNDERSCORE.Contains(name[0]) ? name[0].ToString() : "_"; + for (int i = 1; i < name.Length; i++) + { + if (!ALPHANUM_UNDERSCORE.Contains(name[i])) + formattedFileName += '_'; + else + formattedFileName += name[i]; + } + string script; try { - script = string.Join('\n', File.ReadAllLines(realFilepath)); + script = string.Join('\n', File.ReadAllLines(filepath)); } catch (Exception exception) { return result.failure(new runtimeError(node.startPos, node.endPos, RT_IO, $"Failed to load script \"{file}\"\n{exception.Message}", context)); } - token[] tokens = new lexer(file, script).compileTokens(out error? error); + token[] tokens = new lexer(filepath, script).compileTokens(out error? error); if (error != null) return result.failure(new runtimeRunError(node.startPos, node.endPos, $"Failed to execute script \"{file}\"", error.asString(), context)); @@ -3407,9 +3403,9 @@ private runtimeResult visit_includeNode(includeNode node, context context) value = result.register(new @class(formattedFileName, null, parseResult.node, new string[0]).setPosition(node.startPos, node.endPos).setContext(context).execute(new item[0])); if (result.shouldReturn()) return result; + context.symbolTable.set(formattedFileName, value); } - context.symbolTable.set(formattedFileName, value); return result.success(new nothing().setPosition(node.startPos, node.endPos).setContext(context)); } } @@ -3457,6 +3453,7 @@ public static context globalPredefinedContext } } + public static string STATICLIBPATH = Path.Join(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Libraries"); public static List LOCALLIBPATHS = new List(); public static error? easyRun(string file, string input, context runtimeContext, out item? result) @@ -3466,19 +3463,6 @@ public static context globalPredefinedContext if (fullFilePath != Directory.GetCurrentDirectory()) LOCALLIBPATHS.Add(fullFilePath); - position pos = new position(0, 0, 0, "
", ""); - _globalPredefinedContext.symbolTable.set("console", new console().setPosition(pos, pos).setContext(_globalPredefinedContext).execute(new item[0]).value); - _globalPredefinedContext.symbolTable.set("file", new @file().setPosition(pos, pos).setContext(_globalPredefinedContext).execute(new item[0]).value); - _globalPredefinedContext.symbolTable.set("folder", new folder().setPosition(pos, pos).setContext(_globalPredefinedContext).execute(new item[0]).value); - _globalPredefinedContext.symbolTable.set("path", new path().setPosition(pos, pos).setContext(_globalPredefinedContext).execute(new item[0]).value); - - _globalPredefinedContext.symbolTable.set("integer", new integer_class().setPosition(pos, pos).setContext(_globalPredefinedContext).execute(new item[0]).value); - _globalPredefinedContext.symbolTable.set("float", new float_class().setPosition(pos, pos).setContext(_globalPredefinedContext).execute(new item[0]).value); - _globalPredefinedContext.symbolTable.set("string", new string_class().setPosition(pos, pos).setContext(_globalPredefinedContext).execute(new item[0]).value); - _globalPredefinedContext.symbolTable.set("character_list", new character_list_class().setPosition(pos, pos).setContext(_globalPredefinedContext).execute(new item[0]).value); - - _globalPredefinedContext.symbolTable.set("random", new random().setPosition(pos, pos).setContext(_globalPredefinedContext).execute(new item[0]).value); - return simpleRun(file, input, runtimeContext, out result); } diff --git a/ezrSquared.csproj b/ezrSquared.csproj index e037db0..47df840 100644 --- a/ezrSquared.csproj +++ b/ezrSquared.csproj @@ -6,8 +6,25 @@ net7.0 ezrSquared ezrSquared.Shell.ezrShell + disable enable Graphics\Icon.ico + + true + true + true + + + + WINDOWS + + + + OSX + + + + LINUX diff --git a/ezrSquared.sln b/ezrSquared.sln index 5451279..4f3c019 100644 --- a/ezrSquared.sln +++ b/ezrSquared.sln @@ -5,6 +5,16 @@ VisualStudioVersion = 17.4.33122.133 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ezrSquared", "ezrSquared.csproj", "{BA3608FA-BD80-4826-A75B-A8F9E3662147}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "io", "Libraries\io\io.csproj", "{1193FFE9-DAC9-45FA-B7F4-0B757FE272EE}" + ProjectSection(ProjectDependencies) = postProject + {BA3608FA-BD80-4826-A75B-A8F9E3662147} = {BA3608FA-BD80-4826-A75B-A8F9E3662147} + EndProjectSection +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "std", "Libraries\std\std.csproj", "{C8EA702B-6553-4540-9541-7C9A5B731BAA}" + ProjectSection(ProjectDependencies) = postProject + {BA3608FA-BD80-4826-A75B-A8F9E3662147} = {BA3608FA-BD80-4826-A75B-A8F9E3662147} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +25,14 @@ Global {BA3608FA-BD80-4826-A75B-A8F9E3662147}.Debug|Any CPU.Build.0 = Debug|Any CPU {BA3608FA-BD80-4826-A75B-A8F9E3662147}.Release|Any CPU.ActiveCfg = Release|Any CPU {BA3608FA-BD80-4826-A75B-A8F9E3662147}.Release|Any CPU.Build.0 = Release|Any CPU + {1193FFE9-DAC9-45FA-B7F4-0B757FE272EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1193FFE9-DAC9-45FA-B7F4-0B757FE272EE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1193FFE9-DAC9-45FA-B7F4-0B757FE272EE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1193FFE9-DAC9-45FA-B7F4-0B757FE272EE}.Release|Any CPU.Build.0 = Release|Any CPU + {C8EA702B-6553-4540-9541-7C9A5B731BAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C8EA702B-6553-4540-9541-7C9A5B731BAA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C8EA702B-6553-4540-9541-7C9A5B731BAA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C8EA702B-6553-4540-9541-7C9A5B731BAA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 453eb62d3debf73555d1a33ea9a319a063801787 Mon Sep 17 00:00:00 2001 From: Udayshankar Ravikumar Date: Mon, 20 Mar 2023 22:30:19 +0530 Subject: [PATCH 2/4] Updated Project! --- ezrSquared.csproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ezrSquared.csproj b/ezrSquared.csproj index 47df840..3c0d440 100644 --- a/ezrSquared.csproj +++ b/ezrSquared.csproj @@ -27,4 +27,8 @@ LINUX + + + + From eb03e9719f40deb675d05e1ba61cd01dcf1b56c4 Mon Sep 17 00:00:00 2001 From: Udayshankar Ravikumar Date: Mon, 20 Mar 2023 23:27:10 +0530 Subject: [PATCH 3/4] ezrSquared prerelease-1.4.0.1.0 --- Changelog.txt | 3 +++ Constants.cs | 2 +- Libraries/io/IO.cs | 22 ++++++++++++---------- docs/index.markdown | 3 +++ ezrSquared.csproj | 16 ---------------- 5 files changed, 19 insertions(+), 27 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 631888e..785d6d8 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,5 +1,8 @@ CHANGELOG - What's new? +* prerelease-1.4.0.1.0 - [20-03-23] + * Windows-only functions in the IO library are now actually Windows-only + * prerelease-1.4.0.0.0 - [20-03-23] * Overhaul of module/library system, including `include` expression * Merged STD and Random libraries diff --git a/Constants.cs b/Constants.cs index 638b320..dc09d7e 100644 --- a/Constants.cs +++ b/Constants.cs @@ -4,7 +4,7 @@ namespace ezrSquared.Constants { public static class constants { - public const string VERSION = "prerelease-1.4.0.0.0"; + public const string VERSION = "prerelease-1.4.0.1.0"; public const string VERSION_DATE = "20.03.2023"; public static readonly string[] KEYWORDS = { "item", "and", "or", "invert", "if", "else", "do", "count", "from", "as", "to", "step", "while", "function", "special", "with", "end", "return", "skip", "stop", "try", "error", "in", "object", "global", "include" }; diff --git a/Libraries/io/IO.cs b/Libraries/io/IO.cs index e265d60..3a2dead 100644 --- a/Libraries/io/IO.cs +++ b/Libraries/io/IO.cs @@ -354,8 +354,18 @@ public override runtimeResult execute(item[] args) context internalContext = base.generateContext(); internalContext.symbolTable.set("is_key_pressed", new predefined_function("console_is_key_pressed", keyPressed, new string[4] { "key", "shift_pressed", "control_pressed", "alt_pressed" })); internalContext.symbolTable.set("current_key_pressed", new predefined_function("console_current_key_pressed", anyKeyPressed, new string[0])); - internalContext.symbolTable.set("is_numberlocked", new predefined_function("console_is_numberlocked", numberLocked, new string[0])); - internalContext.symbolTable.set("is_capslocked", new predefined_function("console_is_capslocked", capsLocked, new string[0])); + + if (OperatingSystem.IsWindows()) + { + internalContext.symbolTable.set("is_numberlocked", new predefined_function("console_is_numberlocked", numberLocked, new string[0])); + internalContext.symbolTable.set("is_capslocked", new predefined_function("console_is_capslocked", capsLocked, new string[0])); + + internalContext.symbolTable.set("get_cursor_size", new predefined_function("console_get_cursor_size", getCursorSize, new string[0])); + internalContext.symbolTable.set("set_cursor_size", new predefined_function("console_set_cursor_size", setCursorSize, new string[1] { "size" })); + internalContext.symbolTable.set("get_cursor_visibility", new predefined_function("console_get_cursor_visibility", getCursorVisibility, new string[0])); + internalContext.symbolTable.set("set_cursor_visibility", new predefined_function("console_set_cursor_visibility", setCursorVisibility, new string[1] { "visibility" })); + } + internalContext.symbolTable.set("get_background", new predefined_function("console_get_background", getConsoleBackground, new string[0])); internalContext.symbolTable.set("set_background", new predefined_function("console_set_background", setConsoleBackground, new string[1] { "color" })); internalContext.symbolTable.set("get_foreground", new predefined_function("console_get_foreground", getConsoleForeground, new string[0])); @@ -363,18 +373,11 @@ public override runtimeResult execute(item[] args) internalContext.symbolTable.set("reset_colors", new predefined_function("console_reset_colors", consoleResetColors, new string[0])); internalContext.symbolTable.set("get_cursor_position", new predefined_function("console_get_cursor_position", getCursorPosition, new string[0])); internalContext.symbolTable.set("set_cursor_position", new predefined_function("console_set_cursor_position", setCursorPosition, new string[1] { "position" })); -#if WINDOWS - internalContext.symbolTable.set("get_cursor_size", new predefined_function("console_get_cursor_size", getCursorSize, new string[0])); - internalContext.symbolTable.set("set_cursor_size", new predefined_function("console_set_cursor_size", setCursorSize, new string[1] { "size" })); - internalContext.symbolTable.set("get_cursor_visibility", new predefined_function("console_get_cursor_visibility", getCursorVisibility, new string[0])); - internalContext.symbolTable.set("set_cursor_visibility", new predefined_function("console_set_cursor_visibility", setCursorVisibility, new string[1] { "visibility" })); -#endif internalContext.symbolTable.set("exit", new predefined_function("console_exit", stopApplication, new string[0])); return new runtimeResult().success(new @object(name, internalContext).setPosition(startPos, endPos).setContext(context)); } -#if WINDOWS private runtimeResult getCursorVisibility(context context, position[] positions) { return new runtimeResult().success(new boolean(Console.CursorVisible)); @@ -412,7 +415,6 @@ private runtimeResult setCursorSize(context context, position[] positions) Console.CursorSize = sizeValue; return result.success(new nothing()); } -#endif private runtimeResult getCursorPosition(context context, position[] positions) { diff --git a/docs/index.markdown b/docs/index.markdown index 02a0dd1..547252a 100644 --- a/docs/index.markdown +++ b/docs/index.markdown @@ -97,6 +97,9 @@ Meanwhile, check out some example programs in [***GitHub***](https://github.com/ ## Latest Updates **For those confused by the versioning: 1st place -> Major; 2nd place -> Feature; 3rd place -> Quality of Life; 4th place -> Library; 5th place -> Patch**. I plan to switch to [***Semantic Versioning 2.0.0***](https://semver.org/) for the first stable release. +* prerelease-1.4.0.1.0 - [20-03-23] + * Windows-only functions in the IO library are now actually Windows-only + * **prerelease-1.4.0.0.0** - [20-03-23] * Overhaul of module/library system, including `include` expression * Merged STD and Random libraries diff --git a/ezrSquared.csproj b/ezrSquared.csproj index 3c0d440..e390f34 100644 --- a/ezrSquared.csproj +++ b/ezrSquared.csproj @@ -10,22 +10,6 @@ enable Graphics\Icon.ico - - true - true - true - - - - WINDOWS - - - - OSX - - - - LINUX From a488dad12a88b55fec1cea02f444dbf72d4fd177 Mon Sep 17 00:00:00 2001 From: Udayshankar Ravikumar Date: Tue, 21 Mar 2023 01:27:25 +0530 Subject: [PATCH 4/4] Updated consoleTest! --- Tests/consoleTest.ezr2 | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/consoleTest.ezr2 b/Tests/consoleTest.ezr2 index dbb3e2f..f3c457f 100644 --- a/Tests/consoleTest.ezr2 +++ b/Tests/consoleTest.ezr2 @@ -1,3 +1,4 @@ +include "io" item origRow: (global item origCol: 0)