* Implement first version of languages interfaces and classes ParsersController заменен на LanguageProvider. * Update ParserTools.csproj * Update RemoteCompiler.cs * Update TestRunner * Rename LanguageIntegrator project to Languages * Update TestRunner * Rename Parsers folder * Rename PascalABCParser.dll to PascalABCLanguage.dll * Reorganise LanguageIntegrator and rename DocTagsParser * Update Release Generators * Update language loading messages * Update linux version * Move BaseParser fields to ILanguage interface * Revert "Update Release Generators" This reverts commit 26a991c71b81e643d9fbd9a815ddca222768dda9. * Revert "Rename PascalABCParser.dll to PascalABCLanguage.dll" * Clean the mess in parser folders * Organize namespaces properly * Revert "Rename LanguageIntegrator project to Languages" * Add new enclosing folders for standard languages * Organize namespaces of LanguageIntegrator properly * Rename StandardLanguages to Languages * Comment the rest of Visual basic source code * Update OutputPath in pascal parser project * Move BaseParser methods to IParser * Restore Pascal parser project initial structure * Add PascalLanguage project * Move SyntaxTreeConverters project to Languages\Pascal folder * Rename SemanticRules in parser project * Rename Errors1 to Errors in parser project * Delete LambdaConverter dll from installer * Update language integrator to load *Language.dll files * Move lambda converter project to pascal lanuage dir * Revert "Delete LambdaConverter dll from installer" This reverts commit dd56f559ebe4f8c4c5c33752d44e6953001b96a5. * Switch off VBNETParser building * Delete syntax tree converters controller * Delete lambda converter dll from repository * Reorganize syntax tree to semantic tree conversion stage * Add BaseLanguage class to make language initialization more neat * Delete syntax tree post processors entity from ILanguage and refactor ABCStatistics calls * Add new IDocParser interface for documentation comments parser * Clean up folders * Add helper data structures to reduce parameters amount in CompileInterface and CompileImplementation * Add documentation to language classes * Move Union struct in global namespace and project (ParserTools) * Add more comments and a safe select language method * Rename SemanticRules class * Fix directives format null bug * Add System.Linq ref to LanguageIntegrator * Delete SyntaxToSemanticTreeConverter interface * Add BaseSyntaxTreeConverter * Call safe select language method in intellisence * Delete source files providers from parsers * Rename GetSyntaxTree method * Change Prebuild tree to be virtual - not abstract * Refresh documentation a bit * Add temporary language check for ABCHealth button * Add parser reference to parser tools * Move current compilation unit assigning higher to avoid bug with unit check * Delete null DirectiveInfo's and refactor directives' code * Add a few more comments
183 lines
4.2 KiB
C#
183 lines
4.2 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Reflection;
|
|
using GPPGTools;
|
|
using PascalABCCompiler;
|
|
using PascalABCCompiler.SyntaxTree;
|
|
using PascalABCCompiler.Parsers;
|
|
using PascalABCCompiler.Errors;
|
|
using System.Collections.Generic;
|
|
|
|
|
|
namespace PascalABCCompiler.PythonABCParser
|
|
{
|
|
public class PythonLanguageParser : IParser
|
|
{
|
|
private Parser parser = new Parser();
|
|
|
|
public PythonLanguageParser()
|
|
{
|
|
filesExtensions = new string[1];
|
|
filesExtensions[0] = ".py";
|
|
}
|
|
|
|
string[] filesExtensions;
|
|
public string[] FilesExtensions
|
|
{
|
|
get
|
|
{
|
|
return filesExtensions;
|
|
}
|
|
}
|
|
|
|
public ILanguageInformation LanguageInformation
|
|
{
|
|
get
|
|
{
|
|
return new DefaultLanguageInformation(this);
|
|
}
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
GPPGParser.max_errors = 30;
|
|
GPPGParser.CompilationUnit = null;
|
|
GPPGParser.errors = Errors;
|
|
//GPPGParser.CompilerDirectives = new List<compiler_directive>();
|
|
}
|
|
|
|
public bool CaseSensitive
|
|
{
|
|
get
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public List<compiler_directive> compilerDirectives = new List<compiler_directive>();
|
|
public List<compiler_directive> CompilerDirectives
|
|
{
|
|
get
|
|
{
|
|
return compilerDirectives;
|
|
}
|
|
}
|
|
|
|
SourceFilesProviderDelegate sourceFilesProvider = null;
|
|
public SourceFilesProviderDelegate SourceFilesProvider
|
|
{
|
|
get
|
|
{
|
|
return sourceFilesProvider;
|
|
}
|
|
set
|
|
{
|
|
sourceFilesProvider = value;
|
|
}
|
|
}
|
|
|
|
List<Error> errors = new List<Error>();
|
|
public List<Error> Errors
|
|
{
|
|
get
|
|
{
|
|
return errors;
|
|
}
|
|
set
|
|
{
|
|
errors = value;
|
|
}
|
|
}
|
|
|
|
public Keyword[] Keywords
|
|
{
|
|
get
|
|
{
|
|
return new Keyword[0];
|
|
}
|
|
}
|
|
|
|
public syntax_tree_node BuildTree(string FileName, string Text, ParseMode ParseMode)
|
|
{
|
|
//if (parser == null)
|
|
Reset();
|
|
|
|
GPPGParser.current_file_name = FileName;
|
|
GPPGParser.CompilerDirectives = compilerDirectives;
|
|
|
|
Scanner scn = new Scanner();
|
|
scn.SetSource(Text, 0);
|
|
|
|
parser.scanner = scn;
|
|
|
|
bool b = parser.Parse();
|
|
|
|
if (!b)
|
|
{
|
|
// if we can't recognize error :( or brain.dll not loaded
|
|
Errors.ErrorMsg err = new Errors.ErrorMsg(GPPGParser.current_file_name,new SourceContext(0,0,0,0),"PROGRAM_ERROR");
|
|
GPPGParser.errors.Add(err);
|
|
}
|
|
|
|
Errors = GPPGParser.errors;
|
|
|
|
syntax_tree_node cu = null;
|
|
|
|
switch (ParseMode)
|
|
{
|
|
case ParseMode.Normal:
|
|
cu = GPPGParser.CompilationUnit;
|
|
break;
|
|
case ParseMode.Expression:
|
|
case ParseMode.Statement:
|
|
return null;
|
|
}
|
|
|
|
if (cu != null && cu is compilation_unit)
|
|
{
|
|
(cu as compilation_unit).file_name = FileName;
|
|
(cu as compilation_unit).compiler_directives = CompilerDirectives;
|
|
}
|
|
return cu;
|
|
}
|
|
|
|
public string Name
|
|
{
|
|
get
|
|
{
|
|
return "PythonABC";
|
|
}
|
|
}
|
|
|
|
public string Version
|
|
{
|
|
get
|
|
{
|
|
return "0.1";
|
|
}
|
|
}
|
|
|
|
public string Copyright
|
|
{
|
|
get
|
|
{
|
|
return "(c) Andrew Podkovyrin, 2009";
|
|
}
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return "Python Language Parser v" + Version;
|
|
}
|
|
|
|
public IPreprocessor Preprocessor
|
|
{
|
|
get
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|