Skip to content

Commit 2d1d41a

Browse files
v2.3.0_Beta : Beggining EZText
1 parent 2fa709a commit 2d1d41a

3 files changed

Lines changed: 222 additions & 105 deletions

File tree

EZCode/EZCode.cs

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Text;
1010
using System.Text.RegularExpressions;
1111
using System.Windows.Forms;
12+
using static System.Windows.Forms.LinkLabel;
1213
using Group = EZCode.Groups.Group;
1314
using Player = Sound.Player;
1415
using Types = EZCode.Variables.Ivar.Types;
@@ -245,6 +246,10 @@ private set
245246
/// Needs to have Key_Down and Key_Up event connected to KeyInput_Down and KeyInput_Up
246247
/// </summary>
247248
public HashSet<Keys> Keys = new HashSet<Keys>();
249+
/// <summary>
250+
/// If the code is currently running EZText
251+
/// </summary>
252+
private bool isEZText = false;
248253

249254
public static readonly string SegmentSeperator = "segment";
250255
/// <summary>
@@ -1570,27 +1575,31 @@ async Task<string[]> PlaySwitch(string[]? _parts = null, string jumpsto = "", st
15701575
default:
15711576
try
15721577
{
1573-
if (keyword == "#" || keyword == "#create".ToLower() || keyword == "#suppress".ToLower() || keyword == "#current" || keyword == "#project")
1578+
if (keyword == "#" || keyword == "#create".ToLower() || keyword == "#suppress".ToLower() || keyword == "#current" || keyword == "#project" || keyword == "#eztext")
15741579
{
15751580
int index =
15761581
keyword == "#" && parts[1] == "create".ToLower() ? 2 :
15771582
keyword == "#" && parts[1] == "suppress".ToLower() ? 2 :
15781583
keyword == "#" && parts[1] == "project".ToLower() ? 2 :
15791584
keyword == "#" && parts[1] == "current".ToLower() ? 2 :
1585+
keyword == "#" && parts[1] == "eztext".ToLower() ? 2 :
15801586
keyword == "#create".ToLower() ? 1 :
15811587
keyword == "#suppress".ToLower() ? 1 :
15821588
keyword == "#current".ToLower() ? 1 :
15831589
keyword == "#project".ToLower() ? 1 :
1590+
keyword == "#eztext".ToLower() ? 1 :
15841591
0;
15851592
keyword =
15861593
keyword == "#" && parts[1] == "create".ToLower() ? "#create" :
15871594
keyword == "#" && parts[1] == "suppress".ToLower() ? "#suppress" :
15881595
keyword == "#" && parts[1] == "current".ToLower() ? "#current" :
15891596
keyword == "#" && parts[1] == "project".ToLower() ? "#project" :
1597+
keyword == "#" && parts[1] == "eztext".ToLower() ? "#eztext" :
15901598
keyword == "#create".ToLower() ? keyword.ToLower() :
15911599
keyword == "#suppress".ToLower() ? keyword.ToLower() :
15921600
keyword == "#current".ToLower() ? keyword.ToLower() :
15931601
keyword == "#project".ToLower() ? keyword.ToLower() :
1602+
keyword == "#eztext".ToLower() ? keyword.ToLower() :
15941603
keyword;
15951604
switch (keyword)
15961605
{
@@ -1704,6 +1713,58 @@ async Task<string[]> PlaySwitch(string[]? _parts = null, string jumpsto = "", st
17041713
}
17051714
}
17061715
break;
1716+
case "#eztext":
1717+
if (parts[index].ToLower() != "start" && parts[index].ToLower() != "end")
1718+
{
1719+
ErrorText(parts, ErrorTypes.custom, custom: $"Expected 'start' or 'end' keyword after '#eztext'");
1720+
}
1721+
else if (parts[index].ToLower() == "start")
1722+
{
1723+
List<string> everythingafter = new List<string>();
1724+
everythingafter.AddRange(splitcode.Skip(currentindex + 1));
1725+
everythingafter = everythingafter.Select(x => x.Trim()).TakeWhile(y => !(y == "# eztext end" || y == "#eztext end")).ToList();
1726+
1727+
EZText eztext = new EZText(this);
1728+
string newCode = eztext.Translate(string.Join(Environment.NewLine, everythingafter), codeLine);
1729+
foreach (string error in eztext.Errors)
1730+
{
1731+
ErrorText(new string[0], ErrorTypes.custom, custom: error, dontshowcode: true, dontshowsegment: true);
1732+
}
1733+
List<string> lines = newCode.Split(new[] { '\n', '|' }).Select(x => x.Trim()).Where(y => y != "").ToList();
1734+
string output = "";
1735+
int oldCodeLine = codeLine;
1736+
isEZText = true;
1737+
1738+
for (int i = 0; i < lines.Count; i++)
1739+
{
1740+
if (!playing) break;
1741+
codeLine = i + 1;
1742+
List<string> a_parts = lines[i].Split(new char[] { ' ' }).Where(x => x != "").ToList();
1743+
for (int j = 0; j < a_parts.Count; j++)
1744+
{
1745+
if (a_parts[j].Trim() == "->")
1746+
{
1747+
try
1748+
{
1749+
a_parts.RemoveAt(j);
1750+
a_parts.AddRange(lines[i + 1].Split(' '));
1751+
lines.RemoveAt(i + 1);
1752+
}
1753+
catch
1754+
{
1755+
1756+
}
1757+
}
1758+
}
1759+
string[] task = await PlaySwitch(a_parts.ToArray(), "", lines.ToArray(), i, debugger);
1760+
if (bool.Parse(task[1]) == false) i = lines.Count - 1;
1761+
output += task[0];
1762+
ConsoleText = output;
1763+
}
1764+
ifmany = lines.Count;
1765+
isEZText = false;
1766+
}
1767+
break;
17071768
}
17081769
}
17091770
else if (vars.Select(x => x.Name).Contains(keyword))
@@ -5837,7 +5898,7 @@ public enum ErrorTypes
58375898
/// <param name="keyword">keyword, for error type</param>
58385899
/// <param name="name">name, for the error type</param>
58395900
/// <param name="custom">cutom error, this makes the 'name' and 'keyword' parameters not needed</param>
5840-
public string ErrorText(string[] parts, ErrorTypes error, string keyword = "keyword", string name = "name", string custom = "An Error Occured", bool returnoutput = true, bool dontshowsegment = false)
5901+
public string ErrorText(string[] parts, ErrorTypes error, string keyword = "keyword", string name = "name", string custom = "An Error Occured", bool returnoutput = true, bool dontshowsegment = false, bool dontshowcode = false)
58415902
{
58425903
string text =
58435904
error == ErrorTypes.unkown ? $"An error occured in {SegmentSeperator} {codeLine}" :
@@ -5852,7 +5913,7 @@ public string ErrorText(string[] parts, ErrorTypes error, string keyword = "keyw
58525913
error == ErrorTypes.errorEquation ? $"Unable to solve the equation in {SegmentSeperator} {codeLine}" :
58535914
error == ErrorTypes.methodnamingvoilation ? $"Can not name '{keyword}' as '{name}' because there is a method already named '{name}' in {SegmentSeperator} {codeLine}" :
58545915
error == ErrorTypes.custom ? $"{custom}{(!dontshowsegment ? $" in {SegmentSeperator} {codeLine}" : "")}" : "An Error Occured, We don't know why. If it helps, it was on line " + codeLine;
5855-
text += " : " + string.Join(" ", parts);
5916+
text += !dontshowcode ? " : " + string.Join(" ", parts) : "";
58565917
if ((parts.Contains("#suppress") && parts.Contains("error")) || (parts.Contains("#") && parts.Contains("suppress") && parts.Contains("error"))) return "";
58575918
if (showFileInError)
58585919
{

EZCode/EZText.cs

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
using System.Windows.Forms;
2+
using static System.Runtime.InteropServices.JavaScript.JSType;
3+
4+
namespace EZCode
5+
{
6+
public class EZText
7+
{
8+
/// <summary>
9+
/// EZCode object EZR Code is referencing
10+
/// </summary>
11+
public EzCode ezCode { get; set; }
12+
/// <summary>
13+
/// Easier Code Given
14+
/// </summary>
15+
public string ezText { get; set; } = "";
16+
/// <summary>
17+
/// Translated EZCode
18+
/// </summary>
19+
public string Code { get; set; } = "";
20+
/// <summary>
21+
/// Current line of EZText
22+
/// </summary>
23+
public int CodeLine { get; set; } = 0;
24+
/// <summary>
25+
/// Errors in EZText
26+
/// </summary>
27+
public string[] Errors { get; set; } = new string[0];
28+
public EZText()
29+
{
30+
ezCode = new EzCode();
31+
ezCode.Initialize();
32+
ezCode.Code ??= "";
33+
}
34+
public EZText(EzCode ezcode)
35+
{
36+
ezCode = ezcode;
37+
ezCode.Code ??= "";
38+
}
39+
public EZText(string code)
40+
{
41+
ezCode = new EzCode()
42+
{
43+
Code = code
44+
};
45+
}
46+
public string Translate() => Translate(ezCode.Code, ezCode.codeLine);
47+
public string Translate(string InputCode) => Translate(InputCode, ezCode.codeLine);
48+
public string Translate(int codeLine) => Translate(ezCode.Code, codeLine);
49+
public string Translate(string InputCode, int _codeLine)
50+
{
51+
try
52+
{
53+
CodeLine = _codeLine;
54+
string[] lines = InputCode.Split(Environment.NewLine).Select(x => x.Trim()).Where(y => !y.Equals("") && !y.StartsWith("//")).Select(z=>z
55+
.Replace("is equal to", "equals")
56+
.Replace(" equals ", " = ")
57+
.Replace("is greater than or equal to", ">=")
58+
.Replace("is less than or equal to", "<=")
59+
.Replace("is greater than", ">")
60+
.Replace("is less than", "<")
61+
.Replace(", then ", " then ")
62+
.Replace(" then ", " : ")
63+
).ToArray();
64+
for (int i = 0; i < lines.Length; i++)
65+
{
66+
CodeLine++;
67+
string line = lines[i];
68+
string[] words = line.Split(" ").Select(x => x.Trim()).Where(y => !y.Equals("")).ToArray();
69+
string first = words[0].ToLower();
70+
switch(first)
71+
{
72+
case "add":
73+
case "subtract":
74+
case "multiply":
75+
case "divide":
76+
try
77+
{
78+
string second = words[1], third = words[2].ToLower(), fourth = words[3];
79+
80+
bool by = first == "multiply" || first == "divide" ? true : false;
81+
82+
if (!by && (third == "to" || third == "from"))
83+
{
84+
Code += $"{fourth} {(first == "add" ? "+" : first == "subtract" ? "-" : "")} {second}";
85+
}
86+
else if (by && third == "by")
87+
{
88+
Code += $"{second} {(first == "multiply" ? "*" : first == "divide" ? "/" : "")} {fourth}";
89+
}
90+
else if (first == "add" && third != "to")
91+
{
92+
Error("Expected 'to' for English syntax 'Add X to Var'");
93+
}
94+
else if (first == "subtract" && third != "from")
95+
{
96+
Error("Expected 'to' for English syntax 'Subtract X from Var'");
97+
}
98+
else if (by && third != "by")
99+
{
100+
Error("Expected 'by' for English syntax 'Multiply Var by X'");
101+
}
102+
else
103+
{
104+
Error("Expected 'to', 'by', or 'from' for English Syntax, 'Multiply Var by X', 'Subtract X from Var', or 'Add X to Var'");
105+
}
106+
}
107+
catch
108+
{
109+
Error($"Error occured with '{first}'");
110+
}
111+
break;
112+
case "if":
113+
try
114+
{
115+
if (words[1] == "not" && words[2] == ":")
116+
{
117+
words[0] = "else";
118+
List<string> nw = words.ToList();
119+
nw.RemoveAt(1);
120+
words = nw.ToArray();
121+
}
122+
Code += string.Join(" ", words);
123+
}
124+
catch
125+
{
126+
Error($"Error occured with '{first}'");
127+
}
128+
break;
129+
default:
130+
if (words.Length > 1)
131+
{
132+
string second = words[1];
133+
if (second == "=")
134+
{
135+
string third = words[2];
136+
Code += $"{first} = {third}";
137+
break;
138+
}
139+
}
140+
Error($"Keyword {first} could not be found");
141+
Code += "// Error Occured with tranlateing this line: " + line;
142+
break;
143+
}
144+
Code += Environment.NewLine;
145+
}
146+
}
147+
catch
148+
{
149+
Error("Unhandled Error Occured");
150+
}
151+
return Code;
152+
}
153+
public void Error(string error)
154+
{
155+
Errors = Errors.Append($"{error} in EZText line {CodeLine}").ToArray();
156+
}
157+
}
158+
}

EZCode/EasierCode.cs

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)