/// <summary> /// Builds the Q# syntax tree from the given files/source paris. /// </summary> private static QsCompiler.SyntaxTree.QsNamespace[] BuildQsSyntaxTree(ImmutableDictionary <Uri, string> sources, QsReferences references, QSharpLogger logger) { var loadOptions = new QsCompiler.CompilationLoader.Configuration { GenerateFunctorSupport = true }; var loaded = new QsCompiler.CompilationLoader(_ => sources, _ => references, loadOptions, logger); return(loaded.GeneratedSyntaxTree?.ToArray()); }
/// <summary> /// Compiles the given Q# code and returns the list of elements found in it. /// The compiler does this on a best effort, so it will return the elements even if the compilation fails. /// </summary> public IEnumerable <QsCompiler.SyntaxTree.QsNamespaceElement> IdentifyElements(string source) { var ns = NonNullable <string> .New(Snippets.SNIPPETS_NAMESPACE); var logger = new QSharpLogger(null); var sources = new Dictionary <Uri, string>() { { new Uri($"file:///temp"), $"namespace {ns.Value} {{ {source} }}" } }.ToImmutableDictionary(); var references = QsReferences.Empty; var loadOptions = new QsCompiler.CompilationLoader.Configuration(); // do not generate functor support var loaded = new QsCompiler.CompilationLoader(_ => sources, _ => references, loadOptions, logger); return(loaded.VerifiedCompilation?.SyntaxTree[ns].Elements); }