Skip to content

Commit

Permalink
Merge pull request #442 from renpy/fix-window-statement
Browse files Browse the repository at this point in the history
Fix window statement
  • Loading branch information
duckdoom4 authored Aug 15, 2024
2 parents a02ec96 + 2aa76f4 commit 461d6e9
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/unit_test.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@
window hide # hides the window.
pause # the window is hidden during this pause.

window show dissolve # shows the window with dissolve.
window show show.dissolve.show # shows the window with dissolve.
pause # the window is shown during this pause.
window hide dissolve # hides the window with dissolve.
pause # the window is hidden during this pause.
Expand Down
2 changes: 2 additions & 0 deletions src/tokenizer/debug-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ ${(decoration.hoverMessage as MarkdownString).value}`,
case KeywordTokenType.Scene:
case KeywordTokenType.Camera:
case KeywordTokenType.Show:
case KeywordTokenType.Auto:
case KeywordTokenType.Image:
case KeywordTokenType.Layeredimage:
case KeywordTokenType.Window:
Expand Down Expand Up @@ -476,6 +477,7 @@ ${(decoration.hoverMessage as MarkdownString).value}`,
case MetaTokenType.SceneStatement:
case MetaTokenType.ShowStatement:
case MetaTokenType.HideStatement:
case MetaTokenType.WindowStatement:
case MetaTokenType.CallStatement:
case MetaTokenType.CallArguments:
case MetaTokenType.FromClause:
Expand Down
16 changes: 11 additions & 5 deletions src/tokenizer/renpy-token-patterns.g.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// THIS FILE HAS BEEN GENERATED BY THE `syntax-to-token-pattern.py` GENERATOR
// DO NOT EDIT THIS FILE DIRECTLY! INSTEAD RUN THE PYTHON SCRIPT.
// ANY MANUAL EDITS MADE TO THIS FILE WILL BE OVERWRITTEN. YOU HAVE BEEN WARNED.
// Last generated: 15/08/2024 20:21:42 (UTC+0)
// Last generated: 15/08/2024 21:19:25 (UTC+0)

import { MetaTokenType, CharacterTokenType, LiteralTokenType, EntityTokenType, KeywordTokenType, EscapedCharacterTokenType, OperatorTokenType } from "./renpy-tokens";
import { TokenPattern } from "./token-pattern-types";
Expand Down Expand Up @@ -1471,7 +1471,7 @@ export const window: TokenPattern = {
{
debugName: "window.patterns![0]",

token: MetaTokenType.ShowStatement, /*meta.show.statement.renpy*/
token: MetaTokenType.WindowStatement, /*meta.window.statement.renpy*/
begin: /(?<=^[ \t]*)(window)/dgm,
beginCaptures: {
1: { token: KeywordTokenType.Window, /*keyword.window.renpy*/ },
Expand All @@ -1481,14 +1481,20 @@ export const window: TokenPattern = {
{
debugName: "window.patterns![0].patterns![0]",

token: KeywordTokenType.Show, /*keyword.control.flow.show.renpy*/
match: /\b(show)\b/g,
token: KeywordTokenType.Auto, /*keyword.auto.renpy*/
match: /(?<=window[ \t]+)\b(auto)\b/g,
},
{
debugName: "window.patterns![0].patterns![1]",

token: KeywordTokenType.Show, /*keyword.control.flow.show.renpy*/
match: /(?<=(?:window|auto)[ \t]+)\b(show)\b/g,
},
{
debugName: "window.patterns![0].patterns![2]",

token: KeywordTokenType.Hide, /*keyword.control.flow.hide.renpy*/
match: /\b(hide)\b/g,
match: /(?<=window[ \t]+)\b(hide)\b/g,
},
whitespace,
simpleExpression,
Expand Down
2 changes: 2 additions & 0 deletions src/tokenizer/renpy-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const enum KeywordTokenType {
Scene,
Camera,
Show,
Auto,
Image,
Layeredimage,
Window,
Expand Down Expand Up @@ -344,6 +345,7 @@ export const enum MetaTokenType {
SceneStatement,
ShowStatement,
HideStatement,
WindowStatement,

CallStatement,
CallArguments,
Expand Down
2 changes: 2 additions & 0 deletions src/tokenizer/token-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ const tokenTypeDefinitions: EnumToString<TypeOfTokenType> = {
Scene: { name: "Scene", value: KeywordTokenType.Scene },
Camera: { name: "Camera", value: KeywordTokenType.Camera },
Show: { name: "Show", value: KeywordTokenType.Show },
Auto: { name: "Auto", value: KeywordTokenType.Auto },
Image: { name: "Image", value: KeywordTokenType.Image },
Layeredimage: { name: "Layeredimage", value: KeywordTokenType.Layeredimage },
Window: { name: "Window", value: KeywordTokenType.Window },
Expand Down Expand Up @@ -704,6 +705,7 @@ const tokenTypeDefinitions: EnumToString<TypeOfTokenType> = {
SceneStatement: { name: "SceneStatement", value: MetaTokenType.SceneStatement },
ShowStatement: { name: "ShowStatement", value: MetaTokenType.ShowStatement },
HideStatement: { name: "HideStatement", value: MetaTokenType.HideStatement },
WindowStatement: { name: "WindowStatement", value: MetaTokenType.WindowStatement },

CallStatement: { name: "CallStatement", value: MetaTokenType.CallStatement },
CallArguments: { name: "CallArguments", value: MetaTokenType.CallArguments },
Expand Down
11 changes: 8 additions & 3 deletions src/tokenizer/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class Tokenizer {
stack.push(RenpyPatterns.basePatterns as ExTokenRepoPattern);

const mFlagRe = /(?<!\[)[\^$]/g;
const gAnchorRe = /\(\\G\)|\(\?!\\G\)/g;
const gAnchorRe = /(?:\(\?!\\G\))|(?:\\G)/g;
while (!stack.isEmpty()) {
const p = stack.pop()!;
assert(p !== undefined, "This pattern is undefined! Please make sure that circular includes are added after both patterns are defined.");
Expand All @@ -162,7 +162,7 @@ export class Tokenizer {
}

if (gAnchorRe.test(reBeginSource)) {
assert("Can't use the \\G anchor, please update the regex!");
assert(false, "Can't use the \\G anchor, please update the regex!");
reBeginSource = reBeginSource.replace(gAnchorRe, "");
}

Expand Down Expand Up @@ -206,7 +206,7 @@ export class Tokenizer {
if (reEndSource.startsWith("(?!\\G)")) {
p._endNotG = true;
} else {
assert("The end patterns only supports (?!\\G) at the start of the regex. Please update the regex!");
assert(false, "The end patterns only supports (?!\\G) at the start of the regex. Please update the regex!");
reEndSource = reEndSource.replace(gAnchorRe, "");
}
}
Expand All @@ -225,6 +225,11 @@ export class Tokenizer {
assert(p.match.multiline, "To match this pattern the 'm' flag is required!");
}

if (gAnchorRe.test(p.match.source)) {
assert(false, "The \\G anchors are not yet supported on match patterns!");
p.match = new RegExp(p.match.source.replace(gAnchorRe, ""), p.match.flags);
}

assert(p.match.global, "To match this pattern the 'g' flag is required!");
if (p.captures) {
assert(p.match.hasIndices, "To match this pattern the 'd' flag is required!");
Expand Down
10 changes: 7 additions & 3 deletions syntaxes/renpy.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -1210,20 +1210,24 @@
"window": {
"patterns": [
{
"name": "meta.show.statement.renpy",
"name": "meta.window.statement.renpy",
"begin": "(?<=^[ \\t]*)(window)",
"beginCaptures": {
"1": { "name": "keyword.window.renpy" }
},
"end": "$",
"patterns": [
{
"name": "keyword.auto.renpy",
"match": "(?<=window[ \\t]+)\\b(auto)\\b"
},
{
"name": "keyword.control.flow.show.renpy",
"match": "\\b(show)\\b"
"match": "(?<=(?:window|auto)[ \\t]+)\\b(show)\\b"
},
{
"name": "keyword.control.flow.hide.renpy",
"match": "\\b(hide)\\b"
"match": "(?<=window[ \\t]+)\\b(hide)\\b"
},
{ "include": "#whitespace" },
{ "include": "#simple-expression" }
Expand Down

0 comments on commit 461d6e9

Please sign in to comment.