From eb388f641bc2bde71592449910bd61517bdeabec Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Thu, 11 Feb 2021 12:17:05 +0100 Subject: [PATCH] Generate mozcpp grammar automatically --- generate-moz-grammars/generate-mozcpp.sh | 71 ++++++++++++++++++++++++ tree-sitter-mozcpp/grammar.js | 2 +- 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100755 generate-moz-grammars/generate-mozcpp.sh diff --git a/generate-moz-grammars/generate-mozcpp.sh b/generate-moz-grammars/generate-mozcpp.sh new file mode 100755 index 000000000..94aee9ed2 --- /dev/null +++ b/generate-moz-grammars/generate-mozcpp.sh @@ -0,0 +1,71 @@ +#!/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 + +# Create tree-sitter-cpp directory +mkdir -p tree-sitter-cpp + +# Enter tree-sitter-cpp directory +pushd tree-sitter-cpp + +# Shallow clone tree-sitter-cpp to a specific revision +git init +git remote add origin https://github.com/tree-sitter/tree-sitter-cpp.git +git fetch --depth 1 origin $TS_CPP_VERSION +git checkout FETCH_HEAD + +# Install tree-sitter-cpp dependencies +npm install -y + +# 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 +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 diff --git a/tree-sitter-mozcpp/grammar.js b/tree-sitter-mozcpp/grammar.js index cd7f87c5d..b918464ab 100644 --- a/tree-sitter-mozcpp/grammar.js +++ b/tree-sitter-mozcpp/grammar.js @@ -1,4 +1,4 @@ -const CPP = require("../tree-sitter-cpp/grammar.js") +const CPP = require("./tree-sitter-cpp/grammar.js") module.exports = grammar(CPP, { name: 'cpp',