コード例 #1
0
ファイル: Mq4Parser.cs プロジェクト: matiasev/2calgo.Library
 private void HandleFunctions(string code, Algo algo, ParsingErrors parsingErrors)
 {
     var withoutProperties = code.RemoveMq4Properies();
     var mq4Functions = FunctionsParser.Parse(withoutProperties).ToArray();
     algo.Code.Functions = mq4Functions.ToList();
     HandleInit(algo, mq4Functions, parsingErrors);
 }
コード例 #2
0
         public static string HandleParsingErrors(this string code, ParsingErrors parsingErrors)
         {
             foreach (var errorDetector in ErrorDetectors)
             {
                 foreach (var error in errorDetector.FindErrors(code))
                     parsingErrors.Add(error);
             }

             return code;
         }
コード例 #3
0
        public static string HandleParsingErrors(this string code, ParsingErrors parsingErrors)
        {
            foreach (var errorDetector in ErrorDetectors)
            {
                foreach (var error in errorDetector.FindErrors(code))
                {
                    parsingErrors.Add(error);
                }
            }

            return(code);
        }
コード例 #4
0
ファイル: Mq4Parser.cs プロジェクト: matiasev/2calgo.Library
        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);
        }
コード例 #5
0
ファイル: Mq4Parser.cs プロジェクト: matiasev/2calgo.Library
        private void HandleInit(Algo algo, IEnumerable<Function> mq4Functions, ParsingErrors parsingErrors)
        {
            var initFunction = mq4Functions.FirstOrDefault(function => function.Name == "init");

            if (initFunction == null)
                return;

            var methodCalls = MethodCallsParser.Parse(initFunction.Body).ToArray();

            HandleBufferIndexes(methodCalls, algo);
            HandleLevels(methodCalls, algo);
            HandleIndexStyles(methodCalls, algo, parsingErrors);
        }
コード例 #6
0
ファイル: Mq4Parser.cs プロジェクト: matiasev/2calgo.Library
        private static void HandleIndexStyles(MethodCall[] methodCalls, Algo algo, ParsingErrors parsingErrors)
        {
            var setIndexStyleCalls = methodCalls.Where(call => call.MethodName == "SetIndexStyle");
            var indexesStyles = new Dictionary<int, DrawingShapeStyle>();
            foreach (var methodCall in setIndexStyleCalls)
            {
                int index;
                if (!int.TryParse(methodCall.Parameters[0], out index))
                {
                    parsingErrors.Add(ErrorType.NotSupportedWarning, "SetIndexStyle", "Can't cast to int: " + methodCall.Parameters[0]);
                    continue;
                }
                var drawingShapeStyle = methodCall.Parameters[1].ToDrawingShapeStyle();
                indexesStyles[index] = drawingShapeStyle;

                if (methodCall.Parameters.Length >= 4)
                {
                    int width;
                    if (int.TryParse(methodCall.Parameters[3], out width))
                        algo.Widths[index] = width;
                }
            }
            foreach (var keyValuePair in indexesStyles)
            {
                algo.Styles[keyValuePair.Key] = keyValuePair.Value;
            }
        }