Skip to content

Commit 0ac7e89

Browse files
authored
Merge pull request #444 from renpy/parser-pattern-fixes
Parser pattern fixes
2 parents 386a48b + 81b8e25 commit 0ac7e89

File tree

3 files changed

+64
-45
lines changed

3 files changed

+64
-45
lines changed

src/tokenizer/renpy-token-patterns.g.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// THIS FILE HAS BEEN GENERATED BY THE `syntax-to-token-pattern.py` GENERATOR
66
// DO NOT EDIT THIS FILE DIRECTLY! INSTEAD RUN THE PYTHON SCRIPT.
77
// ANY MANUAL EDITS MADE TO THIS FILE WILL BE OVERWRITTEN. YOU HAVE BEEN WARNED.
8-
// Last generated: 15/08/2024 21:19:25 (UTC+0)
8+
// Last generated: 17/08/2024 11:27:04 (UTC+0)
99

1010
import { MetaTokenType, CharacterTokenType, LiteralTokenType, EntityTokenType, KeywordTokenType, EscapedCharacterTokenType, OperatorTokenType } from "./renpy-tokens";
1111
import { TokenPattern } from "./token-pattern-types";
@@ -1033,7 +1033,7 @@ export const sayStatements: TokenPattern = {
10331033

10341034
token: MetaTokenType.SayStatement, /*meta.say.statement.renpy*/
10351035
contentToken: LiteralTokenType.String, /*renpy.meta.say.$1 string.quoted.renpy*/
1036-
begin: /(?<=^[ \t]+)(?:([a-zA-Z_]\w*)\b|"([a-zA-Z_]\w*)\b")((?:[ \t]+(?:@|\w+))*)?[ \t]*("""|"|'''|'|```|`)/dgm,
1036+
begin: /(?<=^[ \t]+)(?:((?:character\.)?[a-zA-Z_]\w*)\b|"([a-zA-Z_]\w*)\b")((?:[ \t]+(?:@|\w+))*)?(?=[ \t]*r?(?:"|'|`))/dgm,
10371037
beginCaptures: {
10381038
1: {
10391039
token: EntityTokenType.Identifier, /*renpy.meta.character.$1 variable.other.renpy*/
@@ -1073,18 +1073,11 @@ export const sayStatements: TokenPattern = {
10731073
},
10741074
4: { token: MetaTokenType.StringBegin, /*string.quoted.renpy punctuation.definition.string.begin.renpy*/ },
10751075
},
1076-
// @ts-ignore: Back references in end patterns are replaced by begin matches at runtime
1077-
end: /(?<![^\\]\\)(((?<=\4)\4)|\4)([ \t]*\(.*?\)(?![^\(]*?\)))?/dg,
1078-
endCaptures: {
1079-
1: { token: MetaTokenType.StringEnd, /*string.quoted.renpy punctuation.definition.string.end.renpy*/ },
1080-
2: { token: MetaTokenType.EmptyString, /*meta.empty-string.renpy*/ },
1081-
3: {
1082-
token: MetaTokenType.Arguments, /*meta.say.arguments.renpy*/
1083-
patterns: [
1084-
]
1085-
},
1086-
},
1087-
patterns: [stringsInterior]
1076+
end: /$/gm,
1077+
patterns: [
1078+
strings,
1079+
fallbackPatterns,
1080+
]
10881081
},
10891082
{
10901083
debugName: "sayStatements.patterns![1]",
@@ -1237,23 +1230,35 @@ export const image: TokenPattern = {
12371230
debugName: "image.patterns![0]",
12381231

12391232
token: MetaTokenType.ImageStatement, /*meta.image.statement.renpy*/
1240-
begin: /(?<=^[ \t]*)(image)\b[ \t]*/dgm,
1233+
begin: /(?<=^[ \t]*)(image)\b/dgm,
12411234
beginCaptures: {
12421235
1: { token: KeywordTokenType.Image, /*keyword.image.renpy*/ },
12431236
},
1244-
end: /(?=\b(at|with)\b|#|=|:)|$/gm,
1237+
end: /(?=:)|$/gm,
12451238
patterns: [
12461239
strings,
12471240
{
12481241
debugName: "image.patterns![0].patterns![1]",
12491242

12501243
token: EntityTokenType.ImageName, /*entity.name.type.image.renpy*/
1251-
match: /\b(?:[a-zA-Z_0-9]+)\b[ \t]*/g,
1244+
match: /\b(?:[a-zA-Z_0-9]+)\b/g,
12521245
},
1246+
atStatement,
1247+
withStatement,
1248+
{
1249+
debugName: "image.patterns![0].patterns![4]",
1250+
1251+
contentToken: MetaTokenType.PythonExpression, /*meta.python.expression.renpy*/
1252+
begin: /=/dg,
1253+
beginCaptures: {
1254+
0: { token: OperatorTokenType.Assignment, /*keyword.operator.assignment.renpy*/ },
1255+
},
1256+
end: /$/gm,
1257+
patterns: [whitespace]
1258+
},
1259+
fallbackPatterns,
12531260
]
12541261
},
1255-
atStatement,
1256-
withStatement,
12571262
]
12581263
};
12591264

@@ -1681,7 +1686,7 @@ export const label: TokenPattern = {
16811686
beginCaptures: {
16821687
1: { token: KeywordTokenType.Label, /*storage.type.function.label.renpy*/ },
16831688
},
1684-
end: /(?=#|:)|$/gm,
1689+
end: /(?=:)|$/gm,
16851690
patterns: [
16861691
{
16871692
debugName: "label.patterns![0]",
@@ -1690,6 +1695,7 @@ export const label: TokenPattern = {
16901695
match: /\b(?<!\.)(hide)\b/g,
16911696
},
16921697
labelDefName,
1698+
fallbackPatterns,
16931699
]
16941700
};
16951701

@@ -2054,6 +2060,7 @@ simpleExpression.patterns!.splice(7, 0, comments);
20542060
stringsInterior.patterns!.splice(2, 0, stringTags);
20552061
stringTags.patterns![10].captures![4].patterns![0].captures![3].patterns!.splice(0, 0, labelName);
20562062
pythonStatements.patterns!.push(define, defaultStatement, oneLinePython, pythonBlockTester);
2063+
sayStatements.patterns![0].patterns!.splice(2, 0, withStatement);
20572064
sayStatements.patterns![1].patterns!.splice(2, 0, withStatement);
20582065
renpyBlockTester.patterns!.push(basePatterns);
20592066
layeredimageBlockTester.patterns!.push(layeredimageGroup, layeredimageAttribute, basePatterns);

src/tokenizer/token-patterns.g.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
// THIS FILE HAS BEEN GENERATED BY THE `syntax-to-token-pattern.py` GENERATOR
44
// DO NOT EDIT THIS FILE DIRECTLY! INSTEAD RUN THE PYTHON SCRIPT.
55
// ANY MANUAL EDITS MADE TO THIS FILE WILL BE OVERWRITTEN. YOU HAVE BEEN WARNED.
6-
// Last generated: 15/08/2024 20:21:42 (UTC+0)
6+
// Last generated: 17/08/2024 11:27:04 (UTC+0)
77

8-
import * as AtlPatterns from "./atl-token-patterns.g";
98
import * as RenpyPatterns from "./renpy-token-patterns.g";
109
import * as PythonPatterns from "./python-token-patterns.g";
10+
import * as AtlPatterns from "./atl-token-patterns.g";
1111
import * as ScreenPatterns from "./screen-token-patterns.g";
1212
import * as StylePatterns from "./style-token-patterns.g";
1313

@@ -28,14 +28,15 @@ RenpyPatterns.define.patterns![3].patterns!.splice(0, 0, PythonPatterns.expressi
2828
RenpyPatterns.defaultStatement.patterns!.splice(1, 0, PythonPatterns.expression);
2929
RenpyPatterns.defaultStatement.patterns![2].patterns!.splice(0, 0, PythonPatterns.expression);
3030
RenpyPatterns.oneLinePython.patterns!.splice(1, 0, PythonPatterns.expression);
31-
RenpyPatterns.sayStatements.patterns![0].endCaptures![3].patterns!.push(PythonPatterns.oddFunctionCall);
31+
RenpyPatterns.sayStatements.patterns![0].patterns!.splice(1, 0, PythonPatterns.oddFunctionCall);
3232
RenpyPatterns.sayStatements.patterns![1].patterns!.splice(1, 0, PythonPatterns.oddFunctionCall);
3333
RenpyPatterns.conditionals.patterns!.splice(0, 0, PythonPatterns.expression);
34+
RenpyPatterns.image.patterns![0].patterns![4].patterns!.splice(0, 0, PythonPatterns.expression);
3435
RenpyPatterns.labelName.patterns!.splice(0, 0, PythonPatterns.builtinPossibleCallables);
3536
RenpyPatterns.labelCall.patterns!.splice(0, 0, PythonPatterns.specialVariables);
3637
RenpyPatterns.labelCall.patterns!.push(PythonPatterns.functionArguments);
3738
RenpyPatterns.labelDefName.patterns!.splice(0, 0, PythonPatterns.builtinPossibleCallables);
38-
RenpyPatterns.label.patterns!.push(PythonPatterns.parameters);
39+
RenpyPatterns.label.patterns!.splice(2, 0, PythonPatterns.parameters);
3940
RenpyPatterns.returnStatements.patterns!.push(PythonPatterns.expression);
4041
RenpyPatterns.callJumpExpression.patterns!.push(PythonPatterns.expression);
4142
RenpyPatterns.callPass.patterns!.splice(0, 0, PythonPatterns.functionArguments);
@@ -145,4 +146,4 @@ PythonPatterns.doubleOneRegexpComments.patterns!.push(RenpyPatterns.codetags);
145146
PythonPatterns.doubleThreeRegexpComments.patterns!.push(RenpyPatterns.codetags);
146147

147148

148-
export { AtlPatterns, RenpyPatterns, PythonPatterns, ScreenPatterns, StylePatterns };
149+
export { RenpyPatterns, PythonPatterns, AtlPatterns, ScreenPatterns, StylePatterns };

syntaxes/renpy.tmLanguage.json

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@
851851
{
852852
"name": "meta.say.statement.renpy",
853853
"contentName": "renpy.meta.say.$1 string.quoted.renpy",
854-
"begin": "(?<=^[ \\t]+)(?:([a-zA-Z_]\\w*)\\b|\"([a-zA-Z_]\\w*)\\b\")((?:[ \\t]+(?:@|\\w+))*)?[ \\t]*(\"\"\"|\"|'''|'|```|`)",
854+
"begin": "(?<=^[ \\t]+)(?:((?:character\\.)?[a-zA-Z_]\\w*)\\b|\"([a-zA-Z_]\\w*)\\b\")((?:[ \\t]+(?:@|\\w+))*)?(?=[ \\t]*r?(?:\"|'|`))",
855855
"beginCaptures": {
856856
"1": {
857857
"name": "renpy.meta.character.$1 variable.other.renpy",
@@ -883,16 +883,13 @@
883883
},
884884
"4": { "name": "string.quoted.renpy punctuation.definition.string.begin.renpy" }
885885
},
886-
"end": "(?<![^\\\\]\\\\)(((?<=\\4)\\4)|\\4)([ \\t]*\\(.*?\\)(?![^\\(]*?\\)))?",
887-
"endCaptures": {
888-
"1": { "name": "string.quoted.renpy punctuation.definition.string.end.renpy" },
889-
"2": { "name": "meta.empty-string.renpy" },
890-
"3": {
891-
"name": "meta.say.arguments.renpy",
892-
"patterns": [ { "include": "source.renpy.python#odd-function-call" } ]
893-
}
894-
},
895-
"patterns": [ { "include": "#strings-interior" } ]
886+
"end": "$",
887+
"patterns": [
888+
{ "include": "#strings" },
889+
{ "include": "source.renpy.python#odd-function-call" },
890+
{ "include": "#with-statement" },
891+
{ "include": "#fallback-patterns" }
892+
]
896893
},
897894
{
898895
"name": "meta.say.narrator.renpy meta.say.statement.renpy",
@@ -1012,21 +1009,34 @@
10121009
"patterns": [
10131010
{
10141011
"name": "meta.image.statement.renpy",
1015-
"begin": "(?<=^[ \\t]*)(image)\\b[ \\t]*",
1012+
"begin": "(?<=^[ \\t]*)(image)\\b",
10161013
"beginCaptures": {
10171014
"1": { "name": "keyword.image.renpy" }
10181015
},
1019-
"end": "(?=\\b(at|with)\\b|#|=|:)|$",
1016+
"end": "(?=:)|$",
10201017
"patterns": [
10211018
{ "include": "#strings" },
10221019
{
1023-
"match": "\\b(?:[a-zA-Z_0-9]+)\\b[ \\t]*",
1020+
"match": "\\b(?:[a-zA-Z_0-9]+)\\b",
10241021
"name": "entity.name.type.image.renpy"
1025-
}
1022+
},
1023+
{ "include": "#at-statement" },
1024+
{ "include": "#with-statement" },
1025+
{
1026+
"contentName": "meta.python.expression.renpy",
1027+
"begin": "=",
1028+
"beginCaptures": {
1029+
"0": { "name": "keyword.operator.assignment.renpy" }
1030+
},
1031+
"end": "$",
1032+
"patterns": [
1033+
{ "include": "source.renpy.python#expression" },
1034+
{ "include": "#whitespace" }
1035+
]
1036+
},
1037+
{ "include": "#fallback-patterns" }
10261038
]
1027-
},
1028-
{ "include": "#at-statement" },
1029-
{ "include": "#with-statement" }
1039+
}
10301040
]
10311041
},
10321042

@@ -1374,7 +1384,7 @@
13741384
"label": {
13751385
"name": "meta.label.statement.renpy",
13761386
"begin": "(?<=^[ \\t]*)(label)\\b",
1377-
"end": "(?=#|:)|$",
1387+
"end": "(?=:)|$",
13781388
"beginCaptures": {
13791389
"1": { "name": "storage.type.function.label.renpy" }
13801390
},
@@ -1384,7 +1394,8 @@
13841394
"match": "\\b(?<!\\.)(hide)\\b"
13851395
},
13861396
{ "include": "#label-def-name" },
1387-
{ "include": "source.renpy.python#parameters" }
1397+
{ "include": "source.renpy.python#parameters" },
1398+
{ "include": "#fallback-patterns" }
13881399
]
13891400
},
13901401
"return-statements": {

0 commit comments

Comments
 (0)