Skip to content

Commit 6c0b2bf

Browse files
committed
* sync package.json with the actual grammar triggers
1 parent 5b7bac5 commit 6c0b2bf

File tree

4 files changed

+141
-124
lines changed

4 files changed

+141
-124
lines changed

build.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,11 @@ const fs = require("fs");
33
const gen_grammar = require("./out/gen_grammar");
44

55
const result = gen_grammar.gen(gen_grammar.DEF_SPECS);
6-
const json = JSON.stringify(result, null, 4);
7-
fs.writeFileSync("./syntaxes/embed-in-python.json", json)
6+
fs.writeFileSync("./syntaxes/embed-in-python.json", JSON.stringify(result, null, 4));
7+
8+
// patch package.json defaults for the lang triggers
9+
defs = Object.fromEntries(gen_grammar.DEF_SPECS.map((spec) => [spec.lang, spec.trigger]));
10+
package_json = JSON.parse(fs.readFileSync("package.json"));
11+
package_json.contributes.configuration.properties["python-fstring-dsl.grammar.triggers"].default =
12+
defs;
13+
fs.writeFileSync("package.json", JSON.stringify(package_json, null, 4));

package.json

Lines changed: 109 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,117 @@
11
{
2-
"name": "vscode-python-fstring-dsl",
3-
"publisher": "jkmnt",
4-
"version": "0.1.0",
5-
"engines": {
6-
"vscode": "^1.22.0"
7-
},
8-
"license": "MIT",
9-
"displayName": "Highlight f-strings",
10-
"icon": "icon.png",
11-
"description": "Python - highlight HTML, SQL, JS, CSS in f-strings",
12-
"categories": [
13-
"Programming Languages",
14-
"Themes"
15-
],
16-
"keywords": [
17-
"f-strings",
18-
"fstrings",
19-
"python",
20-
"template",
21-
"literal",
22-
"strings",
23-
"syntax",
24-
"highlighting",
25-
"html",
26-
"sql"
27-
],
28-
"activationEvents": [
29-
"onStartupFinished"
30-
],
31-
"main": "./out/main.js",
32-
"contributes": {
33-
"commands": [
34-
{
35-
"command": "python-fstring-dsl.generate_grammar",
36-
"category": "Highlight f-strings",
37-
"title": "Generate grammar from `grammar.triggers`"
38-
}
2+
"name": "vscode-python-fstring-dsl",
3+
"publisher": "jkmnt",
4+
"version": "0.1.0",
5+
"engines": {
6+
"vscode": "^1.22.0"
7+
},
8+
"license": "MIT",
9+
"displayName": "Highlight f-strings",
10+
"icon": "icon.png",
11+
"description": "Python - highlight HTML, SQL, JS, CSS in f-strings",
12+
"categories": [
13+
"Programming Languages",
14+
"Themes"
3915
],
40-
"languages": [
41-
{
42-
"id": "inlinesql",
43-
"configuration": "./inline-sql.configuration.json"
44-
}
16+
"keywords": [
17+
"f-strings",
18+
"fstrings",
19+
"python",
20+
"template",
21+
"literal",
22+
"hitml",
23+
"syntax",
24+
"highlighting",
25+
"html",
26+
"sql"
4527
],
46-
"grammars": [
47-
{
48-
"language": "inlinesql",
49-
"scopeName": "source.sql.inline",
50-
"path": "./syntaxes/sql.tmLanguage.json"
51-
},
52-
{
53-
"injectTo": [
54-
"source.python"
28+
"activationEvents": [
29+
"onStartupFinished"
30+
],
31+
"main": "./out/main.js",
32+
"contributes": {
33+
"commands": [
34+
{
35+
"command": "python-fstring-dsl.generate_grammar",
36+
"category": "Highlight f-strings",
37+
"title": "Generate grammar from `grammar.triggers`"
38+
}
5539
],
56-
"scopeName": "embed-in-python",
57-
"path": "./syntaxes/embed-in-python.json",
58-
"embeddedLanguages": {
59-
"meta.embedded.inline.sql": "sql",
60-
"meta.embedded.inline.html": "html",
61-
"meta.embedded.inline.css": "css",
62-
"meta.embedded.inline.js": "javascript"
63-
}
64-
},
65-
{
66-
"injectTo": [
67-
"source.python"
40+
"languages": [
41+
{
42+
"id": "inlinesql",
43+
"configuration": "./inline-sql.configuration.json"
44+
}
6845
],
69-
"scopeName": "embed-in-embedded-html",
70-
"path": "./syntaxes/embed-in-embedded-html.json",
71-
"embeddedLanguages": {
72-
"meta.embedded.inline.f-expression.python": "python"
73-
}
74-
},
75-
{
76-
"injectTo": [
77-
"source.python"
46+
"grammars": [
47+
{
48+
"language": "inlinesql",
49+
"scopeName": "source.sql.inline",
50+
"path": "./syntaxes/sql.tmLanguage.json"
51+
},
52+
{
53+
"injectTo": [
54+
"source.python"
55+
],
56+
"scopeName": "embed-in-python",
57+
"path": "./syntaxes/embed-in-python.json",
58+
"embeddedLanguages": {
59+
"meta.embedded.inline.sql": "sql",
60+
"meta.embedded.inline.html": "html",
61+
"meta.embedded.inline.css": "css",
62+
"meta.embedded.inline.js": "javascript"
63+
}
64+
},
65+
{
66+
"injectTo": [
67+
"source.python"
68+
],
69+
"scopeName": "embed-in-embedded-html",
70+
"path": "./syntaxes/embed-in-embedded-html.json",
71+
"embeddedLanguages": {
72+
"meta.embedded.inline.f-expression.python": "python"
73+
}
74+
},
75+
{
76+
"injectTo": [
77+
"source.python"
78+
],
79+
"scopeName": "embed-in-embedded-sql",
80+
"path": "./syntaxes/embed-in-embedded-sql.json",
81+
"embeddedLanguages": {
82+
"meta.embedded.inline.f-expression.python": "python"
83+
}
84+
}
7885
],
79-
"scopeName": "embed-in-embedded-sql",
80-
"path": "./syntaxes/embed-in-embedded-sql.json",
81-
"embeddedLanguages": {
82-
"meta.embedded.inline.f-expression.python": "python"
83-
}
84-
}
85-
],
86-
"configuration": {
87-
"title": "Highlight f-strings",
88-
"properties": {
89-
"python-fstring-dsl.grammar.triggers": {
90-
"type": "object",
91-
"default": {
92-
"html": "html",
93-
"sql": "sql",
94-
"js": "js",
95-
"css": "css"
96-
},
97-
"markdownDescription": "Function names (regex) to trigger the syntax highlight.\nOnly `html`, `sql`, `css`, `js` are supported.\n\nE.g.: `{\"html\":\"html|template[.]render\", \"css\":\"minify_css\", \"sql\":false}`\n\nRun **Highlight f-string: Generate grammar** command to apply changes."
86+
"configuration": {
87+
"title": "Highlight f-strings",
88+
"properties": {
89+
"python-fstring-dsl.grammar.triggers": {
90+
"type": "object",
91+
"default": {
92+
"sql": "sql",
93+
"html": "html|hitml\\.m|hitml\\.markup|hitml\\.document|ht\\.m|ht\\.markup|ht\\.document",
94+
"css": "css|hitml\\.css|ht\\.css",
95+
"js": "js|hitml\\.js|ht\\.js"
96+
},
97+
"markdownDescription": "Function names (regex) to trigger the syntax highlight.\nOnly `html`, `sql`, `css`, `js` are supported.\n\nE.g.: `{\"html\":\"html|template[.]render\", \"css\":\"minify_css\", \"sql\":false}`\n\nRun **Highlight f-string: Generate grammar** command to apply changes."
98+
}
99+
}
98100
}
99-
}
101+
},
102+
"repository": {
103+
"type": "git",
104+
"url": "https://github.com/jkmnt/vscode-python-fstring-dsl"
105+
},
106+
"scripts": {
107+
"compile": "tsc -p .",
108+
"grammar": "node build.js",
109+
"build": "npm run compile && npm run grammar",
110+
"package": "vsce package"
111+
},
112+
"devDependencies": {
113+
"@types/node": "^18.14.0",
114+
"typescript": "^4.2.4",
115+
"vscode": "^1.0.0"
100116
}
101-
},
102-
"repository": {
103-
"type": "git",
104-
"url": "https://github.com/jkmnt/vscode-python-fstring-dsl"
105-
},
106-
"scripts": {
107-
"compile": "tsc -p .",
108-
"grammar": "node build.js",
109-
"build": "npm run compile && npm run grammar",
110-
"package": "vsce package"
111-
},
112-
"devDependencies": {
113-
"@types/node": "^18.14.0",
114-
"typescript": "^4.2.4",
115-
"vscode": "^1.0.0"
116-
}
117-
}
117+
}

src/gen_grammar.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,26 @@ export interface Spec {
55
}
66

77
export const DEF_SPECS: Spec[] = [
8-
{ lang: "sql", trigger: "sql", source: "source.sql.inline" },
9-
{ lang: "html", trigger: "html", source: "text.html.basic" },
10-
{ lang: "css", trigger: "css", source: "source.css" },
11-
{ lang: "js", trigger: "js", source: "source.js" },
8+
{
9+
lang: "sql",
10+
trigger: "sql",
11+
source: "source.sql.inline",
12+
},
13+
{
14+
lang: "html",
15+
trigger: "html|hitml\\.m|hitml\\.markup|hitml\\.document|ht\\.m|ht\\.markup|ht\\.document",
16+
source: "text.html.basic",
17+
},
18+
{
19+
lang: "css",
20+
trigger: "css|hitml\\.css|ht\\.css",
21+
source: "source.css",
22+
},
23+
{
24+
lang: "js",
25+
trigger: "js|hitml\\.js|ht\\.js",
26+
source: "source.js",
27+
},
1228
];
1329

1430
const REPOSITORY = {
@@ -80,11 +96,7 @@ function make_lang(spec: Spec) {
8096
{
8197
begin: `([r|R]?f|F)('''|"""|'|")(\\\\$)?`,
8298
end: `(\\2)`,
83-
name: scopes(
84-
"string.quoted.python",
85-
"string.interpolated.python",
86-
"meta.fstring.python"
87-
),
99+
name: scopes("string.quoted.python", "string.interpolated.python", "meta.fstring.python"),
88100
contentName: scopes(`meta.embedded.inline.${spec.lang}`),
89101
beginCaptures: {
90102
1: {
@@ -136,7 +148,6 @@ function make_lang(spec: Spec) {
136148
}
137149

138150
export function gen(specs: Spec[]) {
139-
140151
const grammar = {
141152
comment: "This file is autogenerated.",
142153
scopeName: "embed-in-python",

syntaxes/embed-in-python.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
]
8484
},
8585
{
86-
"begin": "(?x)\n (?<!def\\s+)\n \\b\n (html)\n \\s*\n (\\()",
86+
"begin": "(?x)\n (?<!def\\s+)\n \\b\n (html|hitml\\.m|hitml\\.markup|hitml\\.document|ht\\.m|ht\\.markup|ht\\.document)\n \\s*\n (\\()",
8787
"end": "(?x)\n (\\))\n ",
8888
"name": "meta.function-call.python",
8989
"contentName": "meta.function-call.arguments.python",
@@ -161,7 +161,7 @@
161161
]
162162
},
163163
{
164-
"begin": "(?x)\n (?<!def\\s+)\n \\b\n (css)\n \\s*\n (\\()",
164+
"begin": "(?x)\n (?<!def\\s+)\n \\b\n (css|hitml\\.css|ht\\.css)\n \\s*\n (\\()",
165165
"end": "(?x)\n (\\))\n ",
166166
"name": "meta.function-call.python",
167167
"contentName": "meta.function-call.arguments.python",
@@ -239,7 +239,7 @@
239239
]
240240
},
241241
{
242-
"begin": "(?x)\n (?<!def\\s+)\n \\b\n (js)\n \\s*\n (\\()",
242+
"begin": "(?x)\n (?<!def\\s+)\n \\b\n (js|hitml\\.js|ht\\.js)\n \\s*\n (\\()",
243243
"end": "(?x)\n (\\))\n ",
244244
"name": "meta.function-call.python",
245245
"contentName": "meta.function-call.arguments.python",

0 commit comments

Comments
 (0)