Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
68 changes: 68 additions & 0 deletions generate-moz-grammars/generate-mozjs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

# This script updates the mozjs grammar automatically.
#
# Usage: ./generate-moz-grammars/generate-mozjs.sh

# FIXME we need to remove this line once we are going to use
# the tree-sitter-javascript bindings
# Get the tree-sitter-javascript submodule version
TS_JS_VERSION=`git submodule status tree-sitter-javascript | awk '{ print $1 }'`

# Enter the mozjs directory
pushd tree-sitter-mozjs

# Create tree-sitter-javascript directory
mkdir -p tree-sitter-javascript

# Enter tree-sitter-javascript directory
pushd tree-sitter-javascript

# Shallow clone tree-sitter-javascript to a specific revision
git init
git remote add origin https://github.com/tree-sitter/tree-sitter-javascript.git
git fetch --depth 1 origin $TS_JS_VERSION
git checkout FETCH_HEAD

# Exit tree-sitter-javascript directory
popd

# Init npm
npm init -y

# Install a small module that lets the parser be used from Node
npm install --save nan

# Install the Tree-sitter CLI
npm install --save-dev tree-sitter-cli

# Generate moz-cpp grammar
./node_modules/.bin/tree-sitter generate

# Delete node_modules
rm -rf node_modules

# Delete package files
rm -rf package-lock.json package.json

# Delete tree-sitter-javascript directory
rm -rf tree-sitter-javascript

# Exit tree-sitter-mozjs directory
popd

# Enter enums directory
pushd enums

# Recreate the grammar for rust-code-analysis
cargo clean && cargo run -- -lrust -o ../src/languages

# Exit enums directory
popd

# Format the produced grammars
cargo fmt

# Run rust code-analysis to verify if everything works correctly and to
# update the Cargo.lock
cargo test --workspace
2 changes: 1 addition & 1 deletion tree-sitter-mozjs/grammar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const JS = require("../tree-sitter-javascript/grammar.js")
const JS = require("./tree-sitter-javascript/grammar.js")

module.exports = grammar(JS, {
name: 'mozjs',
Expand Down