Skip to content

Commit 2c0bcaf

Browse files
added stuff for the PlasticCMD Compiler
1 parent e74a799 commit 2c0bcaf

File tree

5 files changed

+77
-25
lines changed

5 files changed

+77
-25
lines changed

Helpers/BMAM.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
1+
using System.Text;
62

73
namespace Plastic.Helpers
84
{

Helpers/JSONSerializer.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Runtime.Serialization.Json;
1+
using System.Runtime.Serialization.Json;
52
using System.Text;
6-
using System.Threading.Tasks;
73

84
namespace Plastic.Helpers
95
{

Helpers/SHA256.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
1+
using System.Text;
62

73
namespace Plastic.Helpers
84
{

Helpers/StringBuilder.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
7-
namespace Plastic.Helpers
1+
namespace Plastic.Helpers
82
{
93
public class StringBuilder
104
{

PlasticEngine.cs

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ public bool CheckOwnership(string varName, string expectedOwner)
386386
}
387387

388388
private OwnershipTracker _ownership = new();
389+
public List<string> Errors { get; private set; } = new List<string>();
389390

390391
public ProgramNode Parse()
391392
{
@@ -401,10 +402,11 @@ public ProgramNode Parse()
401402
}
402403
catch (Exception ex)
403404
{
404-
Console.WriteLine($"Error in Parse: {ex.Message}");
405-
Console.WriteLine($"Current token: {Peek().Type} {Peek().Lexeme}");
406-
407405
Synchronize();
406+
407+
Errors.Add("Error at line " + _tokens[_current].Line + ": " + ex.Message);
408+
409+
return null;
408410
}
409411
}
410412

@@ -3275,6 +3277,74 @@ private void RegisterBuiltins()
32753277
}), "void");
32763278
}
32773279

3280+
public List<string> GetErrors(string source, bool readPlugins = true)
3281+
{
3282+
var errors = new List<string>();
3283+
try
3284+
{
3285+
var lexer = new Lexer(source);
3286+
List<Token> tokens;
3287+
try
3288+
{
3289+
tokens = lexer.ScanTokens();
3290+
}
3291+
catch (Exception lexEx)
3292+
{
3293+
errors.Add($"Lexer error: {lexEx.Message}");
3294+
return errors;
3295+
}
3296+
3297+
var parser = new Parser(tokens);
3298+
ProgramNode program;
3299+
try
3300+
{
3301+
parser._current = 0;
3302+
program = parser.Parse();
3303+
if(program == null)
3304+
{
3305+
foreach(string error in parser.Errors)
3306+
{
3307+
errors.Add(error);
3308+
}
3309+
return errors;
3310+
}
3311+
}
3312+
catch (Exception parseEx)
3313+
{
3314+
errors.Add($"Parser error: {parseEx.Message}");
3315+
return errors;
3316+
}
3317+
3318+
if (readPlugins)
3319+
{
3320+
try
3321+
{
3322+
ProcessImports(program);
3323+
}
3324+
catch (Exception importEx)
3325+
{
3326+
errors.Add($"Import error: {importEx.Message}");
3327+
return errors;
3328+
}
3329+
}
3330+
3331+
try
3332+
{
3333+
var checker = new TypeChecker();
3334+
checker.Check(program);
3335+
}
3336+
catch (Exception typeEx)
3337+
{
3338+
errors.Add($"Type error: {typeEx.Message}");
3339+
}
3340+
}
3341+
catch (Exception ex)
3342+
{
3343+
errors.Add($"Unknown error: {ex.Message}");
3344+
}
3345+
return errors;
3346+
}
3347+
32783348
public void WorkingCreateGlobal(string name, object value, object typeReturn)
32793349
{
32803350
ArgumentNullException.ThrowIfNull(name);

0 commit comments

Comments
 (0)