private UstNode ParseAndConvert(string code, AspxParser.Location location) { SyntaxTree tree = CSharpSyntaxTree.ParseText(code, new CSharpParseOptions(kind: SourceCodeKind.Script)); var converter = new RoslynUstCommonConverterVisitor(tree, fileNode); FileNode resultFileNode = converter.Walk(); UstNode result = NodeHelpers.CreateLanguageNamespace(resultFileNode.Root, Language.Aspx, fileNode); result.ApplyActionToDescendants(ustNode => ustNode.TextSpan = ustNode.TextSpan.AddOffset(location.Start)); return(result); }
private UstNode ParseExpressionAndConvert(string expression, int offset) { ExpressionSyntax node = SyntaxFactory.ParseExpression(expression); var converter = new RoslynUstCommonConverterVisitor(node, fileNode); UstNode result = converter.Walk(node); if (result is FileNode) { result = ((FileNode)result).Root; } result.ApplyActionToDescendants(ustNode => ustNode.TextSpan = ustNode.TextSpan.AddOffset(offset)); return(result); }
public Ust Convert(ParseTree langParseTree) { var roslynParseTree = (CSharpRoslynParseTree)langParseTree; SyntaxTree syntaxTree = roslynParseTree.SyntaxTree; Ust result; if (syntaxTree != null) { string filePath = syntaxTree.FilePath; try { var visitor = new RoslynUstCommonConverterVisitor(syntaxTree, filePath); if (SemanticsInfo != null) { visitor.SemanticsInfo = (CSharpRoslynSemanticsInfo)SemanticsInfo; } visitor.Logger = Logger; FileNode fileNode = visitor.Walk(); result = new MostCommonUst(fileNode, ConvertedLanguages); result.Comments = roslynParseTree.Comments.Select(c => new Common.Nodes.Tokens.Literals.CommentLiteral(c.ToString(), c.GetTextSpan(), fileNode)).ToArray(); } catch (Exception ex) { Logger.LogError(new ConversionException(filePath, ex)); result = new MostCommonUst(); } } else { result = new MostCommonUst(); } result.FileName = langParseTree.FileName; return(result); }