* Tidy up first part of compiler code * Rename Net Compiler Options * Move CompilationErrors to Errors project * Return default constructor to compiler warning * Rename semantic check for include namespaces in unit * Create two Errors files instead of one in Errors project * Fix current unit is not main program check * Add documentation to compilation errors in Errors project * Return compiler thrown errors to Compiler project * Refactor keywords class - extract base keywords functionality * Fix keywords case sensitivity * Fix case sensitivity again... * Optimize keywords initialization * Fix parse expression error because of wrong constructor call
59 lines
2.4 KiB
C#
59 lines
2.4 KiB
C#
// Copyright (c) Ivan Bondarev, Stanislav Mikhalkovich (for details please see \doc\copyright.txt)
|
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
using System.Collections.Generic;
|
|
|
|
namespace PascalABCCompiler.Errors
|
|
{
|
|
public enum ErrorsStrategy { All=0, FirstOnly=1, FirstSemanticAndSyntax=2 };
|
|
public class ErrorsStrategyManager
|
|
{
|
|
public ErrorsStrategy Strategy;
|
|
|
|
public ErrorsStrategyManager(ErrorsStrategy Strategy)
|
|
{
|
|
this.Strategy = Strategy;
|
|
}
|
|
|
|
public List<PascalABCCompiler.Errors.Error> CreateErrorsList(List<PascalABCCompiler.Errors.Error> CompilerErrorsList)
|
|
{
|
|
List<PascalABCCompiler.Errors.Error> ErrorsList = new List<PascalABCCompiler.Errors.Error>();
|
|
switch (Strategy)
|
|
{
|
|
case ErrorsStrategy.All:
|
|
ErrorsList = CompilerErrorsList;
|
|
break;
|
|
case ErrorsStrategy.FirstOnly:
|
|
if (CompilerErrorsList.Count > 0)
|
|
ErrorsList.Add(CompilerErrorsList[0]);
|
|
break;
|
|
case ErrorsStrategy.FirstSemanticAndSyntax:
|
|
if (CompilerErrorsList.Count > 0)
|
|
{
|
|
ErrorsList.Add(CompilerErrorsList[0]);
|
|
bool syntax_add = ErrorsList[0] is PascalABCCompiler.Errors.SyntaxError;
|
|
bool semantic_add = ErrorsList[0] is PascalABCCompiler.Errors.SemanticError;
|
|
int i = 0;
|
|
while (i < CompilerErrorsList.Count && (!syntax_add || !semantic_add))
|
|
{
|
|
if (!syntax_add && CompilerErrorsList[i] is PascalABCCompiler.Errors.SyntaxError)
|
|
{
|
|
ErrorsList.Add(CompilerErrorsList[i]);
|
|
syntax_add = true;
|
|
}
|
|
if (!semantic_add && CompilerErrorsList[i] is PascalABCCompiler.Errors.SemanticError)
|
|
{
|
|
ErrorsList.Add(CompilerErrorsList[i]);
|
|
semantic_add = true;
|
|
}
|
|
i++;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
return ErrorsList;
|
|
}
|
|
|
|
|
|
}
|
|
}
|