Beispiel #1
0
        public void Create()
        {
            StringSet ss = new StringSet();

            Assert.AreEqual(0, ss.Count);
            Assert.AreEqual("", ss.ToString());
        }
Beispiel #2
0
        public void Add()
        {
            StringSet ss = new StringSet();
            ss.Add("foo");
            ss.Add("foo");
            ss.Add("bar");
            Assert.IsTrue(ss["foo"]);
            Assert.AreEqual(2, ss.Count);
            Assert.AreEqual("foo\r\nbar\r\n", ss.ToString());
            ss.Remove("bar");
            Assert.AreEqual(1, ss.Count);
            Assert.IsFalse(ss["fool"]);

            ss = new StringSet(new string[] { "foo", "bar"});
            ss.Add(new StringSet("baz"));
            Assert.AreEqual(3, ss.Count);
        }
Beispiel #3
0
        public void Add()
        {
            StringSet ss = new StringSet();
            ss.Add("foo");
            ss.Add("foo");
            ss.Add("bar");
            Assert.IsTrue(ss["foo"]);
            Assert.AreEqual(2, ss.Count);
            Assert.AreEqual("foo\r\nbar\r\n", ss.ToString());
            ss.Remove("bar");
            Assert.AreEqual(1, ss.Count);
            Assert.IsFalse(ss["fool"]);

            ss = new StringSet(new string[] { "foo", "bar"});
            ss.Add(new StringSet("baz"));
            Assert.AreEqual(3, ss.Count);
        }
        private void ValidateAll()
        {
            //Check rule on all non-terminals
            StringSet ntList = new StringSet();

            foreach (NonTerminal nt in Data.NonTerminals)
            {
                if (nt == Data.AugmentedRoot)
                {
                    continue;                   //augm root does not count
                }
                BnfExpressionData data = nt.Rule.Data;
                if (data.Count == 1 && data[0].Count == 1 && data[0][0] is NonTerminal)
                {
                    ntList.Add(nt.Name);
                }
            }//foreach
            if (ntList.Count > 0)
            {
                string slist = TextUtils.Cleanup(ntList.ToString(", "));
                AddError("Warning: Possible non-terminal duplication. The following non-terminals have rules containing a single non-terminal: \r\n {0}. \r\n" +
                         "Consider merging two non-terminals; you may need to use 'nt1 = nt2;' instead of 'nt1.Rule=nt2'.", slist);
            }
            //Check constructors of all nodes referenced in Non-terminals that don't use NodeCreator delegate
            var ctorArgTypes = new Type[] { typeof(NodeArgs) };

            foreach (NonTerminal nt in Data.NonTerminals)
            {
                if (nt.NodeCreator == null && nt.NodeType != null)
                {
                    object ci = nt.NodeType.GetConstructor(ctorArgTypes);
                    if (ci == null)
                    {
                        AddError(
                            @"AST Node class {0} referenced by non-terminal {1} does not have a constructor for automatic node creation. 
Provide a constructor with a single NodeArgs parameter, or use NodeCreator delegate property in NonTerminal.",
                            nt.NodeType, nt.Name);
                    }
                } //if
            }     //foreach ntInfo
        }         //method
        private void ValidateAll()
        {
            //Check rule on all non-terminals
            StringSet ntList = new StringSet();

            foreach (NonTerminal nt in Data.NonTerminals)
            {
                if (nt == Data.AugmentedRoot)
                {
                    continue;                   //augm root does not count
                }
                BnfExpressionData data = nt.Rule.Data;
                if (data.Count == 1 && data[0].Count == 1 && data[0][0] is NonTerminal)
                {
                    ntList.Add(nt.Name);
                }
            }//foreach
            if (ntList.Count > 0)
            {
                string slist = TextUtils.Cleanup(ntList.ToString(", "));
                AddError("Warning: Possible non-terminal duplication. The following non-terminals have rules containing a single non-terminal: \r\n {0}. \r\n" +
                         "Consider merging two non-terminals; you may need to use 'nt1 = nt2;' instead of 'nt1.Rule=nt2'.", slist);
            }
        }
Beispiel #6
0
 //Constructs the error message in situation when parser has no available action for current input.
 // override this method if you want to change this message
 public virtual string ConstructParserErrorMessage(ParsingContext context, StringSet expectedTerms)
 {
     if(expectedTerms.Count > 0)
     return string.Format(Resources.ErrSyntaxErrorExpected, expectedTerms.ToString(", "));
       else
     return Resources.ErrParserUnexpectedInput;
 }
Beispiel #7
0
 //Constructs the error message in situation when parser has no available action for current input.
 // override this method if you want to change this message
 public virtual string ConstructParserErrorMessage(ParsingContext context, StringSet expectedTerms) {
   return string.Format(Resources.ErrParserUnexpInput, expectedTerms.ToString(" "));
 }
Beispiel #8
0
 public void Create()
 {
     StringSet ss = new StringSet();
     Assert.AreEqual(0, ss.Count);
     Assert.AreEqual("", ss.ToString());
 }
 public override string ToString()
 {
     return(Core.ToString() + "  LOOKAHEADS: " + TextUtils.Cleanup(Lookaheads.ToString(" ")));
 }
 //Constructs the error message in situation when parser has no available action for current input.
 // override this method if you want to change this message
 public virtual string ConstructParserErrorMessage(ParsingContext context, StringSet expectedTerms) {
   return string.Format(O2_Misc_Microsoft_MPL_Libs.Irony_Parser.Resources.ErrParserUnexpInput, expectedTerms.ToString(" "));
    
 }
Beispiel #11
0
        }         //Parse

        #endregion

        #region Error reporting and recovery
        private void ReportParseError()
        {
            if (_currentToken.Terminal == Grammar.Eof)
            {
                _context.ReportError(_currentToken.Location, "Unexpected end of file.");
                return;
            }
            StringSet expectedList = GetCurrentExpectedSymbols();
            string    message      = this.Data.Grammar.GetSyntaxErrorMessage(_context, expectedList);

            if (message == null)
            {
                message = "Syntax error" + (expectedList.Count == 0 ? "." : ", expected: " + TextUtils.Cleanup(expectedList.ToString(" ")));
            }
            if (_context.OptionIsSet(CompilerOptions.GrammarDebugging))
            {
                message += " (parser state: " + _currentState.Name + ")";
            }
            _context.Errors.Add(new SyntaxError(_currentToken.Location, message));
        }