Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion scripts/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def convert_file(filename: pathlib.Path):
pass

destination.write_text(output)
return True


def main():
Expand All @@ -76,7 +77,8 @@ def main():
generated = False

for filename in ROOT.glob("syntaxes/*.tmLanguage.yaml"):
generated = generated or convert_file(filename)
file_changed = convert_file(filename)
generated = generated or file_changed

print("Generated .tmLanguage.json files from .tmLanguage.yaml files.")

Expand Down
27 changes: 25 additions & 2 deletions scripts/syntax_to_token_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ def get_parts(range: slice) -> str:
else:
return "EntityTokenType.FunctionName"

elif get_part(1) == "constant" and get_part(2) == "property-name":
return "EntityTokenType.PropertyName"

elif get_part(1) == "other":
if get_part(2) == "match":
if get_part(3) == "any":
Expand Down Expand Up @@ -304,6 +307,9 @@ def get_parts(range: slice) -> str:
else:
return "KeywordTokenType." + titleCase(get_part(3))

elif get_part(2) == "test":
return "KeywordTokenType.Test"

elif get_part(2) == "import":
return "KeywordTokenType.Import"

Expand Down Expand Up @@ -489,7 +495,9 @@ def transform_pattern(state: GeneratorState, indent: int, value: dict[str, Any],
language = source.split(".")[-1]
language_accessor = titleCase(language) + "Patterns."

if reference == None:
if language == "python" and reference == "python-block-tester":
include = "RenpyPatterns.pythonBlockTester"
elif reference == None:
include = language_accessor + language
else:
include = language_accessor + camelCase(reference)
Expand Down Expand Up @@ -602,12 +610,17 @@ def generate_token_patterns():
atl_state = GeneratorState()
screen_state = GeneratorState()
style_state = GeneratorState()
test_state = GeneratorState()
python_state = GeneratorState()

generated_dir = ROOT / "src" / "tokenizer" / "generated"
generated_dir.mkdir(parents=True, exist_ok=True)

generate_file(renpy_state, "./syntaxes/renpy.tmLanguage.json", "src/tokenizer/generated/renpy-token-patterns.g.ts")
generate_file(atl_state, "./syntaxes/renpy.atl.tmLanguage.json", "src/tokenizer/generated/atl-token-patterns.g.ts")
generate_file(screen_state, "./syntaxes/renpy.screen.tmLanguage.json", "src/tokenizer/generated/screen-token-patterns.g.ts")
generate_file(style_state, "./syntaxes/renpy.style.tmLanguage.json", "src/tokenizer/generated/style-token-patterns.g.ts")
generate_file(test_state, "./syntaxes/renpy.test.tmLanguage.json", "src/tokenizer/generated/test-token-patterns.g.ts")
generate_file(python_state, "./syntaxes/renpy.python.tmLanguage.json", "src/tokenizer/generated/python-token-patterns.g.ts")

# Write the typescript entries to a file
Expand All @@ -620,7 +633,16 @@ def generate_token_patterns():
contents += "\n"

# Add all source import from all states, but only the unique ones
source_imports = list(dict.fromkeys(renpy_state.source_imports + atl_state.source_imports + screen_state.source_imports + style_state.source_imports + python_state.source_imports))
source_imports = list(
dict.fromkeys(
renpy_state.source_imports
+ atl_state.source_imports
+ screen_state.source_imports
+ style_state.source_imports
+ test_state.source_imports
+ python_state.source_imports
)
)

for source_import in source_imports:
contents += f"import * as {titleCase(source_import)}Patterns from \"./{source_import}-token-patterns.g\";\n"
Expand All @@ -638,6 +660,7 @@ def add_entries(entries: list[str], prefix: str) -> str:
contents += add_entries(atl_state.external_pattern_include_entries, "AtlPatterns")
contents += add_entries(screen_state.external_pattern_include_entries, "ScreenPatterns")
contents += add_entries(style_state.external_pattern_include_entries, "StylePatterns")
contents += add_entries(test_state.external_pattern_include_entries, "TestPatterns")
contents += add_entries(python_state.external_pattern_include_entries, "PythonPatterns")

exports: list[str] = []
Expand Down
2 changes: 1 addition & 1 deletion src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function refreshDiagnostics(doc: TextDocument, diagnosticCollection: DiagnosticC

//Filenames must begin with a letter or number,
//and may not begin with "00", as Ren'Py uses such files for its own purposes.
const ignoreThisFilename: string = !!doc.lineAt(0).text.match(rxIgnoreThisFilename);
const ignoreThisFilename: boolean = !!doc.lineAt(0).text.match(rxIgnoreThisFilename);
const checkFilenames: string = config.warnOnInvalidFilenameIssues;
if (checkFilenames.toLowerCase() !== "disabled" && !ignoreThisFilename) {
let severity = DiagnosticSeverity.Error;
Expand Down
17 changes: 17 additions & 0 deletions src/tokenizer/renpy-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,17 @@ export const enum KeywordTokenType {
Circles,
Clockwise,
Counterclockwise,
Knot,
Event,
On,
Function,

// Test keywords
Test,
OtherTest,
Testcase,
Testsuite,

// Python keywords
None,
True,
Expand Down Expand Up @@ -169,6 +176,10 @@ export const enum EntityTokenType {
// ATL entities
EventName,
PropertyName,

// Test entities
TestcaseName,
TestsuiteName,
}

export const enum LiteralTokenType {
Expand Down Expand Up @@ -428,6 +439,12 @@ export const enum MetaTokenType {
TransformStatement,
TransformParameters,

TestBlock,
TestcaseStatement,
TestcaseParameters,
TestsuiteStatement,
TestsuiteParameters,

MemberAccess,
ItemAccess,
IndexedName,
Expand Down
12 changes: 12 additions & 0 deletions src/tokenizer/token-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,11 +540,16 @@ const tokenTypeDefinitions: EnumToString<TypeOfTokenType> = {
Parallel: { name: "Parallel", value: KeywordTokenType.Parallel },
Block: { name: "Block", value: KeywordTokenType.Block },
Choice: { name: "Choice", value: KeywordTokenType.Choice },
Test: { name: "Test", value: KeywordTokenType.Test },
OtherTest: { name: "OtherTest", value: KeywordTokenType.OtherTest },
Testcase: { name: "Testcase", value: KeywordTokenType.Testcase },
Testsuite: { name: "Testsuite", value: KeywordTokenType.Testsuite },

Warp: { name: "Warp", value: KeywordTokenType.Warp },
Circles: { name: "Circles", value: KeywordTokenType.Circles },
Clockwise: { name: "Clockwise", value: KeywordTokenType.Clockwise },
Counterclockwise: { name: "Counterclockwise", value: KeywordTokenType.Counterclockwise },
Knot: { name: "Knot", value: KeywordTokenType.Knot },
Event: { name: "Event", value: KeywordTokenType.Event },
On: { name: "On", value: KeywordTokenType.On },
Function: { name: "Function", value: KeywordTokenType.Function },
Expand Down Expand Up @@ -577,6 +582,8 @@ const tokenTypeDefinitions: EnumToString<TypeOfTokenType> = {
FunctionName: { name: "FunctionName", value: EntityTokenType.FunctionName },
TagName: { name: "TagName", value: EntityTokenType.TagName },
Identifier: { name: "Identifier", value: EntityTokenType.Identifier },
TestcaseName: { name: "TestcaseName", value: EntityTokenType.TestcaseName },
TestsuiteName: { name: "TestsuiteName", value: EntityTokenType.TestsuiteName },

StyleName: { name: "StyleName", value: EntityTokenType.StyleName },
TransformName: { name: "TransformName", value: EntityTokenType.TransformName },
Expand Down Expand Up @@ -844,6 +851,11 @@ const tokenTypeDefinitions: EnumToString<TypeOfTokenType> = {
FunctionDecorator: { name: "FunctionDecorator", value: MetaTokenType.FunctionDecorator },
FunctionCall: { name: "FunctionCall", value: MetaTokenType.FunctionCall },
FunctionCallGeneric: { name: "FunctionCallGeneric", value: MetaTokenType.FunctionCallGeneric },
TestBlock: { name: "TestBlock", value: MetaTokenType.TestBlock },
TestcaseStatement: { name: "TestcaseStatement", value: MetaTokenType.TestcaseStatement },
TestcaseParameters: { name: "TestcaseParameters", value: MetaTokenType.TestcaseParameters },
TestsuiteStatement: { name: "TestsuiteStatement", value: MetaTokenType.TestsuiteStatement },
TestsuiteParameters: { name: "TestsuiteParameters", value: MetaTokenType.TestsuiteParameters },

Fstring: { name: "Fstring", value: MetaTokenType.Fstring },
InterpolateFlags: { name: "InterpolateFlags", value: MetaTokenType.InterpolateFlags },
Expand Down
Loading