diff --git a/.gitignore b/.gitignore index 5091cc25b5..46709939db 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ test/fixtures/ace_modes.json /tmp *.bundle *.so +linguist-grammars* \ No newline at end of file diff --git a/script/grammar-compiler b/script/grammar-compiler index 234346da8d..b1945ea4d9 100755 --- a/script/grammar-compiler +++ b/script/grammar-compiler @@ -6,9 +6,15 @@ cd "$(dirname "$0")/.." image="linguist/grammar-compiler:latest" mkdir -p grammars -docker pull $image +if [ -z "$REBUILD" ]; then + docker pull $image +else + cd tools/grammars + image=$(docker build -q .) + cd "../.." +fi exec docker run --rm \ - -u $(id -u $USER):$(id -g $USER) \ - -v $PWD:/src/linguist \ - -w /src/linguist $image "$@" + -u "$(id -u "$USER")":"$(id -g "$USER")" \ + -v "$PWD:/src/linguist" \ + -w /src/linguist "$image" "$@" diff --git a/tools/grammars/compiler/data.go b/tools/grammars/compiler/data.go index e046971871..9b1e911dfe 100644 --- a/tools/grammars/compiler/data.go +++ b/tools/grammars/compiler/data.go @@ -11,6 +11,10 @@ var GrammarAliases = map[string]string{ "source.asciidoc": "text.html.asciidoc", "source.perl6": "source.perl6fe", "source.css.scss": "source.scss", + "source.git-config": "source.gitconfig", + "source.smarty": "text.html.smarty", + "text.slm": "text.slim", + "text.pug": "text.jade", } var KnownFields = map[string]bool{ @@ -34,3 +38,15 @@ var KnownFields = map[string]bool{ "backgroundColor": true, "increaseIndentPattern": true, } + +// GrammarsInNonStdPath is a list of grammars known to have their syntax .cson or .json files in non-standard directories. +var GrammarsInNonStdPath = map[string]bool{ + "conllu-linguist-grammar": true, + "hy.tmLanguage": true, +} + +// IgnoredFiles is a list of files that look like syntax files but aren't, or are known to be broken and never likely to be fixed. +var IgnoredFiles = map[string]bool{ + "ballerina-grammar/syntaxes/ballerina.monarch.json": true, + "oz-tmbundle/Originals/Oz.tmLanguage": true, +} diff --git a/tools/grammars/compiler/loader.go b/tools/grammars/compiler/loader.go index ce7d3ec0ad..44368105f3 100644 --- a/tools/grammars/compiler/loader.go +++ b/tools/grammars/compiler/loader.go @@ -122,7 +122,7 @@ func isValidGrammar(path string, info os.FileInfo) bool { case ".tmlanguage", ".yaml-tmlanguage": return true case ".cson", ".json": - return strings.HasSuffix(dir, "/grammars") || strings.HasSuffix(dir, "/syntaxes") + return strings.HasSuffix(dir, "/grammars") || strings.HasSuffix(dir, "/syntaxes") || GrammarsInNonStdPath[filepath.Base(dir)] default: return false } diff --git a/tools/grammars/compiler/loader_fs.go b/tools/grammars/compiler/loader_fs.go index a94795c4f4..c90e6eb793 100644 --- a/tools/grammars/compiler/loader_fs.go +++ b/tools/grammars/compiler/loader_fs.go @@ -63,6 +63,16 @@ func (l *fsLoader) load() { } for _, path := range grammars { + rel, err := filepath.Rel("/src/linguist/vendor/grammars/", path) + if err != nil { + l.Fail(err) + return + } + + if IgnoredFiles[rel] { + continue + } + data, err := ioutil.ReadFile(path) if err != nil { l.Fail(err)