-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate mozcpp grammar automatically
- Loading branch information
Showing
2 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/bin/bash | ||
|
||
# This script updates the mozcpp grammar automatically. | ||
# | ||
# Usage: ./generate-moz-grammars/generate-mozcpp.sh | ||
|
||
# FIXME we need to remove this line once we are going to use | ||
# the tree-sitter-cpp bindings | ||
# Get the tree-sitter-cpp submodule version | ||
TS_CPP_VERSION=`git submodule status tree-sitter-cpp | awk '{ print $1 }'` | ||
|
||
# Enter the mozcpp directory | ||
pushd tree-sitter-mozcpp | ||
|
||
# Download tree-sitter-cpp | ||
git clone https://github.com/tree-sitter/tree-sitter-cpp.git | ||
|
||
# Enter tree-sitter-cpp directory | ||
pushd tree-sitter-cpp | ||
|
||
# Checkout the tree-sitter-cpp submodule version | ||
git checkout $TS_CPP_VERSION | ||
|
||
# Clone tree-sitter-c repository | ||
git clone https://github.com/tree-sitter/tree-sitter-c | ||
|
||
# Update the path to the tree-sitter-c repository contained in | ||
# the grammar.js file | ||
NO_FIRST_LINE=`sed '1d' grammar.js` | ||
echo "const C = require(\"./tree-sitter-c/grammar\")$NO_FIRST_LINE" > grammar.js | ||
|
||
# Exit tree-sitter-cpp 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-cpp directory, and consequently tree-sitter-c directory | ||
rm -rf tree-sitter-cpp | ||
|
||
# Exit tree-sitter-mozcpp 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters