Skip to content

Commit

Permalink
Generate mozcpp grammar automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
Luni-4 committed Feb 11, 2021
1 parent c2c89dd commit ead4d2a
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
70 changes: 70 additions & 0 deletions generate-moz-grammars/generate-mozcpp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/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
# Update tree-sitter-cpp submodule such that is the same one used within the
# tree-sitter-mozcpp directory
git submodule update --remote tree-sitter-cpp

# Enter the mozcpp directory
pushd tree-sitter-mozcpp

# Download tree-sitter-cpp
git clone https://github.com/tree-sitter/tree-sitter-cpp.git

# Download tree-sitter-c inside the tree-sitter-cpp repository
pushd tree-sitter-cpp

# Clone tree-sitter-c repository
git clone https://github.com/tree-sitter/tree-sitter-c

# Update tree-sitter-cpp grammar.js
NO_FIRST_LINE=$(sed '1d' grammar.js)
echo "const C = require(\"./tree-sitter-c/grammar\")$NO_FIRST_LINE" > grammar.js

# Exit tree-sitter-cpp
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
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 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-mozcpp/grammar.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down

0 comments on commit ead4d2a

Please sign in to comment.