Skip to content

Commit

Permalink
Merge pull request #2 from Uralstech/experimental
Browse files Browse the repository at this point in the history
Merge experimental into master
  • Loading branch information
Uralstech committed Mar 20, 2023
2 parents f59fcfc + a488dad commit fb628d0
Show file tree
Hide file tree
Showing 14 changed files with 324 additions and 324 deletions.
44 changes: 8 additions & 36 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,10 @@
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
* 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
* Error tags in `error` statements are now expressions
* Added character_list support for some built-in string functions
6 changes: 3 additions & 3 deletions Classes/Nodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
35 changes: 23 additions & 12 deletions Classes/Values.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,17 +1002,18 @@ 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)
return result.failure(new runtimeError(positions[0], positions[1], RT_INDEX, "Index cannot be less than zero", context));
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)
Expand All @@ -1021,21 +1022,26 @@ 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)
{
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++)
Expand All @@ -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)));
}
Expand Down
4 changes: 2 additions & 2 deletions Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.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" };
public static readonly string[] QEYWORDS = { "f", "l", "e", "c", "t", "n", "w", "fd", "sd", "od", "i", "s", "d", "g", "v" };
Expand Down
52 changes: 0 additions & 52 deletions Libraries/Random.cs

This file was deleted.

26 changes: 16 additions & 10 deletions Libraries/IO.cs → Libraries/io/IO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,21 +352,27 @@ 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]));

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]));
internalContext.symbolTable.set("set_foreground", new predefined_function("console_set_foreground", setConsoleForeground, new string[1] { "color" }));
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" }));
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("exit", new predefined_function("console_exit", stopApplication, new string[0]));

return new runtimeResult().success(new @object(name, internalContext).setPosition(startPos, endPos).setContext(context));
Expand Down Expand Up @@ -527,8 +533,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));
}

Expand Down Expand Up @@ -891,7 +897,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();
Expand Down
19 changes: 19 additions & 0 deletions Libraries/io/io.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Reference Include="ezrSquared">
<HintPath>..\..\bin\Release\net7.0\win-x86\ezrSquared.dll</HintPath>
</Reference>
</ItemGroup>

<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
</PropertyGroup>
</Project>
Loading

0 comments on commit fb628d0

Please sign in to comment.