Exemplo n.º 1
0
        private static Result <FreezableStepProperty, IError> TryParse(string text)
        {
            var inputStream       = new AntlrInputStream(text);
            var lexer             = new SCLLexer(inputStream);
            var commonTokenStream = new CommonTokenStream(lexer);
            var parser            = new SCLParser(commonTokenStream);

            var syntaxErrorListener = new SyntaxErrorListener();

            parser.AddErrorListener(syntaxErrorListener);

            var visitor = new Visitor();

            var result = visitor.Visit(parser.fullSequence());

            if (result.IsFailure)
            {
                return(result);
            }

            if (syntaxErrorListener.Errors.Any())
            {
                return(Result.Failure <FreezableStepProperty, IError>(
                           ErrorList.Combine(syntaxErrorListener.Errors)
                           ));
            }

            return(result);
        }
Exemplo n.º 2
0
 void ILSLSyntaxErrorListener.InvalidPrefixOperationUsedInStaticContext(LSLSourceCodeRange location,
                                                                        LSLPrefixOperationType type)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () =>
                               SyntaxErrorListener.InvalidPrefixOperationUsedInStaticContext(location, type));
 }
        private IParseTree ReadAST()
        {
            var code        = textEditor.Text;
            var inputStream = new AntlrInputStream(code);
            var lexer       = new DDD_layout_scriptLexer(inputStream);
            //lexer.RemoveErrorListeners();



            var tokenStream         = new CommonTokenStream(lexer);
            var parser              = new DDD_layout_scriptParser(tokenStream);
            var syntaxErrorListener = new SyntaxErrorListener();

            parser.RemoveErrorListeners();
            parser.AddErrorListener(syntaxErrorListener);
            var context = parser.program();
            List <ErrorPaneRow> rows = new List <ErrorPaneRow>();
            var syntaxAlerts         = syntaxErrorListener.GetAlerts();

            foreach (var alert in syntaxAlerts)
            {
                rows.Add(new ErrorPaneRow(alert.GetAlertType(), alert.LineNumber, alert.Msg));
            }
            ErrorPane.ItemsSource = rows;
            if (syntaxAlerts.Count != 0)
            {
                return(null);
            }
            return(context);
        }
Exemplo n.º 4
0
 void ILSLSyntaxErrorListener.PrefixOperationOnGlobalVariableInStaticContext(LSLSourceCodeRange location,
                                                                             LSLPrefixOperationType type)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () =>
                               SyntaxErrorListener.PrefixOperationOnGlobalVariableInStaticContext(location, type));
 }
Exemplo n.º 5
0
 void ILSLSyntaxErrorListener.PostfixOperationOnNonVariable(LSLSourceCodeRange location,
                                                            LSLPostfixOperationType type)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () =>
                               SyntaxErrorListener.PostfixOperationOnNonVariable(location, type));
 }
Exemplo n.º 6
0
 void ILSLSyntaxErrorListener.InvalidTupleComponentAccessOperation(LSLSourceCodeRange location,
                                                                   ILSLReadOnlyExprNode exprLvalue,
                                                                   string memberAccessed)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () => SyntaxErrorListener.InvalidTupleComponentAccessOperation(location, exprLvalue, memberAccessed));
 }
Exemplo n.º 7
0
 void ILSLSyntaxErrorListener.TypeMismatchInVariableDeclaration(LSLSourceCodeRange location, LSLType variableType,
                                                                ILSLReadOnlyExprNode assignedExpression)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () =>
                               SyntaxErrorListener.TypeMismatchInVariableDeclaration(location, variableType, assignedExpression));
 }
Exemplo n.º 8
0
 void ILSLSyntaxErrorListener.InvalidBinaryOperation(LSLSourceCodeRange location, ILSLReadOnlyExprNode left,
                                                     string operation,
                                                     ILSLReadOnlyExprNode right)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () => SyntaxErrorListener.InvalidBinaryOperation(location, left, operation, right));
 }
Exemplo n.º 9
0
 void ILSLSyntaxErrorListener.RedefinedStandardLibraryFunction(LSLSourceCodeRange location, string functionName,
                                                               IReadOnlyGenericArray <ILSLFunctionSignature> libraryFunctionSignatureOverloads)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () =>
                               SyntaxErrorListener.RedefinedStandardLibraryFunction(location, functionName,
                                                                                    libraryFunctionSignatureOverloads));
 }
Exemplo n.º 10
0
 void ILSLSyntaxErrorListener.GrammarLevelParserSyntaxError(int line, int column,
                                                            LSLSourceCodeRange offendingTokenRange, string offendingTokenText, string message)
 {
     _errorActionQueue.Enqueue(line,
                               () =>
                               SyntaxErrorListener.GrammarLevelParserSyntaxError(line, column, offendingTokenRange,
                                                                                 offendingTokenText, message));
 }
Exemplo n.º 11
0
 void ILSLSyntaxErrorListener.IncorrectEventHandlerSignature(LSLSourceCodeRange location,
                                                             ILSLEventSignature givenEventHandlerSignature,
                                                             ILSLEventSignature correctEventHandlerSignature)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () =>
                               SyntaxErrorListener.IncorrectEventHandlerSignature(location, givenEventHandlerSignature,
                                                                                  correctEventHandlerSignature));
 }
Exemplo n.º 12
0
 void ILSLSyntaxErrorListener.TupleComponentAccessOnLibraryConstant(LSLSourceCodeRange location,
                                                                    ILSLVariableNode libraryConstantReferenceNode,
                                                                    ILSLConstantSignature libraryConstantSignature, string accessedMember)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () =>
                               SyntaxErrorListener.TupleComponentAccessOnLibraryConstant(location, libraryConstantReferenceNode,
                                                                                         libraryConstantSignature, accessedMember));
 }
Exemplo n.º 13
0
 void ILSLSyntaxErrorListener.NoSuitableLibraryFunctionOverloadFound(LSLSourceCodeRange location,
                                                                     string functionName,
                                                                     IReadOnlyGenericArray <ILSLReadOnlyExprNode> givenParameterExpressions)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () =>
                               SyntaxErrorListener.NoSuitableLibraryFunctionOverloadFound(location, functionName,
                                                                                          givenParameterExpressions));
 }
Exemplo n.º 14
0
 void ILSLSyntaxErrorListener.RedefinedStandardLibraryConstant(LSLSourceCodeRange location,
                                                               LSLType redefinitionType,
                                                               ILSLConstantSignature originalSignature)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () =>
                               SyntaxErrorListener.RedefinedStandardLibraryConstant(location, redefinitionType,
                                                                                    originalSignature));
 }
Exemplo n.º 15
0
 void ILSLSyntaxErrorListener.ParameterTypeMismatchInFunctionCall(LSLSourceCodeRange location,
                                                                  int parameterIndexWithError,
                                                                  ILSLFunctionSignature calledFunction, ILSLReadOnlyExprNode[] parameterExpressionsGiven)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () =>
                               SyntaxErrorListener.ParameterTypeMismatchInFunctionCall(location, parameterIndexWithError,
                                                                                       calledFunction, parameterExpressionsGiven));
 }
Exemplo n.º 16
0
 void ILSLSyntaxErrorListener.ImproperParameterCountInFunctionCall(LSLSourceCodeRange location,
                                                                   ILSLFunctionSignature functionSignature,
                                                                   ILSLReadOnlyExprNode[] parameterExpressionsGiven)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () =>
                               SyntaxErrorListener.ImproperParameterCountInFunctionCall(location, functionSignature,
                                                                                        parameterExpressionsGiven));
 }
Exemplo n.º 17
0
 void ILSLSyntaxErrorListener.TypeMismatchInReturnValue(LSLSourceCodeRange location,
                                                        ILSLFunctionSignature functionSignature,
                                                        ILSLReadOnlyExprNode attemptedReturnExpression)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () =>
                               SyntaxErrorListener.TypeMismatchInReturnValue(location, functionSignature,
                                                                             attemptedReturnExpression));
 }
Exemplo n.º 18
0
 void ILSLSyntaxErrorListener.CallToOverloadedLibraryFunctionIsAmbiguous(LSLSourceCodeRange location,
                                                                         string functionName,
                                                                         IReadOnlyGenericArray <ILSLFunctionSignature> ambiguousMatches,
                                                                         IReadOnlyGenericArray <ILSLReadOnlyExprNode> givenParameterExpressions)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () =>
                               SyntaxErrorListener.CallToOverloadedLibraryFunctionIsAmbiguous(location, functionName,
                                                                                              ambiguousMatches, givenParameterExpressions));
 }
Exemplo n.º 19
0
        public static ViGaSParser GetParserForScript(string script, out List <Error> errors)
        {
            var inputStream         = new AntlrInputStream(script);
            var lexer               = new ViGaSLexer(inputStream);
            var tokenStream         = new CommonTokenStream(lexer);
            var parser              = new ViGaSParser(tokenStream);
            var syntaxErrorListener = new SyntaxErrorListener();

            parser.AddErrorListener(syntaxErrorListener);
            errors = syntaxErrorListener.errors;
            return(parser);
        }
        private List <SyntaxError> ParseAndReturnErrors(string input)
        {
            AntlrInputStream    inputStream       = new AntlrInputStream(input);
            CsharpSubsetLexer   lexer             = new CsharpSubsetLexer(inputStream);
            CommonTokenStream   commonTokenStream = new CommonTokenStream(lexer);
            CsharpSubsetParser  parser            = new CsharpSubsetParser(commonTokenStream);
            SyntaxErrorListener listener          = new SyntaxErrorListener();

            parser.AddErrorListener(listener);
            CsharpSubsetParser.ProgramContext programContext = parser.program();
            return(listener.SyntaxErrors);
        }
Exemplo n.º 21
0
        public static IParseTree MakeParseTree(string script, out List <Error> errors)
        {
            var inputStream         = new AntlrInputStream(script);
            var lexer               = new ViGaSLexer(inputStream);
            var tokenStream         = new CommonTokenStream(lexer);
            var parser              = new ViGaSParser(tokenStream);
            var syntaxErrorListener = new SyntaxErrorListener();

            parser.AddErrorListener(syntaxErrorListener);
            var context = parser.script();

            errors = syntaxErrorListener.errors;
            return(context);
        }
Exemplo n.º 22
0
        public void Error_on_empty_from_query()
        {
            var parser = new QueryParser(new CommonTokenStream(new QueryLexer(new AntlrInputStream("from"))));

            parser.AddErrorListener(_errorListener);
            parser.query();
            Assert.Single(_errorListener.Errors);
            Assert.Contains("index or collection name", _errorListener.Errors[0].Message);

            _errorListener = new SyntaxErrorListener();
            parser         = new QueryParser(new CommonTokenStream(new QueryLexer(new AntlrInputStream("from foobar"))));
            parser.query();
            Assert.Empty(_errorListener.Errors);
        }
Exemplo n.º 23
0
        public void Error_on_missing_index_name()
        {
            var parser = new QueryParser(new CommonTokenStream(new QueryLexer(new AntlrInputStream("from index"))));

            parser.AddErrorListener(_errorListener);
            parser.query();
            Assert.Single(_errorListener.Errors);
            Assert.Contains("index name", _errorListener.Errors[0].Message);

            _errorListener = new SyntaxErrorListener();
            parser         = new QueryParser(new CommonTokenStream(new QueryLexer(new AntlrInputStream("from index 'foo/bar'"))));
            parser.AddErrorListener(_errorListener);
            parser.query();
            Assert.Empty(_errorListener.Errors);
        }
Exemplo n.º 24
0
        private IParseTree Parse(string zenContent)
        {
            string[] fileContentLines = zenContent.Split(Environment.NewLine);
            _filesContentsLines.Add(fileContentLines);

            AntlrInputStream    inputStream         = new AntlrInputStream(zenContent);
            ZenLexer            lexer               = new ZenLexer(inputStream);
            CommonTokenStream   commonTokenStream   = new CommonTokenStream(lexer);
            ZenParser           parser              = new ZenParser(commonTokenStream);
            SyntaxErrorListener syntaxErrorListener = new SyntaxErrorListener();

            parser.RemoveErrorListeners();
            parser.AddErrorListener(syntaxErrorListener);
            IParseTree parseTree = parser.main();

            _syntaxErrorsCount += syntaxErrorListener.SyntaxErrors.Count;
            _syntaxErrorsPerFile.Add(syntaxErrorListener.SyntaxErrors);
            return(parseTree);
        }
Exemplo n.º 25
0
        private void ParseCode(string codeString)
        {
            InputStream       = new AntlrInputStream(codeString);
            Lexer             = new CsharpSubsetLexer(InputStream);
            CommonTokenStream = new CommonTokenStream(Lexer);
            Parser            = new CsharpSubsetParser(CommonTokenStream);
            SyntaxErrorListener errorListener = new SyntaxErrorListener();

            Parser.AddErrorListener(errorListener);
            Tree = Parser.program();
            if (errorListener.SyntaxErrors.Any())
            {
                _logOutput.Add("Couldn't refactor, one or more syntax errors occurred:");
                foreach (var error in errorListener.SyntaxErrors)
                {
                    _logOutput.Add(error.AsString());
                }

                SyntaxErrorsFound = true;
                Tree = null;
            }
        }
        private ParseResult ParseFile(string filename, Encoding encoding, bool detailed = false, IEnumerable <ParseResult> currentParseResults = null)
        {
            using (var sw = new StringWriter())
                using (var sr = new StreamReader(filename, encoding))
                {
                    var errors = new List <SyntaxError>();
                    var parser = GetParserForStream(sr, TextWriter.Null, sw);
                    parser.Interpreter.PredictionMode = Antlr4.Runtime.Atn.PredictionMode.SLL;
                    var errListener = new SyntaxErrorListener();
                    parser.AddErrorListener(errListener);
                    var listener = detailed ?
                                   new DaedalusStatefulDetailedParseTreeListener(parser, currentParseResults)
                                : new DaedalusStatefulParseTreeListener(parser, currentParseResults);
                    DaedalusParser.DaedalusFileContext fileCtx;
                    try
                    {
                        fileCtx = parser.daedalusFile();
                    }
                    catch (Exception)
                    {
                        parser.Interpreter.PredictionMode = Antlr4.Runtime.Atn.PredictionMode.LL;
                        fileCtx = parser.daedalusFile();
                    }

                    ParseTreeWalker.Default.Walk(listener, fileCtx);

                    return(new ParseResult
                    {
                        SyntaxErrors = errListener.SyntaxErrors,
                        GlobalConstants = listener.GlobalConsts,
                        GlobalVariables = listener.GlobalVars,
                        GlobalFunctions = listener.GlobalFunctions,
                        GlobalClasses = listener.GlobalClasses,
                        GlobalPrototypes = listener.GlobalPrototypes,
                        GlobalInstances = listener.GlobalInstances,
                    });
                }
        }
        private ParseResult ParseText(string fileContent, bool detailed = false, IEnumerable <ParseResult> currentParseResults = null)
        {
            using (var sw = new StringWriter())
            {
                var errors      = new List <SyntaxError>();
                var parser      = GetParserForText(fileContent, TextWriter.Null, sw);
                var errListener = new SyntaxErrorListener();
                parser.AddErrorListener(errListener);
                var listener = detailed ? new DaedalusStatefulDetailedParseTreeListener(parser, currentParseResults) : new DaedalusStatefulParseTreeListener(parser, currentParseResults);
                ParseTreeWalker.Default.Walk(listener, parser.daedalusFile());

                return(new ParseResult
                {
                    SyntaxErrors = errListener.SyntaxErrors,
                    GlobalConstants = listener.GlobalConsts,
                    GlobalVariables = listener.GlobalVars,
                    GlobalFunctions = listener.GlobalFunctions,
                    GlobalClasses = listener.GlobalClasses,
                    GlobalPrototypes = listener.GlobalPrototypes,
                    GlobalInstances = listener.GlobalInstances,
                });
            }
        }
        private void compareArrays(object[,] valueArray, object[,] formulaArray)
        {
            var x  = valueArray.GetLength(0);
            var y  = valueArray.GetLength(1);
            var xF = formulaArray.GetLength(0);
            var yF = formulaArray.GetLength(1);

            if (x != xF || y != yF)
            {
                Logger.DebugLine("Compare Arrays: x and y dimensions dont match between arrays", 1);
                Logger.DebugLine($"x: {x}, xF: {xF}, y: {y}, yF: {yF}", 1);
            }

            for (int i = 1; i <= x; i++)
            {
                for (int j = 1; j <= y; j++)
                {
                    var value   = valueArray[i, j];
                    var formula = formulaArray[i, j];

                    var equals = false;

                    if (value != null && formula != null)
                    {
                        if (value is double)
                        {
                            string valueString = ((double)value).ToString("G", CultureInfo.InvariantCulture);
                            equals = ((string)formula).Equals(valueString);
                            var valueStringComma   = valueString.Replace(".", ",");
                            var valueStringDot     = valueString.Replace(",", ".");
                            var formulaStringComma = ((string)formula).Replace(".", ",");
                            var formulaStringDot   = ((string)formula).Replace(",", ".");
                            Logger.DebugLine($"Value is double, value: {valueString}, formula: {(string)formula}, equals: {equals}", 1);
                            if (!equals)
                            {
                                equals = ((string)formula).Equals(valueStringComma) || ((string)formula).Equals(valueStringDot);
                                Logger.DebugLine($"Dot Comma conversion check, valueStringComma: {valueStringComma}, valueStringDot: {valueStringDot}, formula: {(string)formula}, equals: {equals}", 1);
                            }
                            if (!equals)
                            {
                                string valueStringInstalled = ((double)value).ToString("G", CultureInfo.InstalledUICulture);
                                equals = ((string)formula).Equals(valueStringInstalled);
                                Logger.DebugLine($"Installed UI Culture ({CultureInfo.InstalledUICulture}) Equal check, value: {valueStringInstalled}, formula: {(string)formula}, equals: {equals}", 1);
                            }
                            if (!equals)
                            {
                                var    culture = CultureInfo.CreateSpecificCulture("de-DE");
                                string valueStringInstalled = ((double)value).ToString("G", culture);
                                equals = ((string)formula).Equals(valueStringInstalled);
                                Logger.DebugLine($"Specific Culture ({culture}) Equal check, value: {valueStringInstalled}, formula: {(string)formula}, equals: {equals}", 1);
                            }
                            if (!equals)
                            {
                                string valueStringDoubleFixedPoint = ((double)value).ToString(FormatStrings.DoubleFixedPoint, CultureInfo.InvariantCulture);
                                equals = ((string)formula).Equals(valueStringDoubleFixedPoint);
                                Logger.DebugLine($"Format DoubleFixedPoint with Culture ({CultureInfo.InvariantCulture}) Equal check, value: {valueStringDoubleFixedPoint}, formula: {(string)formula}, equals: {equals}", 1);
                            }

                            if (!equals && double.TryParse((string)formula, out double parsedFormula))
                            {
                                equals = IsDoubleEqual((double)value, parsedFormula);
                                Logger.DebugLine($"Parsed formula to double, value: {(double)value}, parsedFormula: {parsedFormula}, equals: {equals}", 1);
                            }

                            if (!equals && (double.TryParse(formulaStringComma, out parsedFormula) || double.TryParse(formulaStringDot, out parsedFormula)))
                            {
                                equals = IsDoubleEqual((double)value, parsedFormula);
                                Logger.DebugLine($"Parsed formula dot comma to double, value: {(double)value}, parsedFormula: {parsedFormula}, equals: {equals}", 1);
                            }
                        }
                        else if (value is DateTime)
                        {
                            Logger.DebugLine($"Value is Datetime, value: {value.ToString()}, formula: {(string)formula}", 1);
                            if (int.TryParse((string)formula, out int result))
                            {
                                DateTime date = new DateTime(1900, 1, 1).AddDays(result);
                                equals = true;
                                Logger.DebugLine($"Formula is int, date: {date.ToString()}, value date: {(DateTime)value}", 1);
                            }
                            else if (DateTime.TryParse((string)formula, out DateTime resultDate))
                            {
                                equals = true;
                                Logger.DebugLine($"Formula is datetime, resultDate: {resultDate.ToString()}, value date: {(DateTime)value}", 1);
                            }
                            else if (double.TryParse((string)formula, out double resultDouble))
                            {
                                equals = true;
                                //DateTime date = new DateTime(1900, 1, 1).AddDays(resultDouble);
                                Logger.DebugLine($"Formula is double, resultDouble: {resultDouble.ToString()}, value date: {(DateTime)value}", 1);
                            }
                            else
                            {
                                Logger.DebugLine($"Couldnt compare DateTime, value: {value.ToString()}, formula: {(string)formula}", 2);
                                equals = false;
                            }
                        }
                        else
                        {
                            equals = formula.Equals(value.ToString());
                        }
                    }

                    if (equals)
                    {
                        Logger.DebugLine($"{j}, {i}: Value equals Formula");
                        addConvertedValue(value, i, j);
                    }
                    else if (value == formula)
                    {
                        Logger.DebugLine($"{j}, {i}: Value == Formula");
                        addConvertedValue(value, i, j);
                    }
                    else if (value == null && string.IsNullOrEmpty((string)formula))
                    {
                        Logger.DebugLine($"{j}, {i}: Value equals Formula: Both empty");
                    }
                    else
                    {
                        printObject(value, "Value");
                        Logger.Debug("----");
                        printObject(formula, "Formula");
                        Logger.DebugLine("");
                        Logger.DebugLine($"{j}, {i}: Value does not equal Formula", 1);

                        SyntaxErrorListener errorListener    = new SyntaxErrorListener();
                        AntlrInputStream    inputStream      = new AntlrInputStream((string)formula);
                        ExcelFormulaLexer   spreadsheetLexer = new ExcelFormulaLexer(inputStream);
                        spreadsheetLexer.RemoveErrorListeners();
                        spreadsheetLexer.AddErrorListener(errorListener);
                        CommonTokenStream  commonTokenStream  = new CommonTokenStream(spreadsheetLexer);
                        ExcelFormulaParser excelFormulaParser = new ExcelFormulaParser(commonTokenStream);

                        ExcelFormulaParser.ExcelExprContext context = excelFormulaParser.excelExpr();
                        if (errorListener.HasError)
                        {
                            Logger.DebugLine($"Found Lexer Error - Dont process formula at {i}, {j} : {(string)formula}", 5);
                            if (GlobalSettings.ImportStopAtSyntaxError)
                            {
                                Console.WriteLine($"Lexer Error - Enter to continue", 10);
                                Console.ReadLine();
                            }
                            continue;
                        }
                        if (excelFormulaParser.NumberOfSyntaxErrors > 0)
                        {
                            Logger.DebugLine($"Found Syntax Error - Dont process formula at {i}, {j} : {(string)formula}", 5);
                            if (GlobalSettings.ImportStopAtSyntaxError)
                            {
                                Console.WriteLine($"Syntax Error - Enter to continue", 10);
                                Console.ReadLine();
                            }
                            continue;
                        }
                        ExcelFormulaVisitor visitor = new ExcelFormulaVisitor();
                        string formulaText          = visitor.Visit(context);

                        if (visitor.Error)
                        {
                            continue;
                        }
                        Logger.DebugLine($"FormulaText: {formulaText}", 1);

                        convertedText += $"C[{j},{i}] = {{{formulaText}}} ;\n";
                    }
                }
            }
        }
Exemplo n.º 29
0
        public void RunCode(string code, string zenContent)
        {
            ZenLoader zenLoader = new ZenLoader();

            if (zenLoader.Load(zenContent) != 0)
            {
                return;
            }
            List <ZenFileNode> zenFileNodes = zenLoader.ZenFileNodes;

            List <IParseTree>        parseTrees             = new List <IParseTree>();
            List <string>            filesPaths             = new List <string>();
            List <string[]>          filesContentsLines     = new List <string[]>();
            List <HashSet <string> > suppressedWarningCodes = new List <HashSet <string> >();

            _syntaxErrorsCount   = 0;
            _syntaxErrorsPerFile = new List <List <SyntaxError> >();

            if (code != "")
            {
                DaedalusParser      parser = Compiler.GetParserForText(code);
                SyntaxErrorListener syntaxErrorListener = new SyntaxErrorListener();
                parser.AddErrorListener(syntaxErrorListener);
                parseTrees.Add(parser.daedalusFile());
                _syntaxErrorsCount += syntaxErrorListener.SyntaxErrors.Count;
                _syntaxErrorsPerFile.Add(syntaxErrorListener.SyntaxErrors);

                string[] fileContentLines = code.Split(Environment.NewLine);
                filesPaths.Add("test.d");
                filesContentsLines.Add(fileContentLines);
                suppressedWarningCodes.Add(SemanticErrorsCollectingVisitor.GetWarningCodesToSuppress(fileContentLines[0]));
            }


            if (_syntaxErrorsCount > 0)
            {
                for (int i = 0; i < _syntaxErrorsPerFile.Count; ++i)
                {
                    List <SyntaxError> syntaxErrors = _syntaxErrorsPerFile[i];
                    if (syntaxErrors.Count > 0)
                    {
                        string filePath = filesPaths[i];
                        string fileName = Path.GetFileName(filePath);
                        _errorLogger.LogLine(filePath);
                        foreach (SyntaxError syntaxError in syntaxErrors)
                        {
                            string line = filesContentsLines[i][syntaxError.LineNo - 1];
                            syntaxError.Print(fileName, line, _errorLogger);
                        }
                    }
                }

                _errorLogger.LogLine($"{_syntaxErrorsCount} syntax {(_syntaxErrorsCount == 1 ? "error" : "errors")} generated.");
                return;
            }

            SemanticAnalyzer semanticAnalyzer = new SemanticAnalyzer(
                zenFileNodes,
                parseTrees,
                filesPaths,
                filesContentsLines,
                suppressedWarningCodes
                );

            semanticAnalyzer.Run();
            SymbolTable = semanticAnalyzer.SymbolTable;

            SemanticErrorsCollectingVisitor semanticErrorsCollectingVisitor = new SemanticErrorsCollectingVisitor(_errorLogger, _strictSyntax, _globallySuppressedCodes);

            semanticErrorsCollectingVisitor.FilePathDisplayStatus = FilePathDisplayStatus.NeverDisplay;
            semanticErrorsCollectingVisitor.VisitTree(semanticAnalyzer.AbstractSyntaxTree);

            int    errorsCount   = semanticErrorsCollectingVisitor.ErrorsCount;
            int    warningsCount = semanticErrorsCollectingVisitor.WarningsCount;
            string error         = errorsCount == 1 ? "error" : "errors";
            string warning       = warningsCount == 1 ? "warning" : "warnings";

            if (errorsCount > 0)
            {
                if (warningsCount > 0)
                {
                    _errorLogger.LogLine($"{errorsCount} {error}, {warningsCount} {warning} generated.");
                }
                else
                {
                    _errorLogger.LogLine($"{errorsCount} {error} generated.");
                }
                return;
            }

            if (warningsCount > 0)
            {
                _errorLogger.LogLine($"{warningsCount} {warning} generated.");
            }


            SymbolUpdatingVisitor symbolUpdatingVisitor = new SymbolUpdatingVisitor();

            symbolUpdatingVisitor.VisitTree(semanticAnalyzer.AbstractSyntaxTree);

            AssemblyBuildingVisitor assemblyBuildingVisitor = new AssemblyBuildingVisitor(semanticAnalyzer.SymbolTable);

            assemblyBuildingVisitor.VisitTree(semanticAnalyzer.AbstractSyntaxTree);
        }
Exemplo n.º 30
0
 void ILSLSyntaxErrorListener.CastOnCastExpression(LSLSourceCodeRange location,
                                                   ILSLReadOnlyExprNode castedExpression)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () => SyntaxErrorListener.CastOnCastExpression(location, castedExpression));
 }