Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions .unacceptablelanguageignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ assets/swift-docc-render
src/typings/node-pty.d.ts
src/utilities/utilities.ts
src/tasks/SwiftProcess.ts
syntaxes/swift-gyb.tmLanguage.json
test/unit-tests/syntaxes/swift.tmLanguage.json
test/unit-tests/syntaxes/MagicPython.tmLanguage.json
2 changes: 2 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
!assets/swift-docc-render/**
!assets/swift_askpass.sh
!node_modules/@vscode/codicons/**
!swift-gyb.language-configuration.json
!syntaxes/**
293 changes: 289 additions & 4 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 25 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,28 @@
"filenamePatterns": [
"*.tutorial"
]
},
{
"id": "swift-gyb",
"aliases": [
"Swift GYB"
],
"extensions": [
".swift.gyb"
],
"configuration": "./swift-gyb.language-configuration.json"
}
],
"grammars": [
{
"language": "swift-gyb",
"scopeName": "source.swift.gyb",
"path": "./syntaxes/swift-gyb.tmLanguage.json",
"embeddedLanguages": {
"meta.embedded.block.gyb": "python",
"meta.embedded.control.begin.gyb": "python",
"meta.embedded.expression.gyb": "python"
}
}
],
"snippets": [
Expand Down Expand Up @@ -2005,7 +2027,8 @@
"pretest": "npm run compile-tests",
"soundness": "scripts/soundness.sh",
"check-package-json": "tsx ./scripts/check_package_json.ts",
"test": "vscode-test",
"test": "vscode-test && npm run grammar-test",
"grammar-test": "vscode-tmgrammar-test test/unit-tests/**/*.test.swift.gyb -g test/unit-tests/syntaxes/swift.tmLanguage.json -g test/unit-tests/syntaxes/MagicPython.tmLanguage.json",
"integration-test": "npm test -- --label integrationTests",
"unit-test": "npm test -- --label unitTests",
"coverage": "npm test -- --coverage",
Expand Down Expand Up @@ -2083,6 +2106,7 @@
"sinon-chai": "^3.7.0",
"source-map-support": "^0.5.21",
"strip-ansi": "^6.0.1",
"vscode-tmgrammar-test": "^0.1.3",
"svgo": "^4.0.0",
"tsconfig-paths": "^4.2.0",
"tsx": "^4.20.6",
Expand Down
17 changes: 17 additions & 0 deletions swift-gyb.language-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"brackets": [["{", "}"]],
"autoClosingPairs": [
["%{", "}%"],
["${", "}"]
],
"surroundingPairs": [
["%{", "}%"],
["${", "}"]
],
"folding": {
"markers": {
"start": "^\\s*(?:%\\{|%[^\\{].*?:)",
"end": "^\\s*(?:\\}%|%\\s*end\\b)"
}
}
}
89 changes: 89 additions & 0 deletions syntaxes/swift-gyb.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "Swift GYB",
"patterns": [
{ "include": "#gyb-code-block" },
{ "include": "#gyb-start-control-statement" },
{ "include": "#gyb-end-control-statement" },
{ "include": "#gyb-expression" },
{ "include": "source.swift" }
],
"repository": {
"gyb-code-block": {
"name": "meta.embedded.block.gyb",
"begin": "^\\s*(%)\\{",
"beginCaptures": {
"1": { "name": "keyword.control.gyb" },
"0": { "name": "punctuation.section.block.begin.gyb" }
},
"end": "\\}(%)",
"endCaptures": {
"1": { "name": "keyword.control.gyb" },
"0": { "name": "punctuation.section.block.end.gyb" }
},
"patterns": [{ "include": "source.python" }]
},
"gyb-start-control-statement": {
"name": "meta.embedded.control.begin.gyb",
"begin": "^\\s*(%)(?!\\{|\\s*end\\b)",
"beginCaptures": {
"1": { "name": "keyword.control.flow.gyb" }
},
"end": ":",
"endCaptures": {
"0": { "name": "punctuation.separator.colon.gyb" }
},
"patterns": [{ "include": "source.python" }]
},
"gyb-end-control-statement": {
"name": "meta.embedded.control.end.gyb",
"match": "^\\s*%\\s*end\\b",
"captures": {
"0": { "name": "keyword.control.flow.gyb" }
}
},
"gyb-expression": {
"name": "meta.embedded.expression.gyb",
"begin": "(\\$)\\{",
"beginCaptures": {
"1": { "name": "variable.other.gyb" },
"0": { "name": "punctuation.section.expression.begin.gyb" }
},
"end": "\\}",
"endCaptures": {
"0": { "name": "punctuation.section.expression.end.gyb" }
},
"patterns": [{ "include": "source.python" }]
}
},
"injections": {
"source.swift": {
"patterns": [
{ "include": "#gyb-code-block" },
{ "include": "#gyb-start-control-statement" },
{ "include": "#gyb-end-control-statement" },
{ "include": "#gyb-expression" }
]
},
"source.python": {
"patterns": [
{ "include": "#gyb-code-block" },
{ "include": "#gyb-start-control-statement" },
{ "include": "#gyb-end-control-statement" },
{ "include": "#gyb-expression" }
]
},
"source.swift.gyb": {
"patterns": [
{ "include": "#gyb-code-block" },
{ "include": "#gyb-start-control-statement" },
{ "include": "#gyb-end-control-statement" },
{ "include": "#gyb-expression" }
]
}
},
"scopeName": "source.swift.gyb",
"fileTypes": ["swift.gyb"],
"foldingStartMarker": "^\\s*(?:%\\{|%[^\\{].*?:)",
"foldingStopMarker": "^\\s*(?:\\}%|%\\s*end\\b)"
}
111 changes: 111 additions & 0 deletions test/unit-tests/syntaxes/Character.test.swift.gyb
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// SYNTAX TEST "source.swift.gyb" "Character struct"

%{
// <- keyword.control.gyb
// <~- punctuation.section.block.begin.gyb
abilities = ['strength', 'perception', 'endurance', 'charisma', 'intelligence', 'agility', 'luck']
// ^ keyword.operator.assignment.python
// ^ punctuation.definition.list.begin.python
// ^ punctuation.definition.string.begin.python
// ^^^^^^^^ string.quoted.single.python
// ^ punctuation.definition.string.end.python
// ^ punctuation.separator.element.python
}%
// <- punctuation.section.block.end.gyb
// <~- keyword.control.gyb

enum Hello {}

% for ability in abilities:
// <- keyword.control.flow.gyb
// <~~--- keyword.control.flow.python
// ^^ keyword.control.flow.python
// ^ punctuation.separator.colon.gyb
print("${ability}")
// <----- support.function.swift
// ^ punctuation.definition.arguments.begin.swift
// ^ punctuation.definition.string.begin.swift
// ^ variable.other.gyb
// ^ punctuation.section.expression.begin.gyb
// ^ punctuation.section.expression.end.gyb
// ^ punctuation.definition.string.end.swift
// ^ punctuation.definition.arguments.end.swift
% end
// <----- meta.embedded.control.end.gyb keyword.control.flow.gyb

struct Character {
// <------ storage.type.struct.swift
// ^^^^^^^^^ entity.name.type.struct.swift
// ^ punctuation.definition.type.begin.swift
let name: String
// ^^^ keyword.other.declaration-specifier.swift
// ^^^^ meta.definition.type.body.swift
// ^^^^^^ support.type.swift

% for ability in abilities:
// ^ keyword.control.flow.gyb
// ^^^ keyword.control.flow.python
// ^^ keyword.control.flow.python
// ^ punctuation.separator.colon.gyb
let ${ability}: Int
// ^^^ keyword.other.declaration-specifier.swift
// ^ variable.other.gyb
// ^^ punctuation.section.expression.begin.gyb
// ^ punctuation.section.expression.end.gyb
% end
// ^^^^^ meta.embedded.control.end.gyb keyword.control.flow.gyb

%{
// ^ keyword.control.gyb
// ^ punctuation.section.block.begin.gyb
for i in range(10):
// ^^^^^ support.function.builtin.python
print(i)
}%
// ^ punctuation.section.block.end.gyb
// ^ keyword.control.gyb

enum Error {
case notFound

% for ability in abilities:
case ${ability}
% end
}
}
// <- punctuation.definition.type.end.swift

enum World {}

% for ability in abilities:
// <- keyword.control.flow.gyb
// <~~--- keyword.control.flow.python
// ^^ keyword.control.flow.python
// ^ punctuation.separator.colon.gyb
print("${ability}")
// <----- support.function.swift
// ^ punctuation.definition.arguments.begin.swift
// ^ punctuation.definition.string.begin.swift
// ^ variable.other.gyb
// ^ punctuation.section.expression.begin.gyb
// ^ punctuation.section.expression.end.gyb
// ^ punctuation.definition.string.end.swift
// ^ punctuation.definition.arguments.end.swift
% end
// <----- meta.embedded.control.end.gyb keyword.control.flow.gyb

struct SimpleCharacter {
// <------ storage.type.struct.swift
// ^^^^^^^^^^^^^^^ entity.name.type.struct.swift
// ^ punctuation.definition.type.begin.swift
let name: String
// ^^^ keyword.other.declaration-specifier.swift
// ^^^^ meta.definition.type.body.swift
// ^^^^^^ support.type.swift

% for ability in abilities:
let ${ability}: Int
% end
}
// <- punctuation.definition.type.end.swift

Loading