Skip to content

Commit 04e3d64

Browse files
Made EZCode and Projects Class
1 parent 6525c9d commit 04e3d64

12 files changed

+219
-52
lines changed

EZCode/Debug.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static bool IsHit(Line line, Breakpoint[] breakpoints, Interpreter interp
3030
var point = breakpoints.FirstOrDefault(x => x.Line.FilePath == line.FilePath && x.Line.CodeLine == line.CodeLine);
3131
bool hit = point != null && point.Enabled;
3232

33-
if (hit)
33+
if (hit && point != null)
3434
{
3535
if (point.EZCodeConditionToHit != null)
3636
{

EZCode/EZCode.cs

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
namespace EZCodeLanguage
2+
{
3+
public class EZCode
4+
{
5+
public static string Version = "3.0.0-beta";
6+
public static void RunFileWithMain(string file)
7+
{
8+
Parser parser = new Parser(new FileInfo(Path.GetFullPath(file)));
9+
parser = Package.ReturnParserWithPackages(parser, ["main"]);
10+
Interpreter interpreter = new Interpreter(parser);
11+
interpreter.Interperate();
12+
}
13+
public static void RunFile(string file)
14+
{
15+
Parser parser = new Parser(new FileInfo(Path.GetFullPath(file)));
16+
parser.Parse();
17+
Interpreter interpreter = new Interpreter(parser);
18+
interpreter.Interperate();
19+
}
20+
public static void DebugFile(Debug.Breakpoint[] breakpoints, string file)
21+
{
22+
Parser parser = new Parser(new FileInfo(Path.GetFullPath(file)));
23+
parser.Parse();
24+
Interpreter interpreter = new Interpreter(parser, breakpoints);
25+
interpreter.Interperate();
26+
}
27+
public static void RunCode(string code, string path = "Running from inside program")
28+
{
29+
Parser parser = new Parser(code, path);
30+
parser.Parse();
31+
Interpreter interpreter = new Interpreter(parser);
32+
interpreter.Interperate();
33+
}
34+
public static void RunCodeWithMain(string code, string path = "Running from inside program")
35+
{
36+
Parser parser = new Parser(code, path);
37+
parser = Package.ReturnParserWithPackages(parser, ["main"]);
38+
Interpreter interpreter = new Interpreter(parser);
39+
interpreter.Interperate();
40+
}
41+
public static void DebugCodeWithMain(Debug.Breakpoint[] breakpoints, string code, string path = "Running from inside program")
42+
{
43+
Parser parser = new Parser(code, path);
44+
parser = Package.ReturnParserWithPackages(parser, ["main"]);
45+
Interpreter interpreter = new Interpreter(parser, breakpoints);
46+
interpreter.Interperate();
47+
}
48+
public static void RunProject(string path)
49+
{
50+
ProjectClass project = Project.GetProjectFromPath(path);
51+
Project.Run(project);
52+
}
53+
public static void DebugProject(Debug.Breakpoint[] breakpoints, string path)
54+
{
55+
ProjectClass project = Project.GetProjectFromPath(path);
56+
Parser par = Project.GetParserFromProject(project);
57+
Interpreter interpreter = new Interpreter(par, breakpoints);
58+
interpreter.Interperate();
59+
}
60+
}
61+
}

EZCode/EZHelp.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ public string Format(object _text, object _char)
7070
chars[i] == 'a' ? '@' :
7171
chars[i] == ';' ? ':' :
7272
chars[i] == 's' ? ';' :
73+
chars[i] == 'i' ? '!' :
7374
chars[i];
74-
if (chars[i] == '!')
75+
if (chars[i] == 'E')
7576
{
7677
chars = chars.ToList().Where((x, y) => y != i).ToArray();
7778
minus++;

EZCode/Interpreter.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace EZCodeLanguage
88
public class Interpreter
99
{
1010
public static Interpreter Instance { get; private set; }
11-
public static string Version = "3.0.0-beta";
1211
public event EventHandler OutputWrote;
1312
public event EventHandler OutputCleared;
1413
private string[] _output = [];
@@ -51,7 +50,7 @@ public string ConsoleInput()
5150
Input = null;
5251
return input;
5352
}
54-
public bool ContinueOnBreakpoint;
53+
public bool ContinuedForBreakpoint = false;
5554
public Parser parser { get; set; }
5655
public EZHelp EZHelp { get; private set; }
5756
public Interpreter(Parser parser, Debug.Breakpoint[]? breakpoints = null)
@@ -193,10 +192,11 @@ public void Interperate(LineWithTokens[] LineTokens)
193192
if (!duplicate_stack) StackTrace.Push(message);
194193
CurrentLine = line.Line;
195194

196-
while (Breakpoints != null && Debug.IsHit(line.Line, Breakpoints, this))
195+
while (Breakpoints != null && Debug.IsHit(line.Line, Breakpoints, this) && !ContinuedForBreakpoint)
197196
{
198197
Task.Delay(100);
199198
}
199+
ContinuedForBreakpoint = false;
200200

201201
Token FirstToken = line.Tokens.FirstOrDefault(new Token(TokenType.None, "", ""));
202202
object? Return = null;
@@ -208,7 +208,7 @@ public void Interperate(LineWithTokens[] LineTokens)
208208
{
209209
string combined_packages = string.Join(" ", line.Tokens.Skip(1).Select(x => x.StringValue));
210210
string[] packages = combined_packages.Split(",").Select(x=>x.Trim()).ToArray();
211-
Project[] projects = new Project[packages.Length];
211+
PackageClass[] projects = new PackageClass[packages.Length];
212212
bool include = FirstToken.StringValue == "include";
213213

214214
for (int i = 0; i < packages.Length; i++)

EZCode/Package.cs

+17-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,22 @@
22

33
namespace EZCodeLanguage
44
{
5+
public class PackageClass
6+
{
7+
public string Name { get; set; }
8+
public string[] Files { get; set; }
9+
public Config? Configuration { get; set; }
10+
public class Config
11+
{
12+
public string? LibraryDirectory { get; set; }
13+
public string[]? GlobalPackages { get; set; }
14+
}
15+
}
16+
517
public static class Package
618
{
719
public static string PackagesDirectory = "D:\\EZCodeLanguage\\Packages\\";
8-
public static void AddPackageToExecutionDirectory(Project project, string executionDirectory)
20+
public static void AddPackageToExecutionDirectory(PackageClass project, string executionDirectory)
921
{
1022
string projectPath = GetPackageDirectory(project.Name);
1123
string libraryDirectory = Path.Combine(projectPath, project.Configuration?.LibraryDirectory ?? throw new Exception("Project.LibraryDirectory is null"));
@@ -22,7 +34,7 @@ public static void AddPackageToExecutionDirectory(Project project, string execut
2234
File.Copy(libraryFile, executionSubDirectoryFile);
2335
}
2436
}
25-
public static void RemovePackageFromExecutionDirectory(Project project, string executionDirectory)
37+
public static void RemovePackageFromExecutionDirectory(PackageClass project, string executionDirectory)
2638
{
2739
string libraryDirectory = project.Configuration?.LibraryDirectory ?? throw new Exception("Project.LibraryDirectory is null");
2840
string executionSubDirectory = Path.Combine(executionDirectory, libraryDirectory);
@@ -52,15 +64,15 @@ public static string GetPackageFile(string package_name)
5264
{
5365
return Path.Combine(PackagesDirectory, package_name, "package.json");
5466
}
55-
public static Project GetPackageAsProject(string package_name)
67+
public static PackageClass GetPackageAsProject(string package_name)
5668
{
57-
return JsonConvert.DeserializeObject<Project>(File.ReadAllText(GetPackageFile(package_name)));
69+
return JsonConvert.DeserializeObject<PackageClass>(File.ReadAllText(GetPackageFile(package_name)));
5870
}
5971
public static Parser GetPackageAsParser(string package_name)
6072
{
6173
string file = GetPackageFile(package_name);
6274
string pack_dir = GetPackageDirectory(package_name);
63-
Project project = JsonConvert.DeserializeObject<Project>(File.ReadAllText(file));
75+
PackageClass project = JsonConvert.DeserializeObject<PackageClass>(File.ReadAllText(file));
6476
string[] global_packages = project.Configuration != null ? project.Configuration.GlobalPackages ?? [] : [];
6577
Parser[] parsers = [];
6678
foreach (var pack in global_packages)

EZCode/Parser.cs

+7
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,13 @@ public Parser(string code, string file)
438438
Code = code;
439439
FilePath = file;
440440
}
441+
public Parser(FileInfo file)
442+
{
443+
string code = File.ReadAllText(file.FullName);
444+
string path = file.FullName;
445+
Code = code;
446+
FilePath = path;
447+
}
441448
public LineWithTokens[] Parse()
442449
{
443450
var parse = LinesWithTokens = TokenArray(Code, FilePath).Where(x => x.Line.Value.ToString() != "").ToArray();

EZCode/Project.cs

+40-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,48 @@
1-
namespace EZCodeLanguage
1+
using Newtonsoft.Json;
2+
3+
namespace EZCodeLanguage
24
{
3-
public class Project
5+
public class ProjectClass
46
{
57
public string Name { get; set; }
68
public string[] Files { get; set; }
7-
public Config? Configuration { get; set; }
8-
public class Config
9+
public string[]? GlobalPackages { get; set; }
10+
}
11+
public static class Project
12+
{
13+
public static ProjectClass GetProjectFromPath(string path)
14+
{
15+
string content = File.ReadAllText(path);
16+
ProjectClass project = JsonConvert.DeserializeObject<ProjectClass>(content);
17+
return project;
18+
}
19+
public static Parser GetParserFromProject(ProjectClass project)
20+
{
21+
Parser[] parsers = new Parser[project.Files.Length];
22+
for (int i = 0; i < parsers.Length; i++)
23+
{
24+
parsers[i] = new Parser(new FileInfo(project.Files[i]));
25+
parsers[i].Parse();
26+
}
27+
Parser p = Package.CombineParsers(parsers);
28+
return IncludeGlobalPackages(p, project);
29+
}
30+
public static Parser IncludeGlobalPackages(Parser parser, ProjectClass project)
31+
{
32+
Parser[] parsers = new Parser[project.GlobalPackages.Length];
33+
for (int i = 0; i < parsers.Length; i++)
34+
{
35+
parsers[i] = Package.GetPackageAsParser(project.GlobalPackages[i]);
36+
parsers[i].Parse();
37+
}
38+
parsers = [parser, .. parsers];
39+
return Package.CombineParsers(parsers);
40+
}
41+
public static void Run(ProjectClass project)
942
{
10-
public string? LibraryDirectory { get; set; }
11-
public string[]? GlobalPackages { get; set; }
43+
Parser par = GetParserFromProject(project);
44+
Interpreter interpreter = new Interpreter(par);
45+
interpreter.Interperate();
1246
}
1347
}
1448
}

TestEnv/Code.ezcode

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
include main
1+
method start {
2+
print Hello, World\i
3+
}

TestEnv/FirstProject.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Name": "First Project",
3+
"Files": [
4+
"Code.ezcode"
5+
],
6+
"GlobalPackages": [
7+
"main"
8+
]
9+
}

TestEnv/Program.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using EZCodeLanguage;
22
using System.Diagnostics;
33

4+
/*
45
// set up files variables
56
string path = "Code.ezcode";
67
string full_path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path);
@@ -16,7 +17,7 @@
1617
1718
// breakpoints
1819
EZCodeLanguage.Debug.Breakpoint[] breakpoints = [
19-
//new EZCodeLanguage.Debug.Breakpoint(lines[2].Line)
20+
//new EZCodeLanguage.Debug.Breakpoint(parser.LinesWithTokens[2].Line)
2021
];
2122
2223
// print code and file
@@ -42,3 +43,7 @@
4243
stopwatch.Stop();
4344
long mili = stopwatch.ElapsedMilliseconds;
4445
Console.WriteLine(len + "\n" + "Parser Miliseconds:" + Omili.ToString() + "\nInterperate Miliseconds:" + mili.ToString() + "\nOverall Miliseconds:" + (Omili + mili).ToString());
46+
*/
47+
48+
// or
49+
EZCode.RunProject("FirstProject.json");

TestEnv/TestEnv.csproj

+6-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@
2828

2929
<ItemGroup>
3030
<None Update="Code.ezcode">
31-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
31+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
32+
</None>
33+
<None Update="FirstProject.json">
34+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3235
</None>
3336
</ItemGroup>
3437

38+
<ProjectExtensions><VisualStudio><UserProperties /></VisualStudio></ProjectExtensions>
39+
3540
</Project>

0 commit comments

Comments
 (0)