internal void ParseMapping(YamlMappingNode node, Dictionary <string, string> variables) { var children = node.Children; if (children.ContainsKey(new YamlScalarNode("match"))) { includesAndMatches.Add(Sublime3Format.ReadMatch(node, variables)); return; } YamlNode val; if (children.TryGetValue(new YamlScalarNode("meta_scope"), out val)) { Sublime3Format.ParseScopes(metaScope, ((YamlScalarNode)val).Value); } if (children.TryGetValue(new YamlScalarNode("meta_content_scope"), out val)) { Sublime3Format.ParseScopes(metaContentScope, ((YamlScalarNode)val).Value); } if (children.TryGetValue(new YamlScalarNode("meta_include_prototype"), out val)) { MetaIncludePrototype = ((YamlScalarNode)val).Value != "false"; } if (children.TryGetValue(new YamlScalarNode("include"), out val)) { includesAndMatches.Add(((YamlScalarNode)val).Value); } }
static SyntaxMatch ReadMatch(PDictionary dict) { List <string> matchScope = new List <string> (); Sublime3Format.ParseScopes(matchScope, (dict ["name"] as PString)?.Value); Captures captures = null; var captureDict = dict ["captures"] as PDictionary; if (captureDict != null) { captures = ReadCaptureDictionary(captureDict); } ContextReference pushContext = null; var begin = (dict ["begin"] as PString)?.Value; if (begin != null) { Captures beginCaptures = null; captureDict = dict ["beginCaptures"] as PDictionary; if (captureDict != null) { beginCaptures = ReadCaptureDictionary(captureDict); } var end = (dict ["end"] as PString)?.Value; Captures endCaptures = null; List <string> endScope = new List <string> (); if (end != null) { captureDict = dict ["endCaptures"] as PDictionary; if (captureDict != null) { endCaptures = ReadCaptureDictionary(captureDict); } var list = new List <object> (); if (end != null) { list.Add(new SyntaxMatch(Sublime3Format.CompileRegex(end), endScope, endCaptures ?? captures, null, true, null, null)); } var patternsArray = dict ["patterns"] as PArray; if (patternsArray != null) { ReadPatterns(patternsArray, list); } List <string> metaContent = null; var contentScope = (dict ["contentName"] as PString)?.Value; if (contentScope != null) { metaContent = new List <string> { contentScope }; } var ctx = new SyntaxContext("__generated begin/end capture context", list, metaScope: metaContent); pushContext = new AnonymousMatchContextReference(ctx); } var whileLoop = (dict ["while"] as PString)?.Value; endCaptures = null; endScope = new List <string> (); if (whileLoop != null) { captureDict = dict ["endCaptures"] as PDictionary; if (captureDict != null) { endCaptures = ReadCaptureDictionary(captureDict); } var list = new List <object> (); if (whileLoop != null) { list.Add(new SyntaxMatch("^(?!" + Sublime3Format.CompileRegex(whileLoop) + ")", endScope, endCaptures ?? captures, null, true, null, null)); } var patternsArray = dict ["patterns"] as PArray; if (patternsArray != null) { ReadPatterns(patternsArray, list); } List <string> metaContent = null; var contentScope = (dict ["contentName"] as PString)?.Value; if (contentScope != null) { metaContent = new List <string> { contentScope }; } var ctx = new SyntaxContext("__generated begin/while capture context", list, metaScope: metaContent); pushContext = new AnonymousMatchContextReference(ctx); } return(new SyntaxMatch(Sublime3Format.CompileRegex(begin), matchScope, beginCaptures ?? captures, pushContext, false, null, null)); } var match = (dict ["match"] as PString)?.Value; if (match == null) { return(null); } return(new SyntaxMatch(Sublime3Format.CompileRegex(match), matchScope, captures, pushContext, false, null, null)); }
/* * if (provider.Name.EndsWith (".vssettings", StringComparison.Ordinal)) { * styles [name] = OldFormat.ImportVsSetting (provider.Name, stream); * } else if (provider.Name.EndsWith (".json", StringComparison.Ordinal)) { * styles [name] = OldFormat.ImportColorScheme (stream); * } else { * styles [name] = TextMateFormat.LoadEditorTheme (stream); * } * styles [name].FileName = provider.Name; * * */ static object LoadFile(LanguageBundle bundle, string file, Func <Stream> openStream, Func <IStreamProvider> getStreamProvider) { if (file.EndsWith(".json", StringComparison.OrdinalIgnoreCase)) { using (var stream = openStream()) { string styleName; JSonFormat format; if (TryScanJSonStyle(stream, out styleName, out format)) { switch (format) { case JSonFormat.OldSyntaxTheme: var theme = OldFormat.ImportColorScheme(getStreamProvider().Open()); if (theme != null) { bundle.Add(theme); } return(theme); case JSonFormat.TextMateJsonSyntax: SyntaxHighlightingDefinition highlighting = TextMateFormat.ReadHighlightingFromJson(getStreamProvider().Open()); if (highlighting != null) { bundle.Add(highlighting); } return(highlighting); } } } } else if (file.EndsWith(".tmTheme", StringComparison.OrdinalIgnoreCase)) { using (var stream = openStream()) { string styleName = ScanTextMateStyle(stream); if (!string.IsNullOrEmpty(styleName)) { var theme = TextMateFormat.LoadEditorTheme(getStreamProvider().Open()); if (theme != null) { bundle.Add(theme); } return(theme); } else { LoggingService.LogError("Invalid .tmTheme theme file : " + file); } } } else if (file.EndsWith(".vssettings", StringComparison.OrdinalIgnoreCase)) { using (var stream = openStream()) { string styleName = Path.GetFileNameWithoutExtension(file); EditorTheme theme; try { theme = OldFormat.ImportVsSetting(styleName, getStreamProvider().Open()); } catch (StyleImportException e) { switch (e.Reason) { case StyleImportException.ImportFailReason.Unknown: LoggingService.LogWarning("Unknown error in theme file : " + file, e); break; case StyleImportException.ImportFailReason.NoValidColorsFound: LoggingService.LogWarning("No colors defined in vssettings : " + file, e); break; } return(null); } catch (Exception e) { LoggingService.LogWarning("Invalid theme : " + file, e); return(null); } if (theme != null) { bundle.Add(theme); } return(theme); } } else if (file.EndsWith(".tmLanguage", StringComparison.OrdinalIgnoreCase)) { using (var stream = openStream()) { var highlighting = TextMateFormat.ReadHighlighting(stream); if (highlighting != null) { bundle.Add(highlighting); } return(highlighting); } } else if (file.EndsWith(".sublime-syntax", StringComparison.OrdinalIgnoreCase)) { using (var stream = new StreamReader(openStream())) { var highlighting = Sublime3Format.ReadHighlighting(stream); if (highlighting != null) { bundle.Add(highlighting); } return(highlighting); } } else if (file.EndsWith(".sublime-package", StringComparison.OrdinalIgnoreCase) || file.EndsWith(".tmbundle", StringComparison.OrdinalIgnoreCase)) { try { using (var stream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(openStream())) { var entry = stream.GetNextEntry(); var newBundle = new LanguageBundle(Path.GetFileNameWithoutExtension(file), file); while (entry != null) { if (entry.IsFile && !entry.IsCrypted) { if (stream.CanDecompressEntry) { byte [] data = new byte [entry.Size]; stream.Read(data, 0, (int)entry.Size); LoadFile(newBundle, entry.Name, () => new MemoryStream(data), () => new MemoryStreamProvider(data, entry.Name)); } } entry = stream.GetNextEntry(); } languageBundles.Add(newBundle); return(newBundle); } } catch (Exception e) { LoggingService.LogError("Error while reading : " + file, e); } } else if (file.EndsWith(".tmPreferences", StringComparison.OrdinalIgnoreCase)) { using (var stream = openStream()) { var preference = TextMateFormat.ReadPreferences(stream); if (preference != null) { bundle.Add(preference); } return(preference); } } else if (file.EndsWith(".tmSnippet", StringComparison.OrdinalIgnoreCase)) { using (var stream = openStream()) { var snippet = TextMateFormat.ReadSnippet(stream); if (snippet != null) { bundle.Add(snippet); } return(snippet); } } else if (file.EndsWith(".sublime-snippet", StringComparison.OrdinalIgnoreCase)) { using (var stream = openStream()) { var snippet = Sublime3Format.ReadSnippet(stream); if (snippet != null) { bundle.Add(snippet); } return(snippet); } } return(null); }
protected override SyntaxHighlightingDefinition LoadSyntaxHighlightingDefinition(Stream stream) { using (var sr = new StreamReader(stream)) return(Sublime3Format.ReadHighlighting(sr)); }