From 7f5980230cbae8e6ffb3d631255c5a32add5c0b1 Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Sun, 2 Jul 2023 23:36:01 +0200 Subject: [PATCH 1/2] feat: add include keyword to wit grammar --- syntaxes/wit.tmLanguage.json | 64 ++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/syntaxes/wit.tmLanguage.json b/syntaxes/wit.tmLanguage.json index 9c9be59..a736d4f 100644 --- a/syntaxes/wit.tmLanguage.json +++ b/syntaxes/wit.tmLanguage.json @@ -194,6 +194,70 @@ "end": "\\s*(?<=\\n)", "applyEndPatternLast": 1 }, + { + "name": "meta.include-item.wit", + "comment": "Syntax for WIT like `include \"use-path\"`", + "begin": "\\s*\\b(include)\\s+([^\\s]+)\\s*", + "beginCaptures": { + "1": { + "name": "keyword.control.include.include-item.wit" + }, + "2": { + "name": "meta.use-path.include-item.wit", + "patterns": [ + { + "include": "#use-path" + } + ] + } + }, + "patterns": [ + { + "name": "meta.with.include-item.wit", + "begin": "\\b(with)\\b\\s+(\\{)\\s*", + "beginCaptures": { + "1": { + "name": "keyword.control.with.include-item.wit" + }, + "2": { + "name": "punctuation.brackets.curly.begin.wit" + } + }, + "patterns": [ + { + "include": "#comment" + }, + { + "name": "meta.include-names-item.wit", + "match": "\\s*([^\\s]+)\\s+(as)\\s+([^\\s\\,]+)\\s*", + "captures": { + "1": { + "name": "variable.other.id.include-names-item.wit" + }, + "2": { + "name": "keyword.control.as.include-names-item.wit" + }, + "3": { + "name": "entity.name.type.include-names-item.wit" + } + } + }, + { + "name": "punctuation.comma.wit", + "match": "\\s*(\\,)" + } + ], + "end": "\\s*(\\})\\s*", + "endCaptures": { + "1": { + "name": "punctuation.brackets.curly.end.wit" + } + } + } + ], + "end": "\\s*(?<=\\n)", + "applyEndPatternLast": 1 + }, { "include": "#use" }, From 1ec267921e54e755ab6130a78b56089bb01dc62d Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Sun, 2 Jul 2023 23:39:25 +0200 Subject: [PATCH 2/2] chore: add grammar tests for include keyword --- tests/grammar/world.wit | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/grammar/world.wit b/tests/grammar/world.wit index 83440ee..31d84b7 100644 --- a/tests/grammar/world.wit +++ b/tests/grammar/world.wit @@ -6,6 +6,10 @@ default world some-world { // ^^^^^^^^^^ entity.name.type.id.world-item.wit // ^ meta.world-item.wit punctuation.brackets.curly.begin.wit + include foo +//^^^^^^^ keyword.control.include.include-item.wit +// ^^^ meta.use-path.include-item.wit entity.name.namespace.id.use-path.wit + import filesystem: filesystem.filesystem //^^^^^^ keyword.control.import.import-item.wit // ^^^^^^^^^^ variable.other.id.import-item.wit @@ -51,6 +55,20 @@ world another-world { // ^^^^^^^^^^^^^ entity.name.type.id.world-item.wit // ^ meta.world-item.wit punctuation.brackets.curly.begin.wit + include bar with { a as a1, b as b1 } +//^^^^^^^ keyword.control.include.include-item.wit +// ^^^ meta.use-path.include-item.wit entity.name.namespace.id.use-path.wit +// ^^^^ keyword.control.with.include-item.wit +// ^ meta.with.include-item.wit punctuation.brackets.curly.begin.wit +// ^ variable.other.id.include-names-item.wit +// ^^ keyword.control.as.include-names-item.wit +// ^^ entity.name.type.include-names-item.wit +// ^ meta.with.include-item.wit punctuation.comma.wit +// ^ variable.other.id.include-names-item.wit +// ^^ keyword.control.as.include-names-item.wit +// ^^ entity.name.type.include-names-item.wit +// ^ meta.with.include-item.wit punctuation.brackets.curly.end.wit + use pkg.path.{id} //^^^ keyword.other.use.use-item.wit // ^^^ variable.language.self.use-path.wit