public override Node VisitFunc([NotNull] FormulaGrammerParser.FuncContext context)
        {
            var functionNameToken = context.IDENTIFIER().Symbol;

            if (this.configuration.IsFunctionsSupportDisabled)
            {
                ParsingException.ThrowInvalidTokenException(functionNameToken);
            }

            var functionName = functionNameToken.Text;

            var parameters = new List <Node>();
            var idxExp     = 0;

            FormulaGrammerParser.ExpressionContext exp;
            while ((exp = context.expression(idxExp++)) != null)
            {
                parameters.Add(this.Visit(exp));
            }

            if (!this.configuration.IsFunctionNameValidationDisabled && !this.configuration.HasFunction(functionName, parameters.Count))
            {
                ParsingException.ThrowUnknownFunctionException(functionNameToken);
            }

            return(new FunctionNode(functionName, parameters.ToArray()));
        }
        public void MessageErrorKindConstructor()
        {
            var ex = new ParsingException("test", ErrorKind.MissingOperand);

            Assert.Null(ex.LexicalElement);
            Assert.Equal("test", ex.Message);
            Assert.Equal(ErrorKind.MissingOperand, ex.ErrorKind);
        }
        public void MessageConstructor()
        {
            var ex = new ParsingException("test");

            Assert.Null(ex.LexicalElement);
            Assert.Equal("test", ex.Message);
            Assert.Equal(ErrorKind.UnknownError, ex.ErrorKind);
        }
        public void MessageInnerExceptionConstructor()
        {
            var innerException = new Exception();
            var ex             = new ParsingException("test", innerException);

            Assert.Null(ex.LexicalElement);
            Assert.Equal("test", ex.Message);
            Assert.Equal(innerException, ex.InnerException);
        }
Exemple #5
0
 public void InsertError(ParsingException warning)
 {
     string key = warning.Message;
     if (!Errors.ContainsKey(key))
     {
         Errors.Add(key, warning);
         FilterData();
     }
 }
Exemple #6
0
        public void Expect(char expected)
        {
            var found = GetNext();

            if (found != expected)
            {
                throw ParsingException.UnexpectedCharacter(expected, found, GetLocation());
            }
        }
Exemple #7
0
        //private string GetOption()
        //{
        //    string option = "";
        //    option += MenuButton_EnableSimplificationOfTheFormula.Checked ? "" : "l";
        //    option += MenuButton_EnableOntheflyAutomataSimplification.Checked ? "" : "o";
        //    option += MenuButton_EnableAPosterioriAutomataSimplification.Checked ? "" : "p";
        //    option += MenuButton_EnableStronglyConnectedComponentsSimplification.Checked ? "" : "c";
        //    option += MenuButton_EnableTrickingInAcceptingConditions.Checked ? "" : "a";
        //    return option;
        //}

        private SpecificationBase parseSpecification()
        {
            SpecificationBase spec = null;

            do
            {
                if (mTabItem == null || mTabItem.Text.Trim() == "")
                {
                    DevLog.e(TAG, "mTabItem is null");
                    break;
                }

                // DisableAllControls();
                try
                {
                    string moduleName = mTabItem.ModuleName;
                    if (LoadModule(moduleName))
                    {
                        //string option = GetOption();
                        Stopwatch t = new Stopwatch();
                        // DisableAllControls();
                        disableAllControls();
                        t.Start();
                        spec = mModule.ParseSpecification(mTabItem.Text, "", mTabItem.FileName);
                        t.Stop();

                        if (spec != null)
                        {
                            mTabItem.Specification = spec;
                            if (spec.Errors.Count > 0)
                            {
                                string key = "";
                                foreach (KeyValuePair <string, ParsingException> pair in spec.Errors)
                                {
                                    key = pair.Key;
                                    break;
                                }

                                ParsingException parsingException = spec.Errors[key];
                                spec.Errors.Remove(key);
                                throw parsingException;
                            }
                        }

                        // Spec = spec;
                        initLogic();
                        enableAllControls();
                        // EnableAllControls();
                    }
                }
                catch (ParsingException ex) { }
                catch (Exception ex) { }
            } while (false);

            return(spec);
        }
Exemple #8
0
        private static IExpression ParseBlockOrTupleList(IdentifierToken name, IEnumerator <Token> tokenStream)
        {
            var token = tokenStream.GetNext();

            return(token switch
            {
                OpenBraceToken ob => ParseIntTupleList(name, ob.Location, tokenStream),
                CloseBraceToken _ => new Block(name, ImmutableArray <Assignment> .Empty),
                IdentifierToken i => ParseBlock(name, i, tokenStream),
                _ => throw ParsingException.CreateError(token, "identifier, end of block, or start of tuple"),
            });
Exemple #9
0
 public static void AddIntoUsageTable(Dictionary<string, List<ParsingException>> UsageTable, string keyword, IToken token, ParsingException definition)
 {
     if (UsageTable.ContainsKey(keyword))
     {
         if (token != null)
         {
             UsageTable[keyword].Add(new ParsingException("", token, definition));
         }
     }
     else
     {
         UsageTable.Add(keyword, new List<ParsingException>());
         if (token != null)
         {
             UsageTable[keyword].Add(new ParsingException("", token, definition));
         }
     }
 }
Exemple #10
0
        private ParserException GenerateParserError(ParsingException parsingException)
        {
            var errorLocation = parsingException.Location;
            var error = parsingException.Message;
            var call = parsingException.CallLocation;

            var zone = new Zone(errorLocation, error, call != null ? new Zone(call) : null);

            var message = Stylizer.Stylize(zone);

            return new ParserException(message, parsingException, zone);
        }
Exemple #11
0
        private ParserException GenerateParserError(ParsingException parsingException, string fileName)
        {
            var errorLocation = Tokenizer.Location.Index;
            var error = "Parse Error";
            var call = 0;

            if(parsingException != null)
            {
                errorLocation = parsingException.Index;
                error = parsingException.Message;
                call = parsingException.Call;
            }

            var zone = Tokenizer.GetZone(error, errorLocation, call, fileName);

            var message = Stylizer.Stylize(zone);

            return new ParserException(message, parsingException);
        }
Exemple #12
0
        public override void HandleParsingException(ParsingException ex)
        {
            try
            {

                if (ex is GraphParsingException)
                {
                    string pname = (ex as GraphParsingException).ProcessName;
                    foreach (TreeNode node in ModelNode.Nodes)
                    {
                        if (node.Text == pname)
                        {
                            TreeView_Structure.SelectedNode = node;
                            TreeView_Structure_NodeMouseDoubleClick(null,
                                                                    new TreeNodeMouseClickEventArgs(node, MouseButtons.Left,
                                                                                                    2, 0, 0));
                            break;
                        }
                    }
                }
                else
                {

                    TreeView_Structure.SelectedNode = DeclarationNode;
                    TreeView_Structure_NodeMouseDoubleClick(null,
                                                            new TreeNodeMouseClickEventArgs(DeclarationNode, MouseButtons.Left,
                                                                                            2, 0, 0));

                    if (ex.Line >= 1 && ex.CharPositionInLine >= 0 && ex.Text != null)
                    {
                        this.textEditorControl.ActiveTextAreaControl.JumpTo(ex.Line - 1);
                        SelectionManager selectionManager =
                            textEditorControl.ActiveTextAreaControl.TextArea.SelectionManager;
                        selectionManager.ClearSelection();
                        selectionManager.SetSelection(new TextLocation(ex.CharPositionInLine, ex.Line - 1),
                                                      new TextLocation(ex.CharPositionInLine + ex.Text.Length,
                                                                       ex.Line - 1));
                        textEditorControl.Refresh();
                    }
                }
            }
            catch
            {

            }
        }
Exemple #13
0
        private void OpenException(ParsingException ex)
        {
            try
            {
                do
                {
                    if (string.IsNullOrEmpty(ex.FileName))
                    {
                        if (CurrentEditorTabItem != null)
                            this.CurrentEditorTabItem.HandleParsingException(ex);
                        break;
                    }

                    EditorTabItem item1 = OpenFile(ex.FileName, false);
                    if (item1 != null)
                        item1.HandleParsingException(ex);
                } while (false);
            }
            catch (Exception) { }
        }
Exemple #14
0
 public Declaration(DeclarationType type, ParsingException token)
 {
     DeclarationType = type;
     DeclarationToken = token;
 }