Skip to content

Commit

Permalink
Support syntax highlighting in _ren.py files
Browse files Browse the repository at this point in the history
Add injection grammar for renpy comments in _ren.py files

For now this will only work in doc strings, python syntax highlighting isn't changed
  • Loading branch information
duckdoom4 committed Jun 14, 2023
1 parent 4a169fe commit 163ea4c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
17 changes: 17 additions & 0 deletions examples/test_ren.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This is not included in the game. It's here so that an editor knows
# the type of strength.
strength = 100

"""renpy
init python:
"""

class BoostStrength(Action):
"""
Boosts the strength of the player by 10.
"""

def __call__(self):
global strength
strength += 10
renpy.restart_interaction()
16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
},
"activationEvents": [
"onLanguage:renpy",
"workspaceContains:**/*.rpy"
"workspaceContains:**/*.rpy",
"workspaceContains:**/_ren.py"
],
"main": "./dist/extension",
"browser": "./dist/extension.js",
Expand All @@ -46,7 +47,8 @@
"id": "renpy",
"aliases": [
"Ren'Py",
"renpy"
"renpy",
"rpy"
],
"extensions": [
".rpy",
Expand Down Expand Up @@ -88,6 +90,16 @@
"scopeName": "source.renpy.python",
"path": "./syntaxes/renpy.python.tmLanguage.json"
},
{
"scopeName": "renpy.comment.injection",
"path": "./syntaxes/injection.json",
"injectTo": [
"source.python"
],
"embeddedLanguages": {
"meta.embedded.renpy": "renpy"
}
},
{
"language": "renpy-log",
"scopeName": "text.renpy-log",
Expand Down
26 changes: 26 additions & 0 deletions syntaxes/injection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"scopeName": "renpy.comment.injection",
"injectionSelector": "L:string.quoted.docstring",
"patterns": [
{
"include": "#renpy-source"
}
],
"repository": {
"renpy-source": {
"contentName": "meta.embedded.renpy",
"begin": "(?<=^\\\"\\\"\\\")renpy",
"beginCaptures": {
"0": {
"name": "keyword.renpy"
}
},
"end": "(?=^\\\"\\\"\\\")",
"patterns": [
{
"include": "source.renpy"
}
]
}
}
}

0 comments on commit 163ea4c

Please sign in to comment.