From 012d7da5bcddc125e898fc35439ea1723c5bb9e4 Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Mon, 18 Sep 2017 16:15:57 +0200 Subject: [PATCH] [r] use grammar from https://github.com/Ikuyadeu/vscode-R --- build/npm/update-grammar.js | 8 +- extensions/r/OSSREADME.json | 16 +- extensions/r/package.json | 2 +- extensions/r/syntaxes/r.tmLanguage.json | 607 ++++++++++++++---- .../r/test/colorize-results/test_r.json | 354 ++++++++-- 5 files changed, 769 insertions(+), 218 deletions(-) diff --git a/build/npm/update-grammar.js b/build/npm/update-grammar.js index fca60d83242..9d0cad11dc7 100644 --- a/build/npm/update-grammar.js +++ b/build/npm/update-grammar.js @@ -22,7 +22,7 @@ function getOptions(urlString) { headers: { 'User-Agent': 'NodeJS' } - } + }; } function download(url, redirectCount) { @@ -100,7 +100,9 @@ exports.update = function (repoId, repoPath, dest, modifyGrammar) { result.version = 'https://github.com/' + repoId + '/commit/' + info.commitSha; } for (let key in grammar) { - result[key] = grammar[key]; + if (!result.hasOwnProperty(key)) { + result[key] = grammar[key]; + } } try { @@ -116,7 +118,7 @@ exports.update = function (repoId, repoPath, dest, modifyGrammar) { }); }, console.error); -} +}; if (path.basename(process.argv[1]) === 'update-grammar.js') { for (var i = 3; i < process.argv.length; i += 2) { diff --git a/extensions/r/OSSREADME.json b/extensions/r/OSSREADME.json index 9cf3b6c42fe..bd7a0cab273 100644 --- a/extensions/r/OSSREADME.json +++ b/extensions/r/OSSREADME.json @@ -1,17 +1,7 @@ // ATTENTION - THIS DIRECTORY CONTAINS THIRD PARTY OPEN SOURCE MATERIALS: [{ - "name": "textmate/r.tmbundle", + "name": "Ikuyadeu/vscode-R", "version": "0.0.0", - "license": "TextMate Bundle License", - "repositoryURL": "https://github.com/textmate/r.tmbundle", - "licenseDetail": [ - "Copyright (c) textmate-r.tmbundle project authors", - "", - "If not otherwise specified (see below), files in this folder fall under the following license: ", - "", - "Permission to copy, use, modify, sell and distribute this", - "software is granted. This software is provided \"as is\" without", - "express or implied warranty, and with no claim as to its", - "suitability for any purpose." - ] + "license": "MIT", + "repositoryURL": "https://github.com/Ikuyadeu/vscode-R" }] diff --git a/extensions/r/package.json b/extensions/r/package.json index e1104e23440..96f89e8c67b 100644 --- a/extensions/r/package.json +++ b/extensions/r/package.json @@ -4,7 +4,7 @@ "publisher": "vscode", "engines": { "vscode": "*" }, "scripts": { - "update-grammar": "node ../../build/npm/update-grammar.js textmate/r.tmbundle Syntaxes/R.plist ./syntaxes/r.tmLanguage.json" + "update-grammar": "node ../../build/npm/update-grammar.js Ikuyadeu/vscode-R syntax/r.json ./syntaxes/r.tmLanguage.json" }, "contributes": { "languages": [{ diff --git a/extensions/r/syntaxes/r.tmLanguage.json b/extensions/r/syntaxes/r.tmLanguage.json index 0ba828e6eb2..81b7bca2cb9 100644 --- a/extensions/r/syntaxes/r.tmLanguage.json +++ b/extensions/r/syntaxes/r.tmLanguage.json @@ -1,209 +1,548 @@ { "information_for_contributors": [ - "This file has been converted from https://github.com/textmate/r.tmbundle/blob/master/Syntaxes/R.plist", + "This file has been converted from https://github.com/Ikuyadeu/vscode-R/blob/master/syntax/r.json", "If you want to provide a fix or improvement, please create a pull request against the original repository.", "Once accepted there, we are happy to receive an update request." ], - "version": "https://github.com/textmate/r.tmbundle/commit/6b04ff3424f3f1cdfe64a9cfb71d8765959be250", + "version": "https://github.com/Ikuyadeu/vscode-R/commit/b4fdb1db24cdd690e88bc2bbb7f608426e63da67", "fileTypes": [ "R", "r", - "s", "S", + "s", "Rprofile" ], + "foldingStartMarker": "(\\(\\s*$|\\{\\s*$)", + "foldingStopMarker": "(^\\s*\\)|^\\s*\\})", "keyEquivalent": "^~R", "name": "R", "patterns": [ { - "captures": { - "1": { - "name": "comment.line.pragma.r" - }, - "2": { - "name": "entity.name.pragma.name.r" - } - }, - "match": "^(#pragma[ \\t]+mark)[ \\t](.*)", - "name": "comment.line.pragma-mark.r" - }, - { - "begin": "(^[ \\t]+)?(?=#)", - "beginCaptures": { - "1": { - "name": "punctuation.whitespace.comment.leading.r" - } - }, - "end": "(?!\\G)", - "patterns": [ - { - "begin": "#", - "beginCaptures": { - "0": { - "name": "punctuation.definition.comment.r" - } - }, - "end": "\\n", - "name": "comment.line.number-sign.r" - } - ] + "include": "#roxygen" }, { - "match": "\\b(logical|numeric|character|complex|matrix|array|data\\.frame|list|factor)(?=\\s*\\()", - "name": "storage.type.r" + "include": "#comments" }, { - "match": "\\b(function|if|break|next|repeat|else|for|return|switch|while|in|invisible)\\b", - "name": "keyword.control.r" + "include": "#constants" }, { - "match": "\\b((0(x|X)[0-9a-fA-F]*)|(([0-9]+\\.?[0-9]*)|(\\.[0-9]+))((e|E)(\\+|-)?[0-9]+)?)(i|L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\\b", - "name": "constant.numeric.r" + "include": "#keywords" }, { - "match": "\\b(T|F|TRUE|FALSE|NULL|NA|Inf|NaN)\\b", - "name": "constant.language.r" + "include": "#storage-type" }, { - "match": "\\b(pi|letters|LETTERS|month\\.abb|month\\.name)\\b", - "name": "support.constant.misc.r" + "include": "#strings" }, { - "match": "(\\-|\\+|\\*|\\/|%\\/%|%%|%\\*%|%in%|%o%|%x%|\\^)", - "name": "keyword.operator.arithmetic.r" + "include": "#brackets" }, { - "match": "(=|<-|<<-|->|->>)", - "name": "keyword.operator.assignment.r" + "include": "#function-declarations" }, { - "match": "(==|!=|<>|<|>|<=|>=)", - "name": "keyword.operator.comparison.r" + "include": "#lambda-functions" }, { - "match": "(!|&{1,2}|[|]{1,2})", - "name": "keyword.operator.logical.r" + "include": "#builtin-functions" }, { - "match": "(\\.\\.\\.|\\$|@|:|\\~)", - "name": "keyword.other.r" + "include": "#function-calls" }, { - "begin": "\"", - "beginCaptures": { - "0": { - "name": "punctuation.definition.string.begin.r" - } - }, - "end": "\"", - "endCaptures": { - "0": { - "name": "punctuation.definition.string.end.r" - } - }, - "name": "string.quoted.double.r", + "include": "#general-variables" + } + ], + "repository": { + "comments": { "patterns": [ { - "match": "\\\\.", - "name": "constant.character.escape.r" + "captures": { + "1": { + "name": "comment.line.pragma.r" + }, + "2": { + "name": "entity.name.pragma.name.r" + } + }, + "match": "^(#pragma[ \\t]+mark)[ \\t](.*)", + "name": "comment.line.pragma-mark.r" + }, + { + "begin": "(^[ \\t]+)?(?=#)", + "beginCaptures": { + "1": { + "name": "punctuation.whitespace.comment.leading.r" + } + }, + "end": "(?!\\G)", + "patterns": [ + { + "begin": "#", + "beginCaptures": { + "0": { + "name": "punctuation.definition.comment.r" + } + }, + "end": "\\n", + "name": "comment.line.number-sign.r" + } + ] } ] }, - { - "begin": "'", - "beginCaptures": { - "0": { - "name": "punctuation.definition.string.begin.r" - } - }, - "end": "'", - "endCaptures": { - "0": { - "name": "punctuation.definition.string.end.r" - } - }, - "name": "string.quoted.single.r", + "constants": { "patterns": [ { - "match": "\\\\.", - "name": "constant.character.escape.r" + "match": "\\b(pi|letters|LETTERS|month\\.abb|month\\.name)\\b", + "name": "support.constant.misc.r" + }, + { + "match": "\\b(TRUE|FALSE|NULL|NA|NA_integer_|NA_real_|NA_complex_|NA_character_|Inf|NaN)\\b", + "name": "constant.language.r" + }, + { + "match": "\\b0(x|X)[0-9a-fA-F]+i\\b", + "name": "constant.numeric.imaginary.hexadecimal.r" + }, + { + "match": "\\b[0-9]+\\.?[0-9]*(?:(e|E)(\\+|-)?[0-9]+)?i\\b", + "name": "constant.numeric.imaginary.decimal.r" + }, + { + "match": "\\.[0-9]+(?:(e|E)(\\+|-)?[0-9]+)?i\\b", + "name": "constant.numeric.imaginary.decimal.r" + }, + { + "match": "\\b0(x|X)[0-9a-fA-F]+L\\b", + "name": "constant.numeric.integer.hexadecimal.r" + }, + { + "match": "\\b(?:[0-9]+\\.?[0-9]*)L\\b", + "name": "constant.numeric.integer.decimal.r" + }, + { + "match": "\\b0(x|X)[0-9a-fA-F]+\\b", + "name": "constant.numeric.float.hexadecimal.r" + }, + { + "match": "\\b[0-9]+\\.?[0-9]*(?:(e|E)(\\+|-)?[0-9]+)?\\b", + "name": "constant.numeric.float.decimal.r" + }, + { + "match": "\\.[0-9]+(?:(e|E)(\\+|-)?[0-9]+)?\\b", + "name": "constant.numeric.float.decimal.r" } ] }, - { - "captures": { - "1": { - "name": "entity.name.function.r" + "general-variables": { + "patterns": [ + { + "captures": { + "1": { + "name": "variable.parameter.r" + }, + "2": { + "name": "keyword.operator.assignment.r" + } + }, + "match": "([[:alpha:].][[:alnum:]._]*)\\s*(=)(?=[^=])" }, - "2": { - "name": "keyword.operator.assignment.r" + { + "match": "\\b([\\d_][[:alnum:]._]+)\\b", + "name": "invalid.illegal.variable.other.r" }, - "3": { - "name": "keyword.control.r" + { + "match": "\\b([[:alnum:]_]+)(?=::)", + "name": "entity.namespace.r" + }, + { + "match": "\\b([[:alnum:]._]+)\\b", + "name": "variable.other.r" } - }, - "match": "([[:alpha:].][[:alnum:]._]*)\\s*(<-)\\s*(function)", - "name": "meta.function.r" + ] }, - { - "captures": { - "1": { - "name": "entity.name.tag.r" + "keywords": { + "patterns": [ + { + "match": "\\b(break|next|repeat|else|in)\\b", + "name": "keyword.control.r" + }, + { + "match": "\\b(ifelse|if|for|return|switch|while|invisible)\\b(?=\\s*\\()", + "name": "keyword.control.r" + }, + { + "match": "(\\-|\\+|\\*|\\/|%\\/%|%%|%\\*%|%o%|%x%|\\^)", + "name": "keyword.operator.arithmetic.r" + }, + { + "match": "(=|<-|<<-|->|->>)", + "name": "keyword.operator.assignment.r" + }, + { + "match": "(==|!=|<>|<|>|<=|>=)", + "name": "keyword.operator.comparison.r" + }, + { + "match": "(!|&{1,2}|[|]{1,2})", + "name": "keyword.operator.logical.r" + }, + { + "match": "(%in%|:=|%between%|%chin%|%like%|%\\+%|%\\+replace%|%:%|%do%|%dopar%|%>%|%<>%|%T>%|%\\$%)", + "name": "keyword.operator.other.r" }, - "4": { - "name": "entity.name.type.r" + { + "match": "(\\.\\.\\.|\\$|:|\\~|@)", + "name": "keyword.other.r" } - }, - "match": "(setMethod|setReplaceMethod|setGeneric|setGroupGeneric|setClass)\\s*\\(\\s*([[:alpha:]\\d]+\\s*=\\s*)?(\"|\\x{27})([a-zA-Z._\\[\\$@][a-zA-Z0-9._\\[]*?)\\3.*", - "name": "meta.method.declaration.r" + ] }, - { - "match": "([[:alpha:].][[:alnum:]._]*)\\s*\\(" + "storage-type": { + "patterns": [ + { + "match": "\\b(character|complex|double|expression|integer|list|logical|numeric|single|raw)\\b(?=\\s*\\()", + "name": "storage.type.r" + } + ] }, - { - "captures": { - "1": { - "name": "variable.parameter.r" + "strings": { + "patterns": [ + { + "begin": "\"", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin.r" + } + }, + "end": "\"", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end.r" + } + }, + "name": "string.quoted.double.r", + "patterns": [ + { + "match": "\\\\.", + "name": "constant.character.escape.r" + } + ] }, - "2": { - "name": "keyword.operator.assignment.r" + { + "begin": "'", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin.r" + } + }, + "end": "'", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end.r" + } + }, + "name": "string.quoted.single.r", + "patterns": [ + { + "match": "\\\\.", + "name": "constant.character.escape.r" + } + ] } - }, - "match": "([[:alpha:].][[:alnum:]._]*)\\s*(=)(?=[^=])" + ] }, - { - "match": "\\b([\\d_][[:alnum:]._]+)\\b", - "name": "invalid.illegal.variable.other.r" + "brackets": { + "patterns": [ + { + "begin": "\\(", + "beginCaptures": { + "0": { + "name": "punctuation.section.parens.begin.r" + } + }, + "end": "\\)", + "endCaptures": { + "0": { + "name": "punctuation.section.parens.end.r" + } + }, + "patterns": [ + { + "include": "source.r" + } + ] + }, + { + "begin": "\\[(?!\\[)", + "beginCaptures": { + "0": { + "name": "punctuation.section.brackets.single.begin.r" + } + }, + "end": "\\](?!\\])", + "endCaptures": { + "0": { + "name": "punctuation.section.brackets.single.end.r" + } + }, + "patterns": [ + { + "include": "source.r" + } + ] + }, + { + "begin": "\\[\\[", + "beginCaptures": { + "0": { + "name": "punctuation.section.brackets.double.begin.r" + } + }, + "end": "\\]\\]", + "endCaptures": { + "0": { + "name": "punctuation.section.brackets.double.end.r" + } + }, + "contentName": "meta.item-access.arguments.r", + "patterns": [ + { + "include": "source.r" + } + ] + }, + { + "begin": "\\{", + "beginCaptures": { + "0": { + "name": "punctuation.section.braces.begin.r" + } + }, + "end": "\\}", + "endCaptures": { + "0": { + "name": "punctuation.section.braces.end.r" + } + }, + "patterns": [ + { + "include": "source.r" + } + ] + } + ] }, - { - "match": "\\b([[:alnum:]_]+)(?=::)", - "name": "entity.namespace.r" + "function-declarations": { + "patterns": [ + { + "begin": "^\\s*([a-zA-Z0-9._:]*)\\s*(<