Skip to content

Commit

Permalink
Add language support for NAMESPACE & .Rbuildignore (#1221)
Browse files Browse the repository at this point in the history
  • Loading branch information
nx10 authored Nov 23, 2022
1 parent e7fcb1d commit b3e107e
Show file tree
Hide file tree
Showing 5 changed files with 316 additions and 0 deletions.
2 changes: 2 additions & 0 deletions language/rbuildignore-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
33 changes: 33 additions & 0 deletions language/rnamespace-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"comments": {
"lineComment": "#"
},
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
"autoClosingPairs": [
["#'", ""],
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"],
["`", "`"]
],
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"],
["`", "`"]
],
"folding": {
"markers": {
"start": "^\\s*#region",
"end": "^\\s*#endregion"
}
}
}
32 changes: 32 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"onLanguage:rd",
"onLanguage:rmd",
"onLanguage:debian-control.r",
"onLanguage:namespace.r",
"onLanguage:buildignore.r",
"workspaceContains:**/*.{rproj,Rproj,r,R,rd,Rd,rmd,Rmd}",
"onCommand:r.createRTerm",
"onCommand:r.runSource",
Expand Down Expand Up @@ -183,6 +185,26 @@
".lintr"
],
"configuration": "./language/dcf-configuration.json"
},
{
"id": "namespace.r",
"aliases": [
"R NAMESPACE"
],
"filenames": [
"NAMESPACE"
],
"configuration": "./language/rnamespace-configuration.json"
},
{
"id": "buildignore.r",
"aliases": [
"R ignore"
],
"filenames": [
".Rbuildignore"
],
"configuration": "./language/rbuildignore-configuration.json"
}
],
"snippets": [
Expand Down Expand Up @@ -287,6 +309,16 @@
"injectTo": [
"source.cpp"
]
},
{
"language": "namespace.r",
"scopeName": "namespace.r",
"path": "./syntax/rnamespace.json"
},
{
"language": "buildignore.r",
"scopeName": "buildignore.r",
"path": "./syntax/rbuildignore.json"
}
],
"commands": [
Expand Down
27 changes: 27 additions & 0 deletions syntax/rbuildignore.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"scopeName": "buildignore.r",
"fileTypes": [
".Rbuildignore"
],
"patterns": [
{
"include": "#ignore-line"
}
],
"repository": {
"ignore-line": {
"patterns": [
{
"comment": "source.regexp.python and source.js.regexp both work",
"begin": "^",
"end": "$",
"patterns": [
{
"include": "source.js.regexp"
}
]
}
]
}
}
}
222 changes: 222 additions & 0 deletions syntax/rnamespace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
{
"scopeName": "namespace.r",
"fileTypes": [
"NAMESPACE"
],
"patterns": [
{
"include": "#directive-export"
},
{
"include": "#directive-export-pattern"
},
{
"include": "#directive-export-s3"
},
{
"include": "#directive-import"
},
{
"include": "#directive-import-dynlib"
},
{
"include": "#directive-import-from"
},
{
"include": "#comment"
}
],
"repository": {
"arglist-highlight-all": {
"patterns": [
{
"match": "([^,\\s)]+|`[^`]+`)\\s*",
"captures":{
"1": { "name": "markup.underline" }
}
}
]
},
"arglist-highlight-first": {
"patterns": [
{
"begin": "\\s*([^,\\s)]+|`[^`]+`)\\s*",
"beginCaptures":{
"1": { "name": "markup.underline" }
},
"end": "(?=\\))",
"patterns": [
{
"match": "\\s*([^,\\s)]+|`[^`]+`)\\s*",
"captures":{
"1": { "name": "variable.parameter" }
}
}
]
}
]
},
"arglist-highlight-not-first": {
"patterns": [
{
"begin": "\\s*([^,\\s)]+|`[^`]+`)\\s*",
"beginCaptures":{
"1": { "name": "variable.parameter" }
},
"end": "(?=\\))",
"patterns": [
{
"match": "\\s*([^,\\s)]+|`[^`]+`)\\s*",
"captures":{
"1": { "name": "markup.underline" }
}
}
]
}
]
},
"directive-export": {
"patterns": [
{
"begin": "^\\s*(export|exportClasses|exportMethods)\\s*(\\()",
"beginCaptures":{
"1": { "name": "variable.language" },
"2": { "name": "punctuation.section.parens.start" }
},
"contentName": "meta.function-call.arguments.r",
"end": "(\\))",
"endCaptures": {
"1": { "name": "punctuation.section.parens.end" }
},
"patterns": [
{
"include": "#arglist-highlight-all"
}
]
}
]
},
"directive-export-pattern": {
"patterns": [
{
"begin": "^\\s*(exportPattern|exportClassPattern)\\s*(\\()\\s*",
"beginCaptures":{
"1": { "name": "variable.language" },
"2": { "name": "punctuation.section.parens.start" }
},
"contentName": "meta.function-call.arguments.r",
"end": "\\s*(\\))",
"patterns": [
{
"comment": "unfortunately we can not just include source.js.regexp here as backticks need to be escaped",
"match": "\"[^\"]*\"",
"name": "string.quoted.double"
}
]
}
]
},

"directive-export-s3": {
"patterns": [
{
"begin": "^\\s*(S3method)\\s*(\\()",
"beginCaptures":{
"1": { "name": "variable.language" },
"2": { "name": "punctuation.section.parens.start" }
},
"end": "(\\))",
"endCaptures": {
"1": { "name": "punctuation.section.parens.end" }
},
"patterns": [
{
"include": "#arglist-highlight-first"
}
]
}
]
},
"directive-exports": {
"patterns": [
{
"match": "^\\s*(exportClasses|exportMethods|S3method)\\s*\\(([^\\)]*)\\s*\\)",
"captures":{
"1": { "name": "variable.language" },
"2": { "name": "markup.underline" }
}
}
]
},
"directive-import": {
"patterns": [
{
"begin": "^\\s*(import)\\s*(\\()",
"beginCaptures":{
"1": { "name": "keyword.control" },
"2": { "name": "punctuation.section.parens.start" }
},
"end": "(:?\\s*,\\s*(except=c\\([^)]*\\)))?\\s*(\\))",
"endCaptures": {
"1": { "name": "variable.parameter" },
"2": { "name": "punctuation.section.parens.end" }
},
"patterns": [
{
"include": "#arglist-highlight-all"
}
]
}
]
},
"directive-import-dynlib": {
"patterns": [
{
"begin": "^\\s*(useDynLib)\\s*(\\()",
"beginCaptures":{
"1": { "name": "keyword.control" },
"2": { "name": "punctuation.section.parens.start" }
},
"end": "(\\))",
"endCaptures": {
"1": { "name": "punctuation.section.parens.end" }
},
"patterns": [
{
"include": "#arglist-highlight-first"
}
]
}
]
},
"directive-import-from": {
"patterns": [
{
"begin": "^\\s*(importFrom|importClassesFrom|importMethodsFrom)\\s*(\\()",
"beginCaptures":{
"1": { "name": "keyword.control" },
"2": { "name": "punctuation.section.parens.start" }
},
"end": "(\\))",
"endCaptures": {
"1": { "name": "punctuation.section.parens.end" }
},
"patterns": [
{
"include": "#arglist-highlight-not-first"
}
]
}
]
},
"comment": {
"patterns": [
{
"comment": "comment",
"match": "#[^$]*",
"name": "comment.line.number-sign"
}
]
}
}
}

0 comments on commit b3e107e

Please sign in to comment.