Merge pull request #3079 from pchaigno/yaml-grammars

YAML grammar files
This commit is contained in:
Arfon Smith
2016-09-04 16:54:35 -07:00
committed by GitHub
4 changed files with 22 additions and 7 deletions

View File

@@ -22,6 +22,8 @@ vendor/grammars/Docker.tmbundle:
- source.dockerfile
vendor/grammars/Elm/:
- source.elm
- text.html.mediawiki.elm-build-output
- text.html.mediawiki.elm-documentation
vendor/grammars/FreeMarker.tmbundle:
- text.html.ftl
vendor/grammars/G-Code/:
@@ -602,6 +604,8 @@ vendor/grammars/sublime-text-ox/:
vendor/grammars/sublime-typescript/:
- source.ts
- source.tsx
- text.error-list
- text.find-refs
vendor/grammars/sublime-varnish:
- source.varnish.vcl
vendor/grammars/sublime_cobol:

View File

@@ -42,7 +42,7 @@ class DirectoryPackage
case File.extname(path.downcase)
when '.plist'
path.split('/')[-2] == 'Syntaxes'
when '.tmlanguage'
when '.tmlanguage', '.yaml-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,YAML-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 '.yaml-tmlanguage', '.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', '.YAML-tmLanguage', '.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