Exemple #1
0
        public ParsingResult Parse(string code, AlgoType algotype, File[] includeFiles)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var parsingErrors = new ParsingErrors();

            var algo = new Algo
                {
                    Mq4Code = code, 
                    AlgoType = algotype
                };
            string[] customIndicators;

            code = code
                .RemoveComments()
                .IncludeFiles(includeFiles)
                .HandleParsingErrors(parsingErrors);

            if (parsingErrors.Errors.Any(error => error.ErrorType >= ErrorType.NotSupportedCriticalError))
                return new ParsingResult(algo, parsingErrors.Errors);
            
            code = code
                .ReplaceDateTimeToInt()
                .ReplaceDateConstants()
                .ReplaceDefines()
                .ReplaceCSharpKeyWords()
                .RemoveDotsFromNames()
                .AddZeroToDecimalNumbers()
                .ReplaceUnknownSymbols()
                .ReplaceMq4RgbColorsToKnownColors()
                .ReplaceColorToInt()
                .ReplaceCAlgoKeyWords()
                .ReplacePrintToMq4Print()
                .RenameFunctions()
                .AddRefModifiers()
                .AddTypeParameterToICustom(out customIndicators);

            HandleProperties(code, algo);
            HandleParameters(code, algo);
            HandleFunctions(code, algo, parsingErrors);
            HandleFields(code, algo);

            algo.Code.ExtractStaticVariablesToFields();
            algo.Code.ReplaceSimpleTypesToMq4Types();
            algo.Code.RenameStandardFunctions();
            algo.Code.AddMq4InitFunctionIfDoesNotExist();
            algo.CustomIndicators = customIndicators;

            return new ParsingResult(algo, parsingErrors.Errors);
        }
Exemple #2
0
 public static string IncludeFiles(this string codeWithoutComments, File[] includeFiles)
 {
     var code = codeWithoutComments;
     foreach (var match in IncludeRegex.Matches(code).OfType<Match>())
     {
         var fileName = match.Groups["fileName"].Value;
         if (NotStandard(fileName))
         {
             var file = includeFiles.First(f => f.Name == fileName);
             var adaptedCode = file.Mq4Code.RemoveComments();
             
             code = code.Replace(match.Value, adaptedCode);
         }
         else
         {
             code = code.Replace(match.Value, string.Empty);
         }
     }
     return code;
 }