コード例 #1
0
 /// <summary>
 /// Produces a syntax tree by parsing the source text.
 /// </summary>
 public static MetaSyntaxTree ParseText(
     SourceText text,
     MetaParseOptions options = null,
     string path = "",
     CancellationToken cancellationToken = default(CancellationToken))
 {
     if (text == null)
     {
         throw new ArgumentNullException(nameof(text));
     }
     options = options ?? MetaParseOptions.Default;
     using (var parser = new MetaSyntaxParser(text, options, oldTree: null, changes: null, cancellationToken: cancellationToken))
     {
         var compilationUnit = (MainSyntax)parser.ParseMain().CreateRed();
         var tree            = new ParsedSyntaxTree(text, text.Encoding, text.ChecksumAlgorithm, path, options, compilationUnit, parser.Directives);
         tree.VerifySource();
         return(tree);
     }
 }
コード例 #2
0
        private SyntaxTree WithChanges(SourceText newText, IReadOnlyList <TextChangeRange> changes)
        {
            if (changes == null)
            {
                throw new ArgumentNullException(nameof(changes));
            }
            var oldTree = this;

            // if changes is entire text do a full reparse
            if (changes.Count == 1 && changes[0].Span == new TextSpan(0, this.Length) && changes[0].NewLength == newText.Length)
            {
                // parser will do a full parse if we give it no changes
                changes = null;
                oldTree = null;
            }
            using (var parser = new MetaSyntaxParser(newText, this.Options, oldTree?.GetRoot(), changes))
            {
                var compilationUnit = (MainSyntax)parser.ParseMain().CreateRed();
                var tree            = new ParsedSyntaxTree(newText, newText.Encoding, newText.ChecksumAlgorithm, this.FilePath, this.Options, compilationUnit, parser.Directives);
                tree.VerifySource(changes);
                return(tree);
            }
        }