Skip to content
Merged
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
62 changes: 31 additions & 31 deletions vscode/grammars/ruby.cson.json
Original file line number Diff line number Diff line change
Expand Up @@ -1616,13 +1616,13 @@
]
},
{
"begin": "(?=(?><<[-~]([\"'`]?)((?:[_\\w]+_|)HTML)\\b\\1))",
"begin": "(?=(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)HTML)\\b\\1))",
"comment": "Heredoc with embedded HTML",
"end": "(?!\\G)",
"name": "meta.embedded.block.html",
"patterns": [
{
"begin": "(?><<[-~]([\"'`]?)((?:[_\\w]+_|)HTML)\\b\\1)",
"begin": "(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)HTML)\\b\\1)",
"beginCaptures": {
"0": {
"name": "string.definition.begin.ruby"
Expand Down Expand Up @@ -1653,13 +1653,13 @@
]
},
{
"begin": "(?=(?><<[-~]([\"'`]?)((?:[_\\w]+_|)HAML)\\b\\1))",
"begin": "(?=(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)HAML)\\b\\1))",
"comment": "Heredoc with embedded HAML",
"end": "(?!\\G)",
"name": "meta.embedded.block.haml",
"patterns": [
{
"begin": "(?><<[-~]([\"'`]?)((?:[_\\w]+_|)HAML)\\b\\1)",
"begin": "(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)HAML)\\b\\1)",
"beginCaptures": {
"0": {
"name": "string.definition.begin.ruby"
Expand Down Expand Up @@ -1690,13 +1690,13 @@
]
},
{
"begin": "(?=(?><<[-~]([\"'`]?)((?:[_\\w]+_|)XML)\\b\\1))",
"begin": "(?=(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)XML)\\b\\1))",
"comment": "Heredoc with embedded XML",
"end": "(?!\\G)",
"name": "meta.embedded.block.xml",
"patterns": [
{
"begin": "(?><<[-~]([\"'`]?)((?:[_\\w]+_|)XML)\\b\\1)",
"begin": "(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)XML)\\b\\1)",
"beginCaptures": {
"0": {
"name": "string.definition.begin.ruby"
Expand Down Expand Up @@ -1727,13 +1727,13 @@
]
},
{
"begin": "(?=(?><<[-~]([\"'`]?)((?:[_\\w]+_|)SQL)\\b\\1))",
"begin": "(?=(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)SQL)\\b\\1))",
"comment": "Heredoc with embedded SQL",
"end": "(?!\\G)",
"name": "meta.embedded.block.sql",
"patterns": [
{
"begin": "(?><<[-~]([\"'`]?)((?:[_\\w]+_|)SQL)\\b\\1)",
"begin": "(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)SQL)\\b\\1)",
"beginCaptures": {
"0": {
"name": "string.definition.begin.ruby"
Expand Down Expand Up @@ -1764,13 +1764,13 @@
]
},
{
"begin": "(?=(?><<[-~]([\"'`]?)((?:[_\\w]+_|)(?:GRAPHQL|GQL))\\b\\1))",
"begin": "(?=(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)(?:GRAPHQL|GQL))\\b\\1))",
"comment": "Heredoc with embedded GraphQL",
"end": "(?!\\G)",
"name": "meta.embedded.block.graphql",
"patterns": [
{
"begin": "(?><<[-~]([\"'`]?)((?:[_\\w]+_|)(?:GRAPHQL|GQL))\\b\\1)",
"begin": "(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)(?:GRAPHQL|GQL))\\b\\1)",
"beginCaptures": {
"0": {
"name": "string.definition.begin.ruby"
Expand Down Expand Up @@ -1801,13 +1801,13 @@
]
},
{
"begin": "(?=(?><<[-~]([\"'`]?)((?:[_\\w]+_|)CSS)\\b\\1))",
"begin": "(?=(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)CSS)\\b\\1))",
"comment": "Heredoc with embedded CSS",
"end": "(?!\\G)",
"name": "meta.embedded.block.css",
"patterns": [
{
"begin": "(?><<[-~]([\"'`]?)((?:[_\\w]+_|)CSS)\\b\\1)",
"begin": "(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)CSS)\\b\\1)",
"beginCaptures": {
"0": {
"name": "string.definition.begin.ruby"
Expand Down Expand Up @@ -1838,13 +1838,13 @@
]
},
{
"begin": "(?=(?><<[-~]([\"'`]?)((?:[_\\w]+_|)CPP)\\b\\1))",
"begin": "(?=(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)CPP)\\b\\1))",
"comment": "Heredoc with embedded C++",
"end": "(?!\\G)",
"name": "meta.embedded.block.cpp",
"patterns": [
{
"begin": "(?><<[-~]([\"'`]?)((?:[_\\w]+_|)CPP)\\b\\1)",
"begin": "(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)CPP)\\b\\1)",
"beginCaptures": {
"0": {
"name": "string.definition.begin.ruby"
Expand Down Expand Up @@ -1875,13 +1875,13 @@
]
},
{
"begin": "(?=(?><<[-~]([\"'`]?)((?:[_\\w]+_|)C)\\b\\1))",
"begin": "(?=(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)C)\\b\\1))",
"comment": "Heredoc with embedded C",
"end": "(?!\\G)",
"name": "meta.embedded.block.c",
"patterns": [
{
"begin": "(?><<[-~]([\"'`]?)((?:[_\\w]+_|)C)\\b\\1)",
"begin": "(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)C)\\b\\1)",
"beginCaptures": {
"0": {
"name": "string.definition.begin.ruby"
Expand Down Expand Up @@ -1912,13 +1912,13 @@
]
},
{
"begin": "(?=(?><<[-~]([\"'`]?)((?:[_\\w]+_|)(?:JS|JAVASCRIPT))\\b\\1))",
"begin": "(?=(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)(?:JS|JAVASCRIPT))\\b\\1))",
"comment": "Heredoc with embedded Javascript",
"end": "(?!\\G)",
"name": "meta.embedded.block.js",
"patterns": [
{
"begin": "(?><<[-~]([\"'`]?)((?:[_\\w]+_|)(?:JS|JAVASCRIPT))\\b\\1)",
"begin": "(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)(?:JS|JAVASCRIPT))\\b\\1)",
"beginCaptures": {
"0": {
"name": "string.definition.begin.ruby"
Expand Down Expand Up @@ -1949,13 +1949,13 @@
]
},
{
"begin": "(?=(?><<[-~]([\"'`]?)((?:[_\\w]+_|)JQUERY)\\b\\1))",
"begin": "(?=(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)JQUERY)\\b\\1))",
"comment": "Heredoc with embedded jQuery Javascript",
"end": "(?!\\G)",
"name": "meta.embedded.block.js.jquery",
"patterns": [
{
"begin": "(?><<[-~]([\"'`]?)((?:[_\\w]+_|)JQUERY)\\b\\1)",
"begin": "(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)JQUERY)\\b\\1)",
"beginCaptures": {
"0": {
"name": "string.definition.begin.ruby"
Expand Down Expand Up @@ -1986,13 +1986,13 @@
]
},
{
"begin": "(?=(?><<[-~]([\"'`]?)((?:[_\\w]+_|)(?:SH|SHELL))\\b\\1))",
"begin": "(?=(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)(?:SH|SHELL))\\b\\1))",
"comment": "Heredoc with embedded Shell",
"end": "(?!\\G)",
"name": "meta.embedded.block.shell",
"patterns": [
{
"begin": "(?><<[-~]([\"'`]?)((?:[_\\w]+_|)(?:SH|SHELL))\\b\\1)",
"begin": "(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)(?:SH|SHELL))\\b\\1)",
"beginCaptures": {
"0": {
"name": "string.definition.begin.ruby"
Expand Down Expand Up @@ -2023,13 +2023,13 @@
]
},
{
"begin": "(?=(?><<[-~]([\"'`]?)((?:[_\\w]+_|)LUA)\\b\\1))",
"begin": "(?=(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)LUA)\\b\\1))",
"comment": "Heredoc with embedded Lua",
"end": "(?!\\G)",
"name": "meta.embedded.block.lua",
"patterns": [
{
"begin": "(?><<[-~]([\"'`]?)((?:[_\\w]+_|)LUA)\\b\\1)",
"begin": "(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)LUA)\\b\\1)",
"beginCaptures": {
"0": {
"name": "string.definition.begin.ruby"
Expand Down Expand Up @@ -2060,13 +2060,13 @@
]
},
{
"begin": "(?=(?><<[-~]([\"'`]?)((?:[_\\w]+_|)RUBY)\\b\\1))",
"begin": "(?=(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)RUBY)\\b\\1))",
"comment": "Heredoc with embedded Ruby",
"end": "(?!\\G)",
"name": "meta.embedded.block.ruby",
"patterns": [
{
"begin": "(?><<[-~]([\"'`]?)((?:[_\\w]+_|)RUBY)\\b\\1)",
"begin": "(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)RUBY)\\b\\1)",
"beginCaptures": {
"0": {
"name": "string.definition.begin.ruby"
Expand Down Expand Up @@ -2097,13 +2097,13 @@
]
},
{
"begin": "(?=(?><<[-~]([\"'`]?)((?:[_\\w]+_|)(?:YAML|YML))\\b\\1))",
"begin": "(?=(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)(?:YAML|YML))\\b\\1))",
"comment": "Heredoc with embedded YAML",
"end": "(?!\\G)",
"name": "meta.embedded.block.yaml",
"patterns": [
{
"begin": "(?><<[-~]([\"'`]?)((?:[_\\w]+_|)(?:YAML|YML))\\b\\1)",
"begin": "(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)(?:YAML|YML))\\b\\1)",
"beginCaptures": {
"0": {
"name": "string.definition.begin.ruby"
Expand Down Expand Up @@ -2134,13 +2134,13 @@
]
},
{
"begin": "(?=(?><<[-~]([\"'`]?)((?:[_\\w]+_|)SLIM)\\b\\1))",
"begin": "(?=(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)SLIM)\\b\\1))",
"comment": "Heredoc with embedded Slim",
"end": "(?!\\G)",
"name": "meta.embedded.block.slim",
"patterns": [
{
"begin": "(?><<[-~]([\"'`]?)((?:[_\\w]+_|)SLIM)\\b\\1)",
"begin": "(?><<[-~]?([\"'`]?)((?:[_\\w]+_|)SLIM)\\b\\1)",
"beginCaptures": {
"0": {
"name": "string.definition.begin.ruby"
Expand Down Expand Up @@ -2197,7 +2197,7 @@
]
},
{
"begin": "(?>((<<[-~]([\"'`]?)(\\w+)\\3,\\s?)*<<[-~]([\"'`]?)(\\w+)\\5))(.*)",
"begin": "(?>((<<[-~]?([\"'`]?)(\\w+)\\3,\\s?)*<<[-~]?([\"'`]?)(\\w+)\\5))(.*)",
"beginCaptures": {
"1": {
"name": "string.definition.begin.ruby"
Expand Down
58 changes: 56 additions & 2 deletions vscode/src/test/suite/grammars.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,21 @@ suite("Grammars", () => {
`Tokens did not match expected for HEREDOC using ${delimiter}.`,
);
});

test(`bare HEREDOC using ${delimiter} is tokenized correctly`, () => {
const expectedTokens = [
[`<<${delimiter}`, ["source.ruby", languageConfig.name, "string.definition.begin.ruby"]],
[delimiter, ["source.ruby", languageConfig.name, "string.definition.end.ruby"]],
];
const ruby = expectedTokens.map((token) => token[0]).join("\n");
const actualTokens = tokenizeRuby(ruby);

assert.deepStrictEqual(
actualTokens,
expectedTokens,
`Tokens did not match expected for bare HEREDOC using ${delimiter}.`,
);
});
});
});

Expand Down Expand Up @@ -251,6 +266,45 @@ suite("Grammars", () => {
const actualTokens = tokenizeRuby(ruby);
assert.deepStrictEqual(actualTokens, expectedTokens);
});

test("HEREDOC without dash or tilde after parenthesis is tokenized correctly", () => {
const ruby = "p(<<FOO)\nfoo\nFOO";
const expectedTokens = [
["p", ["source.ruby", "support.function.kernel.ruby"]],
["(", ["source.ruby", "punctuation.section.function.ruby"]],
["<<FOO", ["source.ruby", "string.definition.begin.ruby"]],
[")", ["source.ruby", "punctuation.section.function.ruby"]],
["foo", ["source.ruby", "string.unquoted.heredoc.ruby"]],
["FOO", ["source.ruby", "string.definition.end.ruby"]],
];
const actualTokens = tokenizeRuby(ruby);
assert.deepStrictEqual(actualTokens, expectedTokens);
});

test("HEREDOC with dash after parenthesis is tokenized correctly", () => {
const ruby = "p(<<-FOO)\nfoo\nFOO";
const expectedTokens = [
["p", ["source.ruby", "support.function.kernel.ruby"]],
["(", ["source.ruby", "punctuation.section.function.ruby"]],
["<<-FOO", ["source.ruby", "string.definition.begin.ruby"]],
[")", ["source.ruby", "punctuation.section.function.ruby"]],
["foo", ["source.ruby", "string.unquoted.heredoc.ruby"]],
["FOO", ["source.ruby", "string.definition.end.ruby"]],
];
const actualTokens = tokenizeRuby(ruby);
assert.deepStrictEqual(actualTokens, expectedTokens);
});

test("plain HEREDOC without dash or tilde is tokenized correctly", () => {
const ruby = "<<FOO\nfoo\nFOO";
const expectedTokens = [
["<<FOO", ["source.ruby", "string.definition.begin.ruby"]],
["foo", ["source.ruby", "string.unquoted.heredoc.ruby"]],
["FOO", ["source.ruby", "string.definition.end.ruby"]],
];
const actualTokens = tokenizeRuby(ruby);
assert.deepStrictEqual(actualTokens, expectedTokens);
});
});

suite("Backtick String Literals", () => {
Expand Down Expand Up @@ -735,13 +789,13 @@ suite("Grammars", () => {
const delimiter = delimiters.length > 1 ? `(?:${delimiters.join("|")})` : delimiters[0];

return {
begin: `(?=(?><<[-~](["'\`]?)((?:[_\\w]+_|)${delimiter})\\b\\1))`,
begin: `(?=(?><<[-~]?(["'\`]?)((?:[_\\w]+_|)${delimiter})\\b\\1))`,
comment: `Heredoc with embedded ${label}`,
end: "(?!\\G)",
name,
patterns: [
{
begin: `(?><<[-~](["'\`]?)((?:[_\\w]+_|)${delimiter})\\b\\1)`,
begin: `(?><<[-~]?(["'\`]?)((?:[_\\w]+_|)${delimiter})\\b\\1)`,
beginCaptures: {
"0": { name: "string.definition.begin.ruby" },
},
Expand Down