Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve langauge_kdl #479

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,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
134 changes: 77 additions & 57 deletions plugins/language_kdl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,82 +3,102 @@ local syntax = require "core.syntax"

local identifier = "\"?[^%d%s\\/%(%){}<>;%[%]=,\"][^%s\\/%(%){}<>;%[%]=,\"]*\"?"

local node_comment = { symbols = {} }
node_comment["patterns"] = {
{ pattern = { "{", "}" }, type = "comment", syntax = node_comment },
{ pattern = "[^{}]+", type = "comment" }
}

local nested_multiline = { symbols = {} }
nested_multiline["patterns"] = {
{ pattern = { "/%*", "%*/" }, type = "comment", syntax = nested_multiline },
{ pattern = "[^/*]+", type = "comment" },
}

syntax.add {
name = "KDL",
files = { "%.kdl" },
files = { "%.kdl$" },
space_handling = false,
comment = "//",
block_comment = {"/*", "*/"},
patterns = {
{
pattern = "^%s*".. identifier .."%s*",
type = "keyword"
},--
pattern = "^%s*".. identifier .."%s*",
type = "keyword"
},
{ pattern = "%s+", type = "normal" },
{
pattern = "[{;]%s*()" .. identifier .. "%s*",
type = {"normal", "keyword"}
},--
pattern = "[{;]%s*()" .. identifier .. "%s*",
type = {"normal", "keyword"}
},

{ pattern = { "r#+\"", "\"#+" }, type = "string" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = "[%-+]?0x[%x_]+", type = "number" },
{ pattern = "[%-+]?0b[01_]+", type = "number" },
{ pattern = "[%-+]?0o[0-7_]+", type = "number" },
{
pattern = "[%-+]?[%d_]+%.[%d_]+e[%-+]?[%d_]+",
type = "number"
},
{ pattern = "[%-+]?[%d_]+%.[%d_]+", type = "number" },
pattern = "[%-+]?[%d_]+%.[%d_]+e[%-+]?[%d_]+",
type = "number"
},
{ pattern = "[%-+]?[%d_]+%.[%d_]+", type = "number" },
{ pattern = "[%-+]?[%d_]+e[%-+]?[%d_]+", type = "number" },
{ pattern = "[%-+]?[%d_]+", type = "number" },
{ pattern = "/[%-/].-\n", type = "comment" },
{ pattern = {"/%*", "%*/"}, type = "comment" },
{ pattern = "//.*", type = "comment" },
{
pattern = { "/%-.*{", "}" },
type = "comment", syntax = node_comment
},
Comment on lines +48 to +51
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion in #477 also covered comments like this:

mynode /-"commented" "not commented" {
  a
  b
}

This doesn't, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, your suggestion was very helpful but it only 80% worked, so I made some tweaks. This is how it behaves now, which I believe matches the spec

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, only the single parameter should be commented.
In what cases did my suggestion not work?

{
pattern = {"/%*", "%*/"},
type = "comment", syntax = nested_multiline
},
{ pattern = identifier, type = "keyword2" },
{
pattern = "%(()" .. identifier .. "()%)",
type = {"normal", "function", "normal"}
},
{
pattern = "%(()" .. identifier .. "()%)",
type = {"normal", "function", "normal"}
},
},
symbols = {
["null"] = "literal",
["true"] = "literal",
["false"] = "literal",
["i8"] = "function",
["i32"] = "function",
["i16"] = "function",
["i64"] = "function",
["u8"] = "function",
["u32"] = "function",
["u16"] = "function",
["u64"] = "function",
["isize"] = "function",
["usize"] = "function",
["f32"] = "function",
["f64"] = "function",
["decimal64"] = "function",
["decimal128"] = "function",
["date-time"] = "function",
["time"] = "function",
["date"] = "function",
["duration"] = "function",
["decimal"] = "function",
["currency"] = "function",
["country-2"] = "function",
["country-3"] = "function",
["country-subdivision"] = "function",
["email"] = "function",
["idn-email"] = "function",
["hostname"] = "function",
["idn-hostname"] = "function",
["ipv4"] = "function",
["ipv6"] = "function",
["url"] = "function",
["url-reference"] = "function",
["irl"] = "function",
["irl-reference"] = "function",
["url-template"] = "function",
["uuid"] = "function",
["regex"] = "function",
["base64"] = "function",
["null"] = "literal",
["true"] = "literal",
["false"] = "literal",
["i8"] = "function",
["i32"] = "function",
["i16"] = "function",
["i64"] = "function",
["u8"] = "function",
["u32"] = "function",
["u16"] = "function",
["u64"] = "function",
["isize"] = "function",
["usize"] = "function",
["f32"] = "function",
["f64"] = "function",
["decimal64"] = "function",
["decimal128"] = "function",
["date-time"] = "function",
["time"] = "function",
["date"] = "function",
["duration"] = "function",
["decimal"] = "function",
["currency"] = "function",
["country-2"] = "function",
["country-3"] = "function",
["country-subdivision"] = "function",
["email"] = "function",
["idn-email"] = "function",
["hostname"] = "function",
["idn-hostname"] = "function",
["ipv4"] = "function",
["ipv6"] = "function",
["url"] = "function",
["url-reference"] = "function",
["irl"] = "function",
["irl-reference"] = "function",
["url-template"] = "function",
["uuid"] = "function",
["regex"] = "function",
["base64"] = "function",
},
}