public static Tuple <Nitra.Language, GrammarDescriptor[], LibReference[], bool> Deserialize(string text, Func <string, Assembly> assemblyResolver) { var reader = new StringReader(text); var languageInfo = (Language)_serializer.Deserialize(reader); var languageAssembly = assemblyResolver(languageInfo.Path); var language = Nitra.Language.GetLanguages(languageAssembly).FirstOrDefault(l => String.Equals(l.FullName, languageInfo.Name, StringComparison.Ordinal)); if (language == null) { throw new ApplicationException(string.Format("Language '{0}' not found in assembly '{1}'.", languageInfo.Name, languageAssembly.Location)); } var dynamicExtensions = new List <GrammarDescriptor>(); foreach (var extensionInfo in languageInfo.DynamicExtensions) { var extensionAssembly = assemblyResolver(extensionInfo.Path); var descriptor = GrammarDescriptor.GetDescriptors(extensionAssembly).FirstOrDefault(g => String.Equals(g.FullName, extensionInfo.Name, StringComparison.Ordinal)); if (descriptor == null) { throw new ApplicationException(string.Format("Syntax module '{0}' not found in assembly '{1}'.", extensionInfo.Name, extensionAssembly.Location)); } dynamicExtensions.Add(descriptor); } var libs = languageInfo.Libs == null ? new LibReference[0] : languageInfo.Libs.Select(LibReference.Deserialize).ToArray(); var disableSemanticAnalysis = languageInfo.DisableSemanticAnalysis; return(Tuple.Create(language, dynamicExtensions.ToArray(), libs, disableSemanticAnalysis)); }
private static void OnNormalizedAssembliesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var model = (TestSuiteCreateOrEditModel)d; var oldLanguages = model.Languages.ToHashSet(); var oldDynamicExtensions = model.DynamicExtensions.ToDictionary(x => x.Descriptor); foreach (var assembly in (Assembly[])e.NewValue) { foreach (var language in Language.GetLanguages(assembly)) { if (!oldLanguages.Remove(language)) { model.Languages.Add(language); } } foreach (var descriptor in GrammarDescriptor.GetDescriptors(assembly)) { if (!oldDynamicExtensions.Remove(descriptor)) { model.DynamicExtensions.Add(new DynamicExtensionModel(descriptor)); } } } foreach (var language in oldLanguages) { model.Languages.Remove(language); } foreach (var pair in oldDynamicExtensions) { model.DynamicExtensions.Remove(pair.Value); } }
static GrammarDescriptor[] LoadAssembly(string assemblyFilePath) { var assembly = Assembly.ReflectionOnlyLoadFrom(assemblyFilePath); var runtime = typeof(ParseResult).Assembly.GetName(); foreach (var reference in assembly.GetReferencedAssemblies()) { if (reference.Name == runtime.Name) { if (reference.Version == runtime.Version) { break; } throw new ApplicationException("Assembly '" + assemblyFilePath + "' use incompatible runtime (Nitra.Runtime.dll) version " + reference.Version + ". The current runtime has version " + runtime.Version + "."); } } assembly = Assembly.LoadFrom(assemblyFilePath); return(GrammarDescriptor.GetDescriptors(assembly)); }
public SyntaxModuleVm(GrammarDescriptor grammarDescriptor) { this.GrammarDescriptor = grammarDescriptor; }
public DynamicExtensionModel(GrammarDescriptor descriptor) { _descriptor = descriptor; }
private static StartRuleDescriptor GetStratRule(XAttribute startRule, GrammarDescriptor m) { return(startRule == null ? null : m.Rules.OfType <StartRuleDescriptor>().First(r => r.Name == startRule.Value)); }
private static StartRuleDescriptor GetStratRule(XAttribute startRule, GrammarDescriptor m) { return startRule == null ? null : m.Rules.OfType<StartRuleDescriptor>().First(r => r.Name == startRule.Value); }