Skip to content

Commit

Permalink
Merge pull request #4254 from James-Yu/regfactor_vlb
Browse files Browse the repository at this point in the history
Refactor the development of grammars
  • Loading branch information
jlelong authored May 2, 2024
2 parents 0000256 + 8011845 commit d4adc3d
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 283 deletions.
36 changes: 0 additions & 36 deletions dev/build-grammar.js

This file was deleted.

45 changes: 32 additions & 13 deletions dev/update-grammar.js → dev/update-grammar.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
const fs = require('fs')
const path = require('path')
const vel = require('vscode-extend-language')
import fs from 'fs'
import path from 'path'
import {download, getCommitSha, expandConfigurationFile} from'vscode-extend-language'

const syntaxDir = path.join(__dirname, '..', 'syntax')
const syntaxDir = './syntax'

/**
* Download a file from a specific branch on a repo
* @param {string} repo
* @param {string} file
* @param {string} version git branch to pull
*/
async function downloadFile(repo, file, version='main') {
const url = 'https://raw.githubusercontent.com/' + repo + '/' + version + '/' + file
var content = await vel.download(url)
var content = await download(url)
if (!content) {
console.log('Cannot retrieve ', url)
return
Expand All @@ -16,37 +22,50 @@ async function downloadFile(repo, file, version='main') {
console.log('Updating', syntaxFilePath)
}

async function main() {
async function updateGrammars() {
const latexBasicsRepo = 'jlelong/vscode-latex-basics'
const grammarFiles = [
'BibTeX-style.tmLanguage.json',
'Bibtex.tmLanguage.json',
'DocTeX.tmLanguage.json',
'JLweave.tmLanguage.json',
'LaTeX.tmLanguage.json',
'Pweave.tmLanguage.json',
'RSweave.tmLanguage.json',
'TeX.tmLanguage.json',
'cpp-grammar-bailout.tmLanguage.json',
'markdown-latex-combined.tmLanguage.json'
]

const sha = await vel.getCommitSha(latexBasicsRepo)
const sha = await getCommitSha(latexBasicsRepo)
if (sha) {
console.log(`Update grammar files to ${latexBasicsRepo}@${sha}`)
} else {
console.log('Cannot read last commit information')
}
for (const file of grammarFiles) {
downloadFile(latexBasicsRepo, 'syntaxes/' + file)
await downloadFile(latexBasicsRepo, 'syntaxes/' + file)
}

}

async function main() {

await updateGrammars()
// The order of the files matters!
languageFiles = [
const languageFiles = [
'latex-language-configuration.json',
'latex-cpp-embedded-language-configuration.json',
'markdown-latex-combined-language-configuration.json',
'latex-language-configuration.json',
'latex3-language-configuration.json'
'latex3-language-configuration.json',
'bibtex-language-configuration.json',
'bibtex-style-language-configuration.json',
'doctex-language-configuration.json'
]
for (const file of languageFiles) {
console.log('Expanding', path.join(syntaxDir, file))
await vel.expandConfigurationFile(path.join(syntaxDir, 'src', file), path.join(syntaxDir, file))
await expandConfigurationFile(path.join(syntaxDir, 'src', file), path.join(syntaxDir, file))
}
}

main()
await main()
13 changes: 8 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2579,8 +2579,7 @@
"test": "node ./out/test/runTest.js",
"watch-src": "tsc -watch -p tsconfig.json",
"watch-viewer": "tsc -watch -p viewer/tsconfig.json",
"build-grammar": "node ./dev/build-grammar.js",
"update-grammar": "node ./dev/update-grammar.js"
"update-grammar": "node ./dev/update-grammar.mjs"
},
"dependencies": {
"cross-spawn": "7.0.3",
Expand Down Expand Up @@ -2619,6 +2618,6 @@
"rimraf": "5.0.5",
"textmate-bailout": "1.1.0",
"typescript": "5.3.3",
"vscode-extend-language": "0.1.2"
"vscode-extend-language": "^0.2.2"
}
}
24 changes: 2 additions & 22 deletions syntax/README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
# Grammars and language configuration Files

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

- `Bibtex.tmLanguage.json`
- `LaTeX.tmLanguage.json`
- `TeX.tmLanguage.json`
- `cpp-grammar-bailout.tmLanguage.json`
- `markdown-latex-combined.tmLanguage.json`

The following language configuration files are built from the corresponding file in `src/` using `npm run update-grammar`

- `latex-cpp-embedded-language-configuration.json`
- `latex-language-configuration.json`
- `latex3-language-configuration.json`
- `markdown-latex-combined-language-configuration.json`

The following files are generated from the `.yaml` files located in `src/` using `npm run build-grammar`

- `BibTeX-style.tmLanguage.json`
- `DocTeX.tmLanguage.json`
- `JLweave.tmLanguage.json`
- `LaTeX-Expl3.tmLanguage.json`
- `Pweave.tmLanguage.json`
- `RSweave.tmLanguage.json`
The language configuration files are built from the files in `src/` by running `npm run update-grammar`
2 changes: 1 addition & 1 deletion syntax/bibtex-language-configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"],
["(", ")"]
],
"autoClosingPairs": [
["{", "}"],
Expand Down
61 changes: 0 additions & 61 deletions syntax/src/BibTeX-style.tmLanguage.yaml

This file was deleted.

34 changes: 0 additions & 34 deletions syntax/src/DocTeX.tmLanguage.yaml

This file was deleted.

25 changes: 0 additions & 25 deletions syntax/src/JLweave.tmLanguage.yaml

This file was deleted.

35 changes: 0 additions & 35 deletions syntax/src/Pweave.tmLanguage.yaml

This file was deleted.

Loading

0 comments on commit d4adc3d

Please sign in to comment.