From 1d9b9b4bac7acd88bd076b9a0f48c6abcb2a1de1 Mon Sep 17 00:00:00 2001 From: Jelle Date: Tue, 26 Apr 2022 10:40:23 +0200 Subject: [PATCH 1/6] edit: Merge into blocks --- syntaxes/renpy.tmLanguage_2.json | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/syntaxes/renpy.tmLanguage_2.json b/syntaxes/renpy.tmLanguage_2.json index 5b41732..8a30072 100644 --- a/syntaxes/renpy.tmLanguage_2.json +++ b/syntaxes/renpy.tmLanguage_2.json @@ -3,12 +3,23 @@ "scopeName": "source.renpy", "firstLineMatch": "^#!/.*\\brenpy\\b", "patterns": [ - { "include": "#comments" }, - { "include": "#python-statements" }, - { "include": "#expressions" }, - { "include": "#renpy-keywords"} + { "include": "#statements" }, + { "include": "#expressions" } ], "repository": { + "statements": { + "patterns": [ + { "include": "#comments" }, + { "include": "#python-statements" }, + { "include": "#renpy-keywords" } + ] + }, + "expressions": { + "patterns": [ + { "include": "#strings" } + ] + }, + "python-statements": { "name": "embedded.python", "patterns": [ @@ -63,9 +74,7 @@ "end": "($)", "patterns": [{ "include": "#codetags" }] }, - "expressions": { - "patterns": [{ "include": "#strings" }] - }, + "strings": { "patterns": [ { "include": "#string-quoted-double" }, From 9169823e02ade1bfff7e77bf1a86ecce1d57a5e8 Mon Sep 17 00:00:00 2001 From: Jelle Date: Tue, 26 Apr 2022 11:56:12 +0200 Subject: [PATCH 2/6] feat(grammar): Improved block capture Some features where not captured and others where dismissed. * Block ending is now correctly detected in nested blocks * Block is also detected on partial invalid parameters * Block is now correctly detected on all variants * Block now correctly highlights any optional keywords in any order * Single line now correctly detects define and default only if there is no other character in front * Single line now highlights the variable it defines (Python highlighting seems to skip this for some reason?) --- examples/game/script.rpy | 23 ++++++++++ package.json | 6 ++- syntaxes/renpy.tmLanguage_2.json | 79 ++++++++++++++++++++++++++++---- 3 files changed, 97 insertions(+), 11 deletions(-) diff --git a/examples/game/script.rpy b/examples/game/script.rpy index 6459170..8e779ee 100644 --- a/examples/game/script.rpy +++ b/examples/game/script.rpy @@ -94,8 +94,31 @@ screen hello_title(): linear 0.5 alpha 1.0 # sample python code +init: + "Renpy code block" + +python: + renpy.pause(delay) + +python in X: + renpy.pause(delay) + +python hide: + renpy.pause(delay) + +python early: + renpy.pause(delay) init python: + renpy.pause(delay) + +init -1 python in N: + renpy.pause(delay) + +init 99 python hide: + renpy.pause(delay) + +init python hide early in Namespace: def sampleFunction(name, delay, position=(0,0)): """ diff --git a/package.json b/package.json index 20db77d..d023cc6 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,11 @@ { "language": "renpy", "scopeName": "source.renpy", - "path": "./syntaxes/renpy.tmLanguage_2.json" + "path": "./syntaxes/renpy.tmLanguage_2.json", + "embeddedLanguages": { + "meta.embedded.line.python": "python", + "meta.embedded.block.python": "python" + } } ], "snippets": [ diff --git a/syntaxes/renpy.tmLanguage_2.json b/syntaxes/renpy.tmLanguage_2.json index 8a30072..5710f64 100644 --- a/syntaxes/renpy.tmLanguage_2.json +++ b/syntaxes/renpy.tmLanguage_2.json @@ -21,26 +21,85 @@ }, "python-statements": { - "name": "embedded.python", "patterns": [ { - "comments": "[TODO: REDO] Renpy python block", - "name": "meta.embedded.python.block", - "begin": "^(\\s*)(init\\s-?\\d*\\s?)?(python(\\searly)?(\\sin\\s\\w+)?)", + "comment": "Renpy python block", + "contentName": "meta.embedded.block.python", + + "begin": "(^[ \\t]+)?\\b(?:(init) (?:(-)?(\\d*) )?)?(python)([\\w \\t]*)(:)", "beginCaptures": { - "0": { - "patterns": [{ "include": "#renpy-keywords" }] + "1": { + "name": "punctuation.whitespace.embedded.leading.python" + }, + "2": { + "comment": "init", + "name": "keyword.renpy" + }, + "3": { + "comment": "- sign", + "name": "keyword.operator.arithmetic.python" + }, + "4": { + "comment": "init priority numeric", + "name": "constant.numeric.dec.python" + }, + "5": { + "comment": "python", + "name": "keyword.renpy" + }, + "6": { + "comment": "Statement options", + "name": "meta.embedded.block.python.options", + + "patterns": [ + { + "comment": "in statement", + "match": "(?: (in) (\\w+))", + "captures": + { + "1": { + "comment": "in", + "name": "keyword.renpy" + }, + "2": { + "comment": "namespace", + "name": "entity.name.namespace" + } + } + }, + { + "comment": "keywords", + "match": "\\b(hide|early|in)\\b", + "name": "keyword.renpy" + } + ] + }, + "7": { + "name": "punctuation.section.python.begin.renpy" } }, - "end": "^\\1(?=\\S)|^(?=\\S)", + "end":"^(?!(\\1[ \\t]+)|($))", "patterns": [{ "include": "source.python" }] }, { "comment": "Match begin and end of python one line statements", - "name": "meta.embedded.python.single-line", - "begin": "(?<=(\\$|define|default)\\s)", + "contentName": "meta.embedded.line.python", + "begin": "(\\$|\\bdefine|\\bdefault)(?=\\s)", + "beginCaptures": { + "1": { + "name": "keyword.renpy" + } + }, "end": "\\R$", - "patterns": [{ "include": "source.python" }] + + "patterns": [ + { + "comment": "Type the first name as a variable (Probably not needed, but python doesn't seem to catch it)", + "match": "(? Date: Tue, 26 Apr 2022 12:40:57 +0200 Subject: [PATCH 3/6] feat(grammar): adds new keywords Adds back all the Renpy keywords that can be used outside of a python block --- syntaxes/renpy.tmLanguage_2.json | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/syntaxes/renpy.tmLanguage_2.json b/syntaxes/renpy.tmLanguage_2.json index 5710f64..a722211 100644 --- a/syntaxes/renpy.tmLanguage_2.json +++ b/syntaxes/renpy.tmLanguage_2.json @@ -11,7 +11,7 @@ "patterns": [ { "include": "#comments" }, { "include": "#python-statements" }, - { "include": "#renpy-keywords" } + { "include": "#keywords" } ] }, "expressions": { @@ -103,23 +103,37 @@ } ] }, - "renpy-keywords": { + + "keywords": { "patterns": [ - { "match": "\\$", "name": "keyword.renpy" }, { - "match": "\\b(\\$|init|python|early|in|define|default)\\b", + "comment": "Python statement keywords", + "match": "\\b(init|python|hide|early|in|define|default)\\b", "name": "keyword.renpy" }, { - "match": "(?<=init\\s)-?\\d+", - "name": "constant.numeric" + "comment": "Renpy keywords", + "match": "\\b(play|pause|screen|scene|show|image|transform)\\b", + "name": "keyword.other.renpy" + }, + { + "comment": "Conditional control flow keywords", + "match": "\\b(if|elif|else)\\b", + "name": "keyword.control.conditional.renpy" }, { - "match": "(?<=in\\s)\\w+", - "name": "entity.name.namespace" + "comment": "Control flow keywords", + "match": "\\b(for|while|pass|return|menu|label|jump|call)\\b", + "name": "keyword.control.renpy" + }, + { + "comment": "[TODO: Should probably only be a keyword in the expression]Renpy sub expression keywords", + "match": "\\b(set|expression|pass|sound|at|with|from)\\b", + "name": "keyword.other.renpy" } ] }, + "codetags": { "match": "(?:\\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\\b)", "captures": { "1": { "name": "keyword.codetag.notation.renpy" } } From 4b299168c9165023519484846e0a8c513bfd9575 Mon Sep 17 00:00:00 2001 From: Jelle Date: Tue, 26 Apr 2022 12:54:32 +0200 Subject: [PATCH 4/6] feat(grammar): Add label statement --- syntaxes/renpy.tmLanguage_2.json | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/syntaxes/renpy.tmLanguage_2.json b/syntaxes/renpy.tmLanguage_2.json index a722211..d2c5ad8 100644 --- a/syntaxes/renpy.tmLanguage_2.json +++ b/syntaxes/renpy.tmLanguage_2.json @@ -10,6 +10,7 @@ "statements": { "patterns": [ { "include": "#comments" }, + { "include": "#renpy-statements" }, { "include": "#python-statements" }, { "include": "#keywords" } ] @@ -104,6 +105,39 @@ ] }, + "renpy-statements": { + "patterns": [ + { "include": "#label" } + ] + }, + + "label": { + "patterns": [ + { + "name": "meta.label.renpy", + "begin": "(^[ \\t]+)?\\b(label) +([^_\\d]\\w*)(?= *:)", + "beginCaptures": { + "1": { + "name": "punctuation.whitespace.label.leading.renpy" + }, + "2": { + "name": "keyword.control.renpy" + }, + "3":{ + "name": "entity.name.function.renpy" + } + }, + + "end": "(:|(?=[#'\"\\n]))", + "endCaptures": { + "1": { + "name": "punctuation.section.label.begin.renpy" + } + } + } + ] + }, + "keywords": { "patterns": [ { From 41579e3f4de22eb709f1f1340a599fd947c6f4bf Mon Sep 17 00:00:00 2001 From: Jelle Date: Fri, 29 Apr 2022 00:14:04 +0200 Subject: [PATCH 5/6] edit: Review updates * fixed tabs * label is now defined as a normal keyword instead of a control flow keyword * label now supports having parameters * labels can now also start with . _ or [a-zA-Z] * stores can only start with [a-zA-Z_] --- syntaxes/renpy.tmLanguage_2.json | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/syntaxes/renpy.tmLanguage_2.json b/syntaxes/renpy.tmLanguage_2.json index d2c5ad8..0899da2 100644 --- a/syntaxes/renpy.tmLanguage_2.json +++ b/syntaxes/renpy.tmLanguage_2.json @@ -55,7 +55,7 @@ "patterns": [ { "comment": "in statement", - "match": "(?: (in) (\\w+))", + "match": "(?: (in) ([a-zA-Z_]\\w+))", "captures": { "1": { @@ -115,16 +115,27 @@ "patterns": [ { "name": "meta.label.renpy", - "begin": "(^[ \\t]+)?\\b(label) +([^_\\d]\\w*)(?= *:)", + "begin": "(^[ \\t]+)?\\b(label)\\s+([a-zA-Z_.]\\w*(?:\\(.*\\))?)(:)", "beginCaptures": { "1": { - "name": "punctuation.whitespace.label.leading.renpy" - }, + "name": "punctuation.whitespace.label.leading.renpy" + }, "2": { - "name": "keyword.control.renpy" + "name": "keyword.renpy storage.type.function.renpy" }, "3":{ - "name": "entity.name.function.renpy" + "name": "meta.label.renpy", + "patterns": [ + { + "comment": "Function name", + "match": "([a-zA-Z_.]\\w*)", + "name": "entity.name.function.renpy" + }, + { "include": "source.python#parameters" } + ] + }, + "4": { + "name": "punctuation.section.label.begin.renpy" } }, @@ -147,7 +158,7 @@ }, { "comment": "Renpy keywords", - "match": "\\b(play|pause|screen|scene|show|image|transform)\\b", + "match": "\\b(label|play|pause|screen|scene|show|image|transform)\\b", "name": "keyword.other.renpy" }, { @@ -157,7 +168,7 @@ }, { "comment": "Control flow keywords", - "match": "\\b(for|while|pass|return|menu|label|jump|call)\\b", + "match": "\\b(for|while|pass|return|menu|jump|call)\\b", "name": "keyword.control.renpy" }, { From 4d7f7affe421b83de38b04da9d0af9544866e970 Mon Sep 17 00:00:00 2001 From: Jelle Date: Fri, 29 Apr 2022 00:26:07 +0200 Subject: [PATCH 6/6] edit: allow spaces before : --- syntaxes/renpy.tmLanguage_2.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntaxes/renpy.tmLanguage_2.json b/syntaxes/renpy.tmLanguage_2.json index 0899da2..573b9df 100644 --- a/syntaxes/renpy.tmLanguage_2.json +++ b/syntaxes/renpy.tmLanguage_2.json @@ -115,7 +115,7 @@ "patterns": [ { "name": "meta.label.renpy", - "begin": "(^[ \\t]+)?\\b(label)\\s+([a-zA-Z_.]\\w*(?:\\(.*\\))?)(:)", + "begin": "(^[ \\t]+)?\\b(label)\\s+([a-zA-Z_.]\\w*(?:\\(.*\\))?)(?=\\s*)(:)", "beginCaptures": { "1": { "name": "punctuation.whitespace.label.leading.renpy"