mirror of
https://github.com/Stone-Red-Code/YesNt-Interpreter.git
synced 2026-09-08 07:56:06 +02:00
Use var instead of let for variables
This commit is contained in:
@@ -9,7 +9,7 @@ Current language syntax is documented in [SYNTAX_V2.md](SYNTAX_V2.md).
|
|||||||
Example:
|
Example:
|
||||||
|
|
||||||
```ynt
|
```ynt
|
||||||
let name = world
|
var name = world
|
||||||
print_line Hello ${name}
|
print_line Hello ${name}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -18,3 +18,4 @@ print_line Hello ${name}
|
|||||||
```bash
|
```bash
|
||||||
dotnet run --project YesNt.Interpreter -- path/to/script.ynt
|
dotnet run --project YesNt.Interpreter -- path/to/script.ynt
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -20,7 +20,7 @@ This document describes the current, word-based YesNt syntax.
|
|||||||
## Quick Example
|
## Quick Example
|
||||||
|
|
||||||
```ynt
|
```ynt
|
||||||
let name = world
|
var name = world
|
||||||
func greet:
|
func greet:
|
||||||
print_line Hello ${name}
|
print_line Hello ${name}
|
||||||
return
|
return
|
||||||
@@ -40,10 +40,10 @@ end_if
|
|||||||
## While Loops
|
## While Loops
|
||||||
|
|
||||||
```ynt
|
```ynt
|
||||||
let i = 3
|
var i = 3
|
||||||
while ${i} > 0:
|
while ${i} > 0:
|
||||||
print_line ${i}
|
print_line ${i}
|
||||||
let i = ${i} - 1 calc
|
var i = ${i} - 1 calc
|
||||||
end_while
|
end_while
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ end_while
|
|||||||
|
|
||||||
| Area | v1 Syntax | v2 Syntax | Notes |
|
| Area | v1 Syntax | v2 Syntax | Notes |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| Variables | `<x = value` | `let x = value` | Local variable define/update. |
|
| Variables | `<x = value` | `var x = value` | Local variable define/update. |
|
||||||
| Variables | `!<x = value` | `global x = value` | Global variable define/update. |
|
| Variables | `!<x = value` | `global x = value` | Global variable define/update. |
|
||||||
| Variables | `del x` | `delete x` | Deletes local first, then global. |
|
| Variables | `del x` | `delete x` | Deletes local first, then global. |
|
||||||
| Variables | `>x` | `${x}` | Variable read/interpolation token. |
|
| Variables | `>x` | `${x}` | Variable read/interpolation token. |
|
||||||
@@ -99,3 +99,4 @@ end_while
|
|||||||
|
|
||||||
- `%out` is intentionally kept as `%out`.
|
- `%out` is intentionally kept as `%out`.
|
||||||
- Postfix operations are `calc`, `eval`, and `task`.
|
- Postfix operations are `calc`, `eval`, and `task`.
|
||||||
|
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ public class CodeFlowStatementsTests
|
|||||||
{
|
{
|
||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"let result = before",
|
"var result = before",
|
||||||
"exit",
|
"exit",
|
||||||
"let result = after",
|
"var result = after",
|
||||||
"${result}"
|
"${result}"
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ public class CodeFlowStatementsTests
|
|||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"abort_all",
|
"abort_all",
|
||||||
"let result = after",
|
"var result = after",
|
||||||
"${result}"
|
"${result}"
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -78,3 +78,4 @@ public class CodeFlowStatementsTests
|
|||||||
YesNtAssert.ContainsTerminationMessage(lines, "Function \"nowhere\" not found");
|
YesNtAssert.ContainsTerminationMessage(lines, "Function \"nowhere\" not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ public class CodeFlowTests
|
|||||||
{
|
{
|
||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"let result = 1",
|
"var result = 1",
|
||||||
"goto yes",
|
"goto yes",
|
||||||
"let result = 0",
|
"var result = 0",
|
||||||
"label yes:",
|
"label yes:",
|
||||||
"${result}"
|
"${result}"
|
||||||
];
|
];
|
||||||
@@ -40,9 +40,9 @@ public class CodeFlowTests
|
|||||||
{
|
{
|
||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"let result = low",
|
"var result = low",
|
||||||
"if 6 > 5:",
|
"if 6 > 5:",
|
||||||
"let result = high",
|
"var result = high",
|
||||||
"end_if",
|
"end_if",
|
||||||
"${result}"
|
"${result}"
|
||||||
];
|
];
|
||||||
@@ -55,11 +55,11 @@ public class CodeFlowTests
|
|||||||
{
|
{
|
||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"let result = low",
|
"var result = low",
|
||||||
"if 6 < 5:",
|
"if 6 < 5:",
|
||||||
"let result = high",
|
"var result = high",
|
||||||
"else:",
|
"else:",
|
||||||
"let result = medium",
|
"var result = medium",
|
||||||
"end_if",
|
"end_if",
|
||||||
"${result}"
|
"${result}"
|
||||||
];
|
];
|
||||||
@@ -72,12 +72,12 @@ public class CodeFlowTests
|
|||||||
{
|
{
|
||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"let result = 0",
|
"var result = 0",
|
||||||
"if 1 == 1:",
|
"if 1 == 1:",
|
||||||
"if 2 == 3:",
|
"if 2 == 3:",
|
||||||
"let result = 1",
|
"var result = 1",
|
||||||
"else:",
|
"else:",
|
||||||
"let result = 2",
|
"var result = 2",
|
||||||
"end_if",
|
"end_if",
|
||||||
"end_if",
|
"end_if",
|
||||||
"${result}"
|
"${result}"
|
||||||
@@ -91,9 +91,9 @@ public class CodeFlowTests
|
|||||||
{
|
{
|
||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"let i = 3",
|
"var i = 3",
|
||||||
"while ${i} > 0:",
|
"while ${i} > 0:",
|
||||||
"let i = ${i} - 1 calc",
|
"var i = ${i} - 1 calc",
|
||||||
"end_while",
|
"end_while",
|
||||||
"${i}"
|
"${i}"
|
||||||
];
|
];
|
||||||
@@ -106,9 +106,9 @@ public class CodeFlowTests
|
|||||||
{
|
{
|
||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"let i = 0",
|
"var i = 0",
|
||||||
"while ${i} > 0:",
|
"while ${i} > 0:",
|
||||||
"let i = 99",
|
"var i = 99",
|
||||||
"end_while",
|
"end_while",
|
||||||
"${i}"
|
"${i}"
|
||||||
];
|
];
|
||||||
@@ -121,15 +121,15 @@ public class CodeFlowTests
|
|||||||
{
|
{
|
||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"let outer = 2",
|
"var outer = 2",
|
||||||
"let count = 0",
|
"var count = 0",
|
||||||
"while ${outer} > 0:",
|
"while ${outer} > 0:",
|
||||||
"let inner = 2",
|
"var inner = 2",
|
||||||
"while ${inner} > 0:",
|
"while ${inner} > 0:",
|
||||||
"let count = ${count} + 1 calc",
|
"var count = ${count} + 1 calc",
|
||||||
"let inner = ${inner} - 1 calc",
|
"var inner = ${inner} - 1 calc",
|
||||||
"end_while",
|
"end_while",
|
||||||
"let outer = ${outer} - 1 calc",
|
"var outer = ${outer} - 1 calc",
|
||||||
"end_while",
|
"end_while",
|
||||||
"${count}"
|
"${count}"
|
||||||
];
|
];
|
||||||
@@ -142,11 +142,11 @@ public class CodeFlowTests
|
|||||||
{
|
{
|
||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"let result = 0",
|
"var result = 0",
|
||||||
"if 2 > 1:",
|
"if 2 > 1:",
|
||||||
"let result = 1",
|
"var result = 1",
|
||||||
"else:",
|
"else:",
|
||||||
"let result = 2",
|
"var result = 2",
|
||||||
"end_if",
|
"end_if",
|
||||||
"${result}"
|
"${result}"
|
||||||
];
|
];
|
||||||
@@ -159,9 +159,9 @@ public class CodeFlowTests
|
|||||||
{
|
{
|
||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"let result = 5",
|
"var result = 5",
|
||||||
"if 1 == 2:",
|
"if 1 == 2:",
|
||||||
"let result = 1",
|
"var result = 1",
|
||||||
"end_if",
|
"end_if",
|
||||||
"${result}"
|
"${result}"
|
||||||
];
|
];
|
||||||
@@ -174,11 +174,11 @@ public class CodeFlowTests
|
|||||||
{
|
{
|
||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"let result = 0",
|
"var result = 0",
|
||||||
"if 1 == 1 goto done",
|
"if 1 == 1 goto done",
|
||||||
"let result = 2",
|
"var result = 2",
|
||||||
"label done:",
|
"label done:",
|
||||||
"let result = ${result} + 1 calc",
|
"var result = ${result} + 1 calc",
|
||||||
"${result}"
|
"${result}"
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -228,7 +228,7 @@ public class CodeFlowTests
|
|||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"if 1 == 2:",
|
"if 1 == 2:",
|
||||||
"let result = 1"
|
"var result = 1"
|
||||||
];
|
];
|
||||||
|
|
||||||
YesNtAssert.ContainsTerminationMessage(lines, "No matching end_if found");
|
YesNtAssert.ContainsTerminationMessage(lines, "No matching end_if found");
|
||||||
@@ -250,9 +250,9 @@ public class CodeFlowTests
|
|||||||
{
|
{
|
||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"let i = 0",
|
"var i = 0",
|
||||||
"while ${i} > 1:",
|
"while ${i} > 1:",
|
||||||
"let i = ${i} + 1 calc"
|
"var i = ${i} + 1 calc"
|
||||||
];
|
];
|
||||||
|
|
||||||
YesNtAssert.ContainsTerminationMessage(lines, "No matching end_while found");
|
YesNtAssert.ContainsTerminationMessage(lines, "No matching end_while found");
|
||||||
@@ -269,3 +269,4 @@ public class CodeFlowTests
|
|||||||
YesNtAssert.ContainsTerminationMessage(lines, "No matching while found");
|
YesNtAssert.ContainsTerminationMessage(lines, "No matching while found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public class ConsoleStatementsTests
|
|||||||
|
|
||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"let value = %read_line",
|
"var value = %read_line",
|
||||||
"${value}"
|
"${value}"
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ public class ConsoleStatementsTests
|
|||||||
|
|
||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"let value = %read_key"
|
"var value = %read_key"
|
||||||
];
|
];
|
||||||
|
|
||||||
_ = Task.Run(() => interpreter.Execute(lines, true));
|
_ = Task.Run(() => interpreter.Execute(lines, true));
|
||||||
@@ -108,3 +108,4 @@ public class ConsoleStatementsTests
|
|||||||
StringAssert.Contains(output.ToString(), "Terminated by external process");
|
StringAssert.Contains(output.ToString(), "Terminated by external process");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,14 +32,14 @@ public class FunctionStatementsTests
|
|||||||
"goto main",
|
"goto main",
|
||||||
"func probe:",
|
"func probe:",
|
||||||
"global hasInBefore = %has_in",
|
"global hasInBefore = %has_in",
|
||||||
"let consume = %in",
|
"var consume = %in",
|
||||||
"global hasInAfter = %has_in",
|
"global hasInAfter = %has_in",
|
||||||
"push_out ${hasInBefore}",
|
"push_out ${hasInBefore}",
|
||||||
"push_out ${hasInAfter}",
|
"push_out ${hasInAfter}",
|
||||||
"return",
|
"return",
|
||||||
"label main:",
|
"label main:",
|
||||||
"call probe with x",
|
"call probe with x",
|
||||||
"let hasOut = %has_out",
|
"var hasOut = %has_out",
|
||||||
"${hasOut}"
|
"${hasOut}"
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ public class FunctionStatementsTests
|
|||||||
"return",
|
"return",
|
||||||
"label main:",
|
"label main:",
|
||||||
"call make with anything",
|
"call make with anything",
|
||||||
"let value = %out",
|
"var value = %out",
|
||||||
"${value}"
|
"${value}"
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ public class FunctionStatementsTests
|
|||||||
{
|
{
|
||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"let x = %out"
|
"var x = %out"
|
||||||
];
|
];
|
||||||
|
|
||||||
YesNtAssert.ContainsTerminationMessage(lines, "No out argument in stack");
|
YesNtAssert.ContainsTerminationMessage(lines, "No out argument in stack");
|
||||||
@@ -80,7 +80,7 @@ public class FunctionStatementsTests
|
|||||||
{
|
{
|
||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"let x = %in"
|
"var x = %in"
|
||||||
];
|
];
|
||||||
|
|
||||||
YesNtAssert.ContainsTerminationMessage(lines, "Statement not allowed outside of function");
|
YesNtAssert.ContainsTerminationMessage(lines, "Statement not allowed outside of function");
|
||||||
@@ -138,10 +138,11 @@ public class FunctionStatementsTests
|
|||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"clear_call_stack",
|
"clear_call_stack",
|
||||||
"let result = ok",
|
"var result = ok",
|
||||||
"${result}"
|
"${result}"
|
||||||
];
|
];
|
||||||
|
|
||||||
YesNtAssert.IsLastLineEqual(lines, "ok");
|
YesNtAssert.IsLastLineEqual(lines, "ok");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public class ProcessingStatementsTests
|
|||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"sleep 5",
|
"sleep 5",
|
||||||
"let result = ok",
|
"var result = ok",
|
||||||
"${result}"
|
"${result}"
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ public class ProcessingStatementsTests
|
|||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"length hello",
|
"length hello",
|
||||||
"let value = %out",
|
"var value = %out",
|
||||||
"${value}"
|
"${value}"
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ public class ProcessingStatementsTests
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File.WriteAllText(tempFile, "let imported = yes");
|
File.WriteAllText(tempFile, "var imported = yes");
|
||||||
|
|
||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
@@ -139,3 +139,4 @@ public class ProcessingStatementsTests
|
|||||||
YesNtAssert.IsLastLineEqual(lines, "1", timeout: 3000);
|
YesNtAssert.IsLastLineEqual(lines, "1", timeout: 3000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class SystemStatementsTests
|
|||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"exec cmd with /c,echo yesnt",
|
"exec cmd with /c,echo yesnt",
|
||||||
"let exitCode = %out",
|
"var exitCode = %out",
|
||||||
"${exitCode}"
|
"${exitCode}"
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ public class SystemStatementsTests
|
|||||||
"push_in /c",
|
"push_in /c",
|
||||||
"push_in echo yesnt",
|
"push_in echo yesnt",
|
||||||
"exec cmd",
|
"exec cmd",
|
||||||
"let exitCode = %out",
|
"var exitCode = %out",
|
||||||
"${exitCode}"
|
"${exitCode}"
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -46,3 +46,4 @@ public class SystemStatementsTests
|
|||||||
YesNtAssert.ContainsTerminationMessage(lines, "Failed to start \"does_not_exist_abc_xyz\"");
|
YesNtAssert.ContainsTerminationMessage(lines, "Failed to start \"does_not_exist_abc_xyz\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public class VariableStatementsTests
|
|||||||
{
|
{
|
||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"let value = hi",
|
"var value = hi",
|
||||||
"${value}"
|
"${value}"
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ public class VariableStatementsTests
|
|||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"global value = global",
|
"global value = global",
|
||||||
"let value = local",
|
"var value = local",
|
||||||
"${value}"
|
"${value}"
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ public class VariableStatementsTests
|
|||||||
{
|
{
|
||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"let value = a",
|
"var value = a",
|
||||||
"delete value",
|
"delete value",
|
||||||
"global value = b",
|
"global value = b",
|
||||||
"${value}"
|
"${value}"
|
||||||
@@ -74,7 +74,7 @@ public class VariableStatementsTests
|
|||||||
{
|
{
|
||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"let a"
|
"var a"
|
||||||
];
|
];
|
||||||
|
|
||||||
YesNtAssert.ContainsTerminationMessage(lines, "Invalid statement");
|
YesNtAssert.ContainsTerminationMessage(lines, "Invalid statement");
|
||||||
@@ -85,7 +85,7 @@ public class VariableStatementsTests
|
|||||||
{
|
{
|
||||||
List<string> lines =
|
List<string> lines =
|
||||||
[
|
[
|
||||||
"let a b = 1"
|
"var a b = 1"
|
||||||
];
|
];
|
||||||
|
|
||||||
YesNtAssert.ContainsTerminationMessage(lines, "Invalid Syntax");
|
YesNtAssert.ContainsTerminationMessage(lines, "Invalid Syntax");
|
||||||
@@ -102,3 +102,4 @@ public class VariableStatementsTests
|
|||||||
YesNtAssert.ContainsTerminationMessage(lines, "Variable \"missing\" not found");
|
YesNtAssert.ContainsTerminationMessage(lines, "Variable \"missing\" not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
using YesNt.Interpreter.Attributes;
|
using YesNt.Interpreter.Attributes;
|
||||||
using YesNt.Interpreter.Enums;
|
using YesNt.Interpreter.Enums;
|
||||||
@@ -8,7 +8,7 @@ namespace YesNt.Interpreter.Statements;
|
|||||||
|
|
||||||
internal partial class VariableStatements : StatementRuntimeInformation
|
internal partial class VariableStatements : StatementRuntimeInformation
|
||||||
{
|
{
|
||||||
[Statement("let", SearchMode.StartOfLine, SpaceAround.End, System.ConsoleColor.DarkBlue, Priority = Priority.VeryLow, Separator = "=")]
|
[Statement("var", SearchMode.StartOfLine, SpaceAround.End, System.ConsoleColor.DarkBlue, Priority = Priority.VeryLow, Separator = "=")]
|
||||||
public void DefineVariable(string args)
|
public void DefineVariable(string args)
|
||||||
{
|
{
|
||||||
string[] parts = args.Split('=');
|
string[] parts = args.Split('=');
|
||||||
@@ -118,3 +118,4 @@ internal partial class VariableStatements : StatementRuntimeInformation
|
|||||||
[GeneratedRegex("\\$\\{([a-zA-Z0-9]+)\\}")]
|
[GeneratedRegex("\\$\\{([a-zA-Z0-9]+)\\}")]
|
||||||
private static partial Regex VariableStatementRegex();
|
private static partial Regex VariableStatementRegex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user