From 4a031107ac962ccfafa32685795891c346176510 Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Sun, 26 Jun 2016 19:30:23 +0200 Subject: [PATCH] Support for Sublime Text YAML syntax definitions Sublime Text YAML syntax definitions use the .sublime-syntax file extension Most syntax files declare a YAML 1.2 syntax although they are YAML 1.1 compatible Thus, the YAML version header is stripped off before parsing Displays a warning if parsing fails In .sublime-syntax files, the scope is under the 'scope' key -- as opposed to the usual 'scopeName' key --- script/convert-grammars | 21 ++++++++++++++++----- vendor/grammars/NSIS | 2 +- vendor/grammars/awk-sublime | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/script/convert-grammars b/script/convert-grammars index ec3287db..56a38607 100755 --- a/script/convert-grammars +++ b/script/convert-grammars @@ -42,7 +42,7 @@ class DirectoryPackage case File.extname(path.downcase) when '.plist' path.split('/')[-2] == 'Syntaxes' - when '.tmlanguage' + when '.tmlanguage', '.sublime-syntax' true when '.cson', '.json' path.split('/')[-2] == 'grammars' @@ -114,7 +114,7 @@ class SVNPackage def fetch(tmp_dir) `svn export -q "#{url}/Syntaxes" "#{tmp_dir}/Syntaxes"` raise "Failed to export SVN repository: #{url}: #{$?.to_s}" unless $?.success? - Dir["#{tmp_dir}/Syntaxes/*.{plist,tmLanguage,tmlanguage}"] + Dir["#{tmp_dir}/Syntaxes/*.{plist,tmLanguage,tmlanguage,sublime-syntax}"] end end @@ -148,6 +148,17 @@ def load_grammar(path) case File.extname(path.downcase) when '.plist', '.tmlanguage' Plist::parse_xml(path) + when '.sublime-syntax' + content = File.read(path) + # Attempt to parse YAML file even if it has a YAML 1.2 header + if content.lines[0] =~ /^%YAML[ :]1\.2/ + content = content.lines[1..-1].join + end + begin + YAML.load(content) + rescue Psych::SyntaxError => e + $stderr.puts "Failed to parse YAML grammar '#{path}'" + end when '.cson' cson = `"#{CSONC}" "#{path}"` raise "Failed to convert CSON grammar '#{path}': #{$?.to_s}" unless $?.success? @@ -169,7 +180,7 @@ def load_grammars(tmp_dir, source, all_scopes) else SingleFile.new(source) end - elsif source.end_with?('.tmLanguage', '.plist') + elsif source.end_with?('.tmLanguage', '.plist', '.sublime-syntax') SingleGrammar.new(source) elsif source.start_with?('https://github.com') GitHubPackage.new(source) @@ -185,7 +196,7 @@ def load_grammars(tmp_dir, source, all_scopes) p.fetch(tmp_dir).map do |path| grammar = load_grammar(path) - scope = grammar['scopeName'] + scope = grammar['scopeName'] || grammar['scope'] if all_scopes.key?(scope) unless all_scopes[scope] == p.url @@ -204,7 +215,7 @@ def install_grammars(grammars, path) installed = [] grammars.each do |grammar| - scope = grammar['scopeName'] + scope = grammar['scopeName'] || grammar['scope'] File.write(File.join(GRAMMARS_PATH, "#{scope}.json"), JSON.pretty_generate(grammar)) installed << scope end diff --git a/vendor/grammars/NSIS b/vendor/grammars/NSIS index e0524002..b9be931f 160000 --- a/vendor/grammars/NSIS +++ b/vendor/grammars/NSIS @@ -1 +1 @@ -Subproject commit e052400204103acc26c14feeb624dd7ce6157611 +Subproject commit b9be931f41ac6039208494f8e98fd53a2394e517 diff --git a/vendor/grammars/awk-sublime b/vendor/grammars/awk-sublime index 7ec7d154..792d9215 160000 --- a/vendor/grammars/awk-sublime +++ b/vendor/grammars/awk-sublime @@ -1 +1 @@ -Subproject commit 7ec7d154469c05780cfeecca8fc00fda6f9ac0e7 +Subproject commit 792d9215315758c505a44a325b910bedc87bd10b