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 5b41732..573b9df 100644 --- a/syntaxes/renpy.tmLanguage_2.json +++ b/syntaxes/renpy.tmLanguage_2.json @@ -3,53 +3,182 @@ "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": "#renpy-statements" }, + { "include": "#python-statements" }, + { "include": "#keywords" } + ] + }, + "expressions": { + "patterns": [ + { "include": "#strings" } + ] + }, + "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) ([a-zA-Z_]\\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": "(?