internal void Parse(ITextSnapshot snapshot, out LanguageService.SyntaxTree.ITokenStream TokenStream, string path) { string source = snapshot.GetText(); // Currently we "eat" all Exception that might be raised // by XSharpSyntaxTree.ParseText TokenStream = null; try { LanguageService.CodeAnalysis.SyntaxTree tree = XSharpSyntaxTree.ParseText(source, null, path); var syntaxRoot = tree.GetRoot(); // Get the antlr4 parse tree root var xtree = ((LanguageService.CodeAnalysis.XSharp.Syntax.CompilationUnitSyntax)syntaxRoot).XSource; TokenStream = ((LanguageService.CodeAnalysis.XSharp.Syntax.CompilationUnitSyntax)syntaxRoot).XTokenStream; // var walker = new LanguageService.SyntaxTree.Tree.ParseTreeWalker(); var discover = new XSharpTreeDiscover(); discover.Snapshot = snapshot; discover.xsharpBraceCloseType = xsharpBraceCloseType; discover.xsharpBraceOpenType = xsharpBraceOpenType; discover.xsharpIdentifierType = xsharpIdentifierType; discover.xsharpRegionStartType = xsharpRegionStartType; discover.xsharpRegionStopType = xsharpRegionStopType; // Walk the tree. The TreeDiscover class will collect the tags. walker.Walk(discover, xtree); this.tags = discover.tags; } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } }
internal void Parse(ITextSnapshot snapshot, out LanguageService.SyntaxTree.ITokenStream TokenStream, string path) { string source = snapshot.GetText(); // Currently we "eat" all Exception that might be raised // by XSharpSyntaxTree.ParseText TokenStream = null; try { LanguageService.CodeAnalysis.SyntaxTree tree = XSharpSyntaxTree.ParseText(source, null, path); var syntaxRoot = tree.GetRoot(); // Get the antlr4 parse tree root var xtree = ((LanguageService.CodeAnalysis.XSharp.Syntax.CompilationUnitSyntax)syntaxRoot).XSource; TokenStream = ((LanguageService.CodeAnalysis.XSharp.Syntax.CompilationUnitSyntax)syntaxRoot).XTokenStream; // var walker = new LanguageService.SyntaxTree.Tree.ParseTreeWalker(); var discover = new XSharpTreeDiscover(); discover.Snapshot = snapshot; discover.xsharpBraceCloseType = xsharpBraceCloseType; discover.xsharpBraceOpenType = xsharpBraceOpenType; discover.xsharpIdentifierType = xsharpIdentifierType; discover.xsharpRegionStartType = xsharpRegionStartType; discover.xsharpRegionStopType = xsharpRegionStopType; // Walk the tree. The TreeDiscover class will collect the tags. walker.Walk(discover, xtree); this.tags = discover.tags; } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } }
/// <summary> /// /// </summary> /// <param name="source"></param> /// <returns></returns> public CodeCompileUnit Parse(string source) { CodeCompileUnit ccu = new CodeCompileUnit(); // try { // Tab replace, in order to have the good position of Memebers (Line/col) String TabSpace = new String(' ', TabSize); source = source.Replace("\t", TabSpace); // LanguageService.CodeAnalysis.SyntaxTree tree = XSharpSyntaxTree.ParseText(source); var syntaxRoot = tree.GetRoot(); // Get the antlr4 parse tree root var xtree = ((LanguageService.CodeAnalysis.XSharp.Syntax.CompilationUnitSyntax)syntaxRoot).XSource; // var discover = new XSharpTreeDiscover(); discover.SourceCode = source; discover.CurrentFile = this.FileName; // var walker = new LanguageService.SyntaxTree.Tree.ParseTreeWalker(); walker.Walk(discover, xtree); // ccu = discover.CodeCompileUnit; ccu.UserData[XSharpCodeConstants.USERDATA_FILENAME] = this.FileName; } catch ( Exception ex ) { Debug.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace); } // return ccu; }
/// <summary> /// /// </summary> /// <param name="source"></param> /// <returns></returns> public CodeCompileUnit Parse(string source) { XCodeCompileUnit ccu = new XCodeCompileUnit(); // try { var reporter = new ErrorIgnorer(); ITokenStream tokenStream; LanguageService.CodeAnalysis.XSharp.SyntaxParser.XSharpParserRuleContext xtree; bool ok = XSharp.Parser.VsParser.Parse(source, this.FileName, _projectNode.ParseOptions, reporter, out tokenStream, out xtree, out _); // We need to d 2 steps here: // 1 - Scan for the fields , so we know the difference between fields and properties when we perform step 2 // 2 - Scan for the rest. We pass the list of fields to the tree discover code so it "knows" about all fields var discoverFields = new XSharpFieldsDiscover(_projectNode, typeInMainFile); discoverFields.SourceCode = source; discoverFields.CurrentFile = this.FileName; var walker = new LanguageService.SyntaxTree.Tree.ParseTreeWalker(); walker.Walk(discoverFields, xtree); // now the discoverFields class should contain a Dictionary with <context, FieldList> var discover = new XSharpClassDiscover(_projectNode, typeInMainFile); discover.FieldList = discoverFields.FieldList; discover.SourceCode = source; discover.CurrentFile = this.FileName; // walker.Walk(discover, xtree); // ccu = discover.CodeCompileUnit; var firstType = ccu.GetFirstClass(); if (firstType != null) { // save a copy of the member list to the CCU ccu.Members = firstType.Members; } // save file name & original source ccu.FileName = this.FileName; ccu.Source = source; } catch (Exception ex) { if (System.Diagnostics.Debugger.IsAttached) { Debug.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace); } } // return(ccu); }
/// <summary> /// /// </summary> /// <param name="source"></param> /// <returns></returns> public CodeCompileUnit Parse(string source) { XCodeCompileUnit ccu = new XCodeCompileUnit(); // try { // Tab replace, in order to have the good position of Members (Line/col) String TabSpace = new String(' ', TabSize); source = source.Replace("\t", TabSpace); // var reporter = new ErrorIgnorer(); ITokenStream tokenStream; LanguageService.CodeAnalysis.XSharp.SyntaxParser.XSharpParserRuleContext xtree; bool ok = XSharp.Parser.VsParser.Parse(source, this.FileName, _projectNode.ParseOptions, reporter, out tokenStream, out xtree); // We need to d 2 steps here: // 1 - Scan for the fields , so we know the difference between fields and properties when we perform step 2 // 2 - Scan for the rest. We pass the list of fields to the tree discover code so it "knows" about all fields var discoverFields = new XSharpFieldsDiscover(_projectNode); discoverFields.SourceCode = source; discoverFields.CurrentFile = this.FileName; var walker = new LanguageService.SyntaxTree.Tree.ParseTreeWalker(); walker.Walk(discoverFields, xtree); // now the discoverFields class should contain a Dictionary with <context, FieldList> var discover = new XSharpClassDiscover(_projectNode); discover.FieldList = discoverFields.FieldList; discover.SourceCode = source; discover.CurrentFile = this.FileName; // walker.Walk(discover, xtree); // ccu = discover.CodeCompileUnit; ccu.UserData[XSharpCodeConstants.USERDATA_FILENAME] = this.FileName; ccu.UserData[XSharpCodeConstants.USERDATA_CODE] = source; } catch (Exception ex) { if (System.Diagnostics.Debugger.IsAttached) { Debug.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace); } } // return(ccu); }
public void BuildModel(XSharpParser.SourceContext xTree, bool buildLocals) { // abort when the project is unloaded or when no project // because in these cases there is no need to build a model if (_prjNode == null || !_file.Project.Loaded) { return; } // if (xTree != null) { try { XSharpModelDiscover mdiscover; if (buildLocals) { mdiscover = new XSharpModelDiscoverWithLocals(_file, xTree, _errors); } else { mdiscover = new XSharpModelDiscover(_file, xTree, _errors); } var walker = new LanguageService.SyntaxTree.Tree.ParseTreeWalker(); // // Walk the tree. The XSharpModelDiscover class will build the model. walker.Walk(mdiscover, xTree); // Callback for LibraryManager // Disabled for Now RvdH //if ( _file.Project != null) // _file.Project.FileWalkComplete?.Invoke(_file); // } catch (Exception e) { Support.Debug("SourceWalker.BuildModel failed: " + e.Message); } } }