Skip to content

Commit

Permalink
Add language_ring (#487)
Browse files Browse the repository at this point in the history
* Add `language_ring`

* Update plugins/language_ring.lua

Co-authored-by: Guldoman <[email protected]>

* Update language_ring.lua

* More improvements

* Update language_ring.lua

* Update language_ring.lua

* Update plugins/language_ring.lua

Co-authored-by: Guldoman <[email protected]>

* Update manifest.json

* Add `Ring` String Interpolation

* Update plugins/language_ring.lua

Co-authored-by: Guldoman <[email protected]>

* Update language_ring.lua

* Update language_ring.lua

* Update plugins/language_ring.lua

Co-authored-by: Guldoman <[email protected]>

---------

Co-authored-by: Guldoman <[email protected]>
  • Loading branch information
ysdragon and Guldoman authored Nov 25, 2024
1 parent cdc74a9 commit ff2bab3
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ to follow with `extra.follow_branch`.*
| [`language_psql`](plugins/language_psql.lua?raw=1) | Syntax for the postgresql database access language |
| [`language_r`](plugins/language_R.lua?raw=1) | Syntax for [R](https://www.r-project.org/) scripting language |
| [`language_rescript`](plugins/language_rescript.lua?raw=1) | Syntax for the [ReScript](https://rescript-lang.org/) programming language |
| [`language_ring`](plugins/language_ring.lua?raw=1) | Syntax for the [Ring](https://ring-lang.net/) programming language |
| [`language_rivet`](plugins/language_rivet.lua?raw=1) | Syntax for the [Rivet](https://github.com/rivet-lang/rivet) programming language |
| [`language_ruby`](plugins/language_ruby.lua?raw=1) | Syntax for the [Ruby](https://www.ruby-lang.org/) programming language |
| [`language_rust`](plugins/language_rust.lua?raw=1) | Syntax for the [Rust](https://rust-lang.org/) programming language |
Expand Down
13 changes: 12 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"language_psql": {},
"language_r": {},
"language_rescript": {},
"language_ring": {},
"language_rivet": {},
"language_ruby": {},
"language_rust": {},
Expand All @@ -168,7 +169,7 @@
"id": "meta_languages",
"mod_version": "3",
"type": "meta",
"version": "0.1.18"
"version": "0.1.19"
},
{
"description": "Align multiple carets and selections *([clip](https://user-images.githubusercontent.com/2798487/165631951-532f8d24-d596-4dd0-9d21-ff53c71ed32f.mp4))*",
Expand Down Expand Up @@ -1492,6 +1493,16 @@
],
"version": "0.1"
},
{
"description": "Syntax for the [Ring](https://ring-lang.net/) programming language",
"id": "language_ring",
"mod_version": "3",
"path": "plugins/language_ring.lua",
"tags": [
"language"
],
"version": "0.1"
},
{
"description": "Syntax for the [Rivet](https://github.com/rivet-lang/rivet) programming language",
"id": "language_rivet",
Expand Down
92 changes: 92 additions & 0 deletions plugins/language_ring.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
-- mod-version:3
-- Refrence: https://ring-lang.github.io/doc1.21.2/syntaxflexibility.html

local syntax = require "core.syntax"

-- Keywords
local keywords = {
"enablehashcomments", "disablehashcomments", "call", "class", "from", "get", "give",
"import", "load", "new", "package", "private", "changeringkeyword", "changeringoperator",
"loadsyntax", "endclass", "endpackage", "if", "but", "else", "elseif", "ok", "for",
"foreach", "to", "next", "catch", "step", "endfor", "while", "other", "end", "do",
"endwhile", "endswitch", "endtry", "try", "break", "bye", "continue", "default",
"endfunc", "endfunction", "return", "switch", "case", "on", "off", "again", "exit",
"loop", "done", "in", "func", "def", "nl"
}

-- Types using ring type hints library
local types = {
"char", "unsigned", "signed", "int", "short", "long", "float", "double", "void",
"byte", "boolean", "string", "list", "number", "object", "public", "static",
"abstract", "protected", "override"
}

-- Special values
local literals = {
"true", "false", "null"
}

-- Built-in functions
local builtin_functions = {
"see", "put", "print"
}

local symbols = {}

for _, keyword in ipairs(keywords) do
symbols[keyword:upper()] = "keyword"
symbols[keyword:gsub("^%l", string.upper)] = "keyword"
symbols[keyword] = "keyword"
end

for _, type in ipairs(types) do
symbols[type:upper()] = "keyword2"
symbols[type:gsub("^%l", string.upper)] = "keyword2"
symbols[type] = "keyword2"
end

for _, literal in ipairs(literals) do
symbols[literal:upper()] = "literal"
symbols[literal:gsub("^%l", string.upper)] = "literal"
symbols[literal] = "literal"
end

for _, func in ipairs(builtin_functions) do
symbols[func:upper()] = "function"
symbols[func:gsub("^%l", string.upper)] = "function"
symbols[func] = "function"
end

local string_syntax = {
patterns = {
{ pattern = {"%#{", "}", "\\"}, type="keyword", syntax = ".ring" },
{ pattern = "[^#\"`']+", type = "string"},
{ pattern = "[#\"`']", type = "string"}
},
symbols = {}
}

syntax.add {
name = "Ring",
files = { "%.ring$", "%.rh$", "%.rform$" },
comment = "//",
patterns = {
{ pattern = "#.*", type = "comment" },
{ pattern = "//.*", type = "comment" },
{ pattern = { "/%*", "%*/" }, type = "comment" },
{ pattern = { '"', '"', '\\' }, type = "string", syntax = string_syntax },
{ pattern = { "'", "'", '\\' }, type = "string", syntax = string_syntax },
{ pattern = { "`", "`", '\\' }, type = "string", syntax = string_syntax },
{ pattern = "-?%d+[%d%.]*f?", type = "number" },
{ pattern = "-?0x%x+", type = "number" },
{ pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },
{ pattern = "[%a_][%w_]*%f[(]", type = "function" },
{ pattern = "[Dd][Ee][Ff]()%s+()[%a_][%w_]*", type = { "keyword", "normal", "function" } },
{ pattern = "[Ff][Uu][Nn][Cc]()%s+()[%a_][%w_]*", type = { "keyword", "normal", "function" } },
{ pattern = "[Cc][Ll][Aa][Ss][Ss]()%s+()[%a_][%w_]*", type = { "keyword", "normal", "function" } },
{ pattern = "[%a_][%w_]*", type = "symbol" },
{ pattern = "%?", type = "keyword" },
{ pattern = ":[%a_][%w_]*", type = "literal" },
},
symbols = symbols
}

0 comments on commit ff2bab3

Please sign in to comment.