/// <summary> /// Produces a syntax tree by parsing the source text. /// </summary> public static SoalSyntaxTree ParseText( string text, SoalParseOptions options = null, string path = "", Encoding encoding = null, CancellationToken cancellationToken = default(CancellationToken)) { return(ParseText(SourceText.From(text, encoding), options, path, cancellationToken)); }
internal ParsedSyntaxTree(SourceText textOpt, Encoding encodingOpt, SourceHashAlgorithm checksumAlgorithm, string path, SoalParseOptions options, SoalSyntaxNode root, DirectiveStack directives, bool cloneRoot = true) { Debug.Assert(root != null); Debug.Assert(options != null); Debug.Assert(path != null); Debug.Assert(textOpt == null || textOpt.Encoding == encodingOpt && textOpt.ChecksumAlgorithm == checksumAlgorithm); _lazyText = textOpt; _encodingOpt = encodingOpt ?? textOpt?.Encoding; _checksumAlgorithm = checksumAlgorithm; _options = options; _path = path; _root = cloneRoot ? new MainSyntax((InternalSyntaxNode)root.Green, this, 0) : root; _hasCompilationUnitRoot = root.Kind == SoalSyntaxKind.Main; this.SetDirectiveStack(directives); }
/// <summary> /// Creates a new syntax tree from a syntax node. /// </summary> public static SoalSyntaxTree Create(SoalSyntaxNode root, SoalParseOptions options = null, string path = "", Encoding encoding = null) { if (root == null) { throw new ArgumentNullException(nameof(root)); } var directives = DirectiveStack.Empty; return(new ParsedSyntaxTree( textOpt: null, encodingOpt: encoding, checksumAlgorithm: SourceHashAlgorithm.Sha1, path: path, options: options ?? SoalParseOptions.Default, root: root, directives: directives)); }
/// <summary> /// Produces a syntax tree by parsing the source text. /// </summary> public static SoalSyntaxTree ParseText( SourceText text, SoalParseOptions options = null, string path = "", CancellationToken cancellationToken = default(CancellationToken)) { if (text == null) { throw new ArgumentNullException(nameof(text)); } if (path == null) { throw new ArgumentNullException(nameof(path)); } options = options ?? SoalParseOptions.Default; using (var parser = SoalLanguage.Instance.SyntaxFactory.MakeParser(text, options, oldTree: null, changes: null)) { var compilationUnit = (MainSyntax)parser.Parse().CreateRed(); var tree = new ParsedSyntaxTree(text, text.Encoding, text.ChecksumAlgorithm, path, options, compilationUnit, parser.Directives); tree.VerifySource(); return(tree); } }