Skip to content

Commit

Permalink
Add script for generating grammars.dat and setup CI (#2)
Browse files Browse the repository at this point in the history
* Make script work in node.js. The function `generate()` now just returns the blob.

* Log which language is loading right now

* Add GitHub action script for build and publish grammars.dat as artifact

* Add Create Pull Request workflow

* Update README.md

Co-authored-by: Fela Ameghino <[email protected]>
  • Loading branch information
STmihan and FrayxRulez authored Oct 30, 2023
1 parent e686941 commit 2478423
Show file tree
Hide file tree
Showing 7 changed files with 365 additions and 1,930 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/build-grammars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Update grammars

on: [ workflow_dispatch ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm install
- run: npm start
- name: Upload a Build Artifact
uses: actions/[email protected]
with:
name: grammars.dat
path: ./libprisma/grammars.dat
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
commit-message: Update grammars
title: Update grammars
branch: update-grammars
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ bld/

# Visual Studio 2015/2017 cache/options directory
.vs/
# Webstorm cache directory
.idea/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

Expand Down Expand Up @@ -360,4 +362,4 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ for (auto it = tokens.begin(); it != tokens.end(); ++it)
```
### How to update
As mentioned, grammars dictionary is generated starting from prism.js source code.
Currently, this is done manually by visiting prism's [test drive](https://prismjs.com/test.html).
Once on the page, it is necessary to select all the languages, open the browser console and paste in both `isEqual.js` and `generate.js`.
After a few seconds, the file `grammars.dat` will be downloaded.
TODO: would be great to automate this step, or at least to make the script auto-execute rather to require all the user input.
Run
```sh
npm install
npm start
```
The new version of `grammars.dat` will appear in the `libprisma/grammars.dat`.

### Supported languages
| Language | Aliases |
Expand Down
Loading

0 comments on commit 2478423

Please sign in to comment.