Skip to content

Commit d4adc3d

Browse files
authored
Merge pull request #4254 from James-Yu/regfactor_vlb
Refactor the development of grammars
2 parents 0000256 + 8011845 commit d4adc3d

15 files changed

+55
-283
lines changed

dev/build-grammar.js

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
const fs = require('fs')
2-
const path = require('path')
3-
const vel = require('vscode-extend-language')
1+
import fs from 'fs'
2+
import path from 'path'
3+
import {download, getCommitSha, expandConfigurationFile} from'vscode-extend-language'
44

5-
const syntaxDir = path.join(__dirname, '..', 'syntax')
5+
const syntaxDir = './syntax'
66

7+
/**
8+
* Download a file from a specific branch on a repo
9+
* @param {string} repo
10+
* @param {string} file
11+
* @param {string} version git branch to pull
12+
*/
713
async function downloadFile(repo, file, version='main') {
814
const url = 'https://raw.githubusercontent.com/' + repo + '/' + version + '/' + file
9-
var content = await vel.download(url)
15+
var content = await download(url)
1016
if (!content) {
1117
console.log('Cannot retrieve ', url)
1218
return
@@ -16,37 +22,50 @@ async function downloadFile(repo, file, version='main') {
1622
console.log('Updating', syntaxFilePath)
1723
}
1824

19-
async function main() {
25+
async function updateGrammars() {
2026
const latexBasicsRepo = 'jlelong/vscode-latex-basics'
2127
const grammarFiles = [
28+
'BibTeX-style.tmLanguage.json',
2229
'Bibtex.tmLanguage.json',
30+
'DocTeX.tmLanguage.json',
31+
'JLweave.tmLanguage.json',
2332
'LaTeX.tmLanguage.json',
33+
'Pweave.tmLanguage.json',
34+
'RSweave.tmLanguage.json',
2435
'TeX.tmLanguage.json',
2536
'cpp-grammar-bailout.tmLanguage.json',
2637
'markdown-latex-combined.tmLanguage.json'
2738
]
2839

29-
const sha = await vel.getCommitSha(latexBasicsRepo)
40+
const sha = await getCommitSha(latexBasicsRepo)
3041
if (sha) {
3142
console.log(`Update grammar files to ${latexBasicsRepo}@${sha}`)
3243
} else {
3344
console.log('Cannot read last commit information')
3445
}
3546
for (const file of grammarFiles) {
36-
downloadFile(latexBasicsRepo, 'syntaxes/' + file)
47+
await downloadFile(latexBasicsRepo, 'syntaxes/' + file)
3748
}
3849

50+
}
51+
52+
async function main() {
53+
54+
await updateGrammars()
3955
// The order of the files matters!
40-
languageFiles = [
56+
const languageFiles = [
57+
'latex-language-configuration.json',
4158
'latex-cpp-embedded-language-configuration.json',
4259
'markdown-latex-combined-language-configuration.json',
43-
'latex-language-configuration.json',
44-
'latex3-language-configuration.json'
60+
'latex3-language-configuration.json',
61+
'bibtex-language-configuration.json',
62+
'bibtex-style-language-configuration.json',
63+
'doctex-language-configuration.json'
4564
]
4665
for (const file of languageFiles) {
4766
console.log('Expanding', path.join(syntaxDir, file))
48-
await vel.expandConfigurationFile(path.join(syntaxDir, 'src', file), path.join(syntaxDir, file))
67+
await expandConfigurationFile(path.join(syntaxDir, 'src', file), path.join(syntaxDir, file))
4968
}
5069
}
5170

52-
main()
71+
await main()

package-lock.json

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,8 +2579,7 @@
25792579
"test": "node ./out/test/runTest.js",
25802580
"watch-src": "tsc -watch -p tsconfig.json",
25812581
"watch-viewer": "tsc -watch -p viewer/tsconfig.json",
2582-
"build-grammar": "node ./dev/build-grammar.js",
2583-
"update-grammar": "node ./dev/update-grammar.js"
2582+
"update-grammar": "node ./dev/update-grammar.mjs"
25842583
},
25852584
"dependencies": {
25862585
"cross-spawn": "7.0.3",
@@ -2619,6 +2618,6 @@
26192618
"rimraf": "5.0.5",
26202619
"textmate-bailout": "1.1.0",
26212620
"typescript": "5.3.3",
2622-
"vscode-extend-language": "0.1.2"
2621+
"vscode-extend-language": "^0.2.2"
26232622
}
26242623
}

syntax/README.md

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
11
# Grammars and language configuration Files
22

3-
The following grammar files are retrieved from https://github.com/jlelong/vscode-latex-basics and are updated by the script `npm run update-grammar`
3+
All the `tmLanguage.json` files of this directory are retrieved from https://github.com/jlelong/vscode-latex-basics by running `npm run update-grammar`
44

5-
- `Bibtex.tmLanguage.json`
6-
- `LaTeX.tmLanguage.json`
7-
- `TeX.tmLanguage.json`
8-
- `cpp-grammar-bailout.tmLanguage.json`
9-
- `markdown-latex-combined.tmLanguage.json`
10-
11-
The following language configuration files are built from the corresponding file in `src/` using `npm run update-grammar`
12-
13-
- `latex-cpp-embedded-language-configuration.json`
14-
- `latex-language-configuration.json`
15-
- `latex3-language-configuration.json`
16-
- `markdown-latex-combined-language-configuration.json`
17-
18-
The following files are generated from the `.yaml` files located in `src/` using `npm run build-grammar`
19-
20-
- `BibTeX-style.tmLanguage.json`
21-
- `DocTeX.tmLanguage.json`
22-
- `JLweave.tmLanguage.json`
23-
- `LaTeX-Expl3.tmLanguage.json`
24-
- `Pweave.tmLanguage.json`
25-
- `RSweave.tmLanguage.json`
5+
The language configuration files are built from the files in `src/` by running `npm run update-grammar`

syntax/bibtex-language-configuration.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"brackets": [
66
["{", "}"],
77
["[", "]"],
8-
["(", ")"],
8+
["(", ")"]
99
],
1010
"autoClosingPairs": [
1111
["{", "}"],

syntax/src/BibTeX-style.tmLanguage.yaml

Lines changed: 0 additions & 61 deletions
This file was deleted.

syntax/src/DocTeX.tmLanguage.yaml

Lines changed: 0 additions & 34 deletions
This file was deleted.

syntax/src/JLweave.tmLanguage.yaml

Lines changed: 0 additions & 25 deletions
This file was deleted.

syntax/src/Pweave.tmLanguage.yaml

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)