public static T ParseGlobal <T>(string program, bool expectErrors) where T : INode { VBParser parser = ParserFactory.CreateParser(new StringReader(program)); parser.Parse(); if (expectErrors) { Assert.IsFalse(parser.Errors.ErrorOutput.Length == 0, "Expected errors, but operation completed successfully"); } else { Assert.AreEqual("", parser.Errors.ErrorOutput); } Assert.IsNotNull(parser.CompilationUnit); Assert.IsNotNull(parser.CompilationUnit.Children); Assert.IsNotNull(parser.CompilationUnit.Children[0]); Assert.AreEqual(1, parser.CompilationUnit.Children.Count); Type type = typeof(T); Assert.IsTrue(type.IsAssignableFrom(parser.CompilationUnit.Children[0].GetType()), String.Format("Parsed expression was {0} instead of {1} ({2})", parser.CompilationUnit.Children[0].GetType(), type, parser.CompilationUnit.Children[0])); parser.CompilationUnit.AcceptVisitor(new CheckParentVisitor(), null); // TODO fix Locations // parser.CompilationUnit.AcceptChildren(new LocationAssignmentCheckVisitor(), null); return((T)parser.CompilationUnit.Children[0]); }
public void VBNetInvalidOptionDeclarationTest() { string program = "Option\n"; VBParser parser = ParserFactory.CreateParser(new StringReader(program)); parser.Parse(); Assert.IsFalse(parser.Errors.ErrorOutput.Length == 0, "Expected errors, but operation completed successfully"); }
public void VBNetComplexUsingAliasDeclarationTest() { string program = "Imports NS1, AL=NS2, NS3, AL2=NS4, NS5\n"; VBParser parser = ParserFactory.CreateParser(new StringReader(program)); parser.Parse(); Assert.AreEqual("", parser.Errors.ErrorOutput); // TODO : Extend test ... }
public void VBNetDeclarationTest() { string program = "Imports System\n" + "Imports My.Name.Space\n"; VBParser parser = ParserFactory.CreateParser(new StringReader(program)); parser.Parse(); Assert.AreEqual("", parser.Errors.ErrorOutput); CheckTwoSimpleUsings(parser.CompilationUnit); }
void CSharpParseButtonClick(object sender, EventArgs e) { var parser = new VBParser(); compilationUnit = parser.Parse(new StringReader(codeView.Text)); if (parser.HasErrors) MessageBox.Show(parser.Errors.ErrorOutput); treeView.Nodes.Clear(); foreach (var element in compilationUnit.Children) { treeView.Nodes.Add(MakeTreeNode(element)); } SelectCurrentNode(treeView.Nodes); }
void TestExpression(string expression) { VBParser parser = ParserFactory.CreateParser(new StringReader(expression)); Expression e = parser.ParseExpression(); Assert.AreEqual("", parser.Errors.ErrorOutput); VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor(); e.AcceptVisitor(outputVisitor, null); Assert.AreEqual("", outputVisitor.Errors.ErrorOutput); Assert.AreEqual(StripWhitespace(expression), StripWhitespace(outputVisitor.Text)); }
public void VBNetUsingAliasDeclarationTest() { string program = "Imports TESTME=System\n" + "Imports myAlias=My.Name.Space\n" + "Imports StringCollection = System.Collections.Generic.List(Of string)\n"; VBParser parser = ParserFactory.CreateParser(new StringReader(program)); parser.Parse(); Assert.AreEqual("", parser.Errors.ErrorOutput); CheckAliases(parser.CompilationUnit); }
void TestProgram(string program) { VBParser parser = ParserFactory.CreateParser(new StringReader(program)); parser.Parse(); Assert.AreEqual("", parser.Errors.ErrorOutput); VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor(); outputVisitor.Options.OutputByValModifier = true; outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null); Assert.AreEqual("", outputVisitor.Errors.ErrorOutput); Assert.AreEqual(StripWhitespace(program), StripWhitespace(outputVisitor.Text)); }
public static T ParseGlobal <T>(string code, bool expectErrors = false) where T : AstNode { VBParser parser = new VBParser(); CompilationUnit cu = parser.Parse(new StringReader(code)); Assert.AreEqual(expectErrors, parser.HasErrors, "HasErrors"); AstNode node = cu.Children.Single(); Type type = typeof(T); Assert.IsTrue(type.IsAssignableFrom(node.GetType()), String.Format("Parsed node was {0} instead of {1} ({2})", node.GetType(), type, node)); return((T)node); }
public void VBNetWrongUsing2Test() { string program = "Imports ,\n"; VBParser parser = ParserFactory.CreateParser(new StringReader(program)); parser.Parse(); Assert.IsTrue(parser.Errors.Count > 0); UsingDeclaration u = (UsingDeclaration)parser.CompilationUnit.Children[0]; foreach (Using us in u.Usings) { Assert.IsNotNull(us); } }
void ParseButtonClick(object sender, EventArgs e) { using (VBParser parser = new VBParser(new VBLexer(new StringReader(codeView.Text)))) { parser.Parse(); // this allows retrieving comments, preprocessor directives, etc. (stuff that isn't part of the syntax) SetSpecials(parser.Lexer.SpecialTracker.RetrieveSpecials()); // this retrieves the root node of the result DOM if (parser.Errors.Count > 0) { MessageBox.Show(parser.Errors.ErrorOutput); } syntaxTree.Unit = parser.CompilationUnit; } }
public static T ParseExpression<T>(string expr, bool expectErrors) where T : INode { VBParser parser = ParserFactory.CreateParser(new StringReader(expr)); INode parsedExpression = parser.ParseExpression(); if (expectErrors) Assert.IsFalse(parser.Errors.ErrorOutput.Length == 0, "Expected errors, but operation completed successfully"); else Assert.AreEqual("", parser.Errors.ErrorOutput); // TODO fix Locations // parsedExpression.AcceptVisitor(new LocationAssignmentCheckVisitor(), null); Type type = typeof(T); Assert.IsTrue(type.IsAssignableFrom(parsedExpression.GetType()), String.Format("Parsed expression was {0} instead of {1} ({2})", parsedExpression.GetType(), type, parsedExpression)); return (T)parsedExpression; }
void CSharpParseButtonClick(object sender, EventArgs e) { var parser = new VBParser(); compilationUnit = parser.Parse(new StringReader(codeView.Text)); if (parser.HasErrors) { MessageBox.Show(parser.Errors.ErrorOutput); } treeView.Nodes.Clear(); foreach (var element in compilationUnit.Children) { treeView.Nodes.Add(MakeTreeNode(element)); } SelectCurrentNode(treeView.Nodes); }
void TestProgram(string program) { VBParser parser = ParserFactory.CreateParser(new StringReader(program)); parser.Parse(); Assert.AreEqual("", parser.Errors.ErrorOutput); VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor(); outputVisitor.Options.IndentationChar = ' '; outputVisitor.Options.TabSize = 2; outputVisitor.Options.IndentSize = 2; using (SpecialNodesInserter.Install(parser.Lexer.SpecialTracker.RetrieveSpecials(), outputVisitor)) { outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null); } Assert.AreEqual("", outputVisitor.Errors.ErrorOutput); Assert.AreEqual(program.Replace("\r", ""), outputVisitor.Text.TrimEnd().Replace("\r", "")); parser.Dispose(); }
public void VBNetXmlNamespaceSingleQuotedWithPrefixUsingTest() { string program = "Imports <xmlns:avalonedit='http://icsharpcode.net/sharpdevelop/avalonedit'>"; VBParser parser = ParserFactory.CreateParser(new StringReader(program)); parser.Parse(); Assert.AreEqual("", parser.Errors.ErrorOutput); CompilationUnit unit = parser.CompilationUnit; Assert.AreEqual(1, unit.Children.Count); Assert.IsTrue(unit.Children[0] is UsingDeclaration); UsingDeclaration ud = (UsingDeclaration)unit.Children[0]; Assert.AreEqual(1, ud.Usings.Count); Assert.IsFalse(ud.Usings[0].IsAlias); Assert.IsTrue(ud.Usings[0].IsXml); Assert.AreEqual("xmlns:avalonedit", ud.Usings[0].XmlPrefix); Assert.AreEqual("http://icsharpcode.net/sharpdevelop/avalonedit", ud.Usings[0].Name); }