public void ParseAll() { using (TestStringReader reader = CgtTokenizerTest.GetReader()) { Tokenizer tokenizer = new Tokenizer(reader, grammar); LalrProcessor processor = new LalrProcessor(tokenizer, true); Assert.Equal(ParseMessage.Accept, processor.ParseAll()); Assert.Equal("Expression", processor.CurrentToken.Symbol.Name); Assert.Equal(27, CountTokens(processor.CurrentToken)); } }
public void SmokeTest() { LalrProcessor processor = new LalrProcessor(new Tokenizer(new StringReader("((100+5.0)/\r\n(4.5+.5))-\r\n12345.4e+1"), grammar), true); Assert.Equal(ParseMessage.Accept, processor.ParseAll()); XPathDocument doc; using (TokenXmlReader reader = new TokenXmlReader(null, processor.CurrentToken)) { doc = new XPathDocument(reader); } Trace.Write("XML: " + doc.CreateNavigator().OuterXml); }
public void bsnGold() { using var reader = new StringReader(JsonString); var tokenizer = new Tokenizer(reader, _jsonGrammar); var processor = new LalrProcessor(tokenizer, true); var parseMessage = processor.ParseAll(); if (parseMessage != ParseMessage.Accept) { throw new Exception("Parsing failed"); } }
void Parse(JsonTestSuite suite) { using (var reader = new StringReader(suite.Json)) { var tokenizer = new Tokenizer(reader, grammar); var processor = new LalrProcessor(tokenizer, true); ParseMessage parseMessage = processor.ParseAll(); if (parseMessage != ParseMessage.Accept) { // you could build a detailed error message here: // the position is in processor.CurrentToken.Position // and use processor.GetExpectedTokens() on syntax errors throw new InvalidOperationException("Parsing failed"); } } }
void Parse(XmlTestSuite suite) { using (var reader = new StringReader(suite.Xml)) { var tokenizer = new Tokenizer(reader, grammar); var processor = new LalrProcessor(tokenizer, true); ParseMessage parseMessage = processor.ParseAll(); if (parseMessage != ParseMessage.Accept) { // you could build a detailed error message here: // the position is in processor.CurrentToken.Position // and use processor.GetExpectedTokens() on syntax errors var ct = processor.CurrentToken; throw new InvalidOperationException(string.Format("Parsing failed, position: {0}, text: {1}", ct.Position, ct.Text)); } } }
public override object Execute(JsonSuite suite) { using (var reader = new StringReader(suite.Json)) { var tokenizer = new Tokenizer(reader, grammar); var processor = new LalrProcessor(tokenizer, true); ParseMessage parseMessage = processor.ParseAll(); if (parseMessage != ParseMessage.Accept) { // you could build a detailed error message here: // the position is in processor.CurrentToken.Position // and use processor.GetExpectedTokens() on syntax errors throw new InvalidOperationException("Parsing failed"); } return(null); // how do we actually get the results?? wierd. } }