Skip to content

Commit

Permalink
(wip) change CI, align tab
Browse files Browse the repository at this point in the history
  • Loading branch information
quangIO committed Aug 26, 2021
1 parent aaac25d commit df5f5e2
Show file tree
Hide file tree
Showing 4 changed files with 358 additions and 2 deletions.
19 changes: 19 additions & 0 deletions .azure-pipelines/steps/grammar-bundle/-create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@ steps:

- bash: |
set -e
brew install gcc
displayName: Install GCC
condition: and(succeeded(), eq(variables['Agent.OS'], 'Darwin'))

- bash: |
set -e
sudo apt install build-essential manpages-dev software-properties-common -y
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
sudo apt update -y && sudo apt install gcc-11 g++-11 -y
displayName: Install GCC
condition: and(succeeded(), eq(variables['Agent.OS'], 'Linux'))


- bash: |
set -e
export CXXFLAGS="$CXXFLAGS -std=c++17 -O2"
export CFLAGS="$CFLAGS -O2"
alias gcc="gcc-11"
alias g++="g++-11"
BUNDLE_VERSION=$(cask eval "(progn (require 'tree-sitter-langs-build) (princ tree-sitter-langs--bundle-version))")
echo "##vso[task.setvariable variable=BUNDLE_VERSION]$BUNDLE_VERSION"
cask eval "(progn (require 'tree-sitter-langs-build) (tree-sitter-langs-create-bundle :clean))"
Expand Down
6 changes: 4 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@
[submodule "repos/hcl"]
path = repos/hcl
url = https://github.com/mitchellh/tree-sitter-hcl.git
ignore = dirty
branch = master
ignore = dirty
branch = master
[submodule "repos/haskell"]
path = repos/haskell
url = https://github.com/tree-sitter/tree-sitter-haskell
ignore = dirty
branch = master
169 changes: 169 additions & 0 deletions .gitmodules.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# `update = none` makes `git submodule update` a no-op. This prevents wasteful work on e.g. MELPA.
# Checkouts can be done explicitly with `git submodule update --checkout`.

# `ignore = dirty` makes `git status` ignore untracked files and uncommited changes in submodules.
# This reduces noises when working on the grammars.

# `branch =` allows using `git submodule update --checkout --remote` to update to the latest
# revision of a remote branch.

[submodule "repos/agda"]
path = repos/agda
url = https://github.com/tree-sitter/tree-sitter-agda
update = none
ignore = dirty
branch = master
[submodule "repos/bash"]
path = repos/bash
url = https://github.com/tree-sitter/tree-sitter-bash
update = none
ignore = dirty
branch = master
[submodule "repos/c"]
path = repos/c
url = https://github.com/tree-sitter/tree-sitter-c
update = none
ignore = dirty
branch = master
[submodule "repos/c-sharp"]
path = repos/c-sharp
url = https://github.com/tree-sitter/tree-sitter-c-sharp
update = none
ignore = dirty
branch = master
[submodule "repos/cpp"]
path = repos/cpp
url = https://github.com/tree-sitter/tree-sitter-cpp
update = none
ignore = dirty
branch = master
[submodule "repos/css"]
path = repos/css
url = https://github.com/tree-sitter/tree-sitter-css
update = none
ignore = dirty
branch = master
[submodule "repos/elm"]
path = repos/elm
url = https://github.com/razzeee/tree-sitter-elm
update = none
ignore = dirty
branch = main
[submodule "repos/fluent"]
path = repos/fluent
url = https://github.com/tree-sitter/tree-sitter-fluent
update = none
ignore = dirty
branch = master
[submodule "repos/go"]
path = repos/go
url = https://github.com/tree-sitter/tree-sitter-go
update = none
ignore = dirty
branch = master
[submodule "repos/html"]
path = repos/html
url = https://github.com/tree-sitter/tree-sitter-html
update = none
ignore = dirty
branch = master
[submodule "repos/janet-simple"]
path = repos/janet-simple
url = https://codeberg.org/sogaiu/tree-sitter-janet-simple
update = none
ignore = dirty
branch = master
[submodule "repos/java"]
path = repos/java
url = https://github.com/tree-sitter/tree-sitter-java
update = none
ignore = dirty
branch = master
[submodule "repos/javascript"]
path = repos/javascript
url = https://github.com/tree-sitter/tree-sitter-javascript
update = none
ignore = dirty
branch = master
[submodule "repos/jsdoc"]
path = repos/jsdoc
url = https://github.com/tree-sitter/tree-sitter-jsdoc
update = none
ignore = dirty
branch = master
[submodule "repos/json"]
path = repos/json
url = https://github.com/tree-sitter/tree-sitter-json
update = none
ignore = dirty
branch = master
[submodule "repos/julia"]
path = repos/julia
url = https://github.com/tree-sitter/tree-sitter-julia
update = none
ignore = dirty
branch = master
[submodule "repos/ocaml"]
path = repos/ocaml
url = https://github.com/tree-sitter/tree-sitter-ocaml
update = none
ignore = dirty
branch = master
[submodule "repos/php"]
path = repos/php
url = https://github.com/tree-sitter/tree-sitter-php
update = none
ignore = dirty
branch = master
[submodule "repos/python"]
path = repos/python
url = https://github.com/tree-sitter/tree-sitter-python
update = none
ignore = dirty
branch = master
[submodule "repos/ruby"]
path = repos/ruby
url = https://github.com/tree-sitter/tree-sitter-ruby
update = none
ignore = dirty
branch = master
[submodule "repos/rust"]
path = repos/rust
url = https://github.com/tree-sitter/tree-sitter-rust
update = none
ignore = dirty
branch = master
[submodule "repos/scala"]
path = repos/scala
url = https://github.com/tree-sitter/tree-sitter-scala
update = none
ignore = dirty
branch = master
[submodule "repos/swift"]
path = repos/swift
url = https://github.com/tree-sitter/tree-sitter-swift
update = none
ignore = dirty
branch = master
[submodule "repos/typescript"]
path = repos/typescript
url = https://github.com/tree-sitter/tree-sitter-typescript
update = none
<<<<<<< HEAD
ignore = dirty
branch = master
[submodule "repos/haskell"]
path = repos/haskell
url = https://github.com/tree-sitter/tree-sitter-haskell
=======
ignore = dirty
branch = master
[submodule "repos/pgn"]
path = repos/pgn
url = https://github.com/rolandwalker/tree-sitter-pgn.git
ignore = dirty
branch = master
[submodule "repos/hcl"]
path = repos/hcl
url = https://github.com/mitchellh/tree-sitter-hcl.git
>>>>>>> upstream/master
166 changes: 166 additions & 0 deletions tree-sitter-langs.el.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
;;; tree-sitter-langs.el --- Grammar bundle for tree-sitter -*- lexical-binding: t; coding: utf-8 -*-

;; Copyright (C) 2021 Tuấn-Anh Nguyễn
;;
;; Author: Tuấn-Anh Nguyễn <[email protected]>
;; Keywords: languages tools parsers tree-sitter
;; Homepage: https://github.com/emacs-tree-sitter/tree-sitter-langs
;; Version: 0.10.5
;; Package-Requires: ((emacs "25.1") (tree-sitter "0.15.0"))
;; SPDX-License-Identifier: MIT

;;; Commentary:

;; This is a convenient language bundle for the Emacs package `tree-sitter'. It
;; serves as an interim distribution mechanism, until `tree-sitter' is
;; widespread enough for language-specific major modes to incorporate its
;; functionalities.
;;
;; For each supported language, this package provides:
;;
;; 1. Pre-compiled grammar binaries for 3 major platforms: macOS, Linux and
;; Windows, on x86_64. In the future, `tree-sitter-langs' may provide tooling
;; for major modes to do this on their own.
;;
;; 2. Optional highlighting patterns. This is mainly intended for major modes
;; that are not aware of `tree-sitter'. A language major mode that wants to
;; use `tree-sitter' for syntax highlighting should instead provide the query
;; patterns on its own, using the mechanisms defined by `tree-sitter-hl'.
;;
;; 3. Optional query patterns for other minor modes that provide high-level
;; functionalities on top of `tree-sitter', such as code folding, evil text
;; objects... As with highlighting patterns, major modes that are directly
;; aware of `tree-sitter' should provide the query patterns on their own.


;;; Code:

(require 'cl-lib)

(require 'tree-sitter)
(require 'tree-sitter-load)
(require 'tree-sitter-hl)

(require 'tree-sitter-langs-build)

(eval-when-compile
(require 'pcase))

;; Not everyone uses a package manager that properly checks dependencies. We check it ourselves, and
;; ask users to upgrade `tree-sitter' if necessary. Otherwise, they would get `tsc-lang-abi-too-new'
;; errors, without an actionable message.
(let ((min-version "0.15.0"))
(when (version< tsc-dyn--version min-version)
(display-warning 'tree-sitter-langs
(format "Please upgrade `tree-sitter'. This bundle requires version %s or later." min-version)
:emergency)))

(defgroup tree-sitter-langs nil
"Grammar bundle for `tree-sitter'."
:group 'tree-sitter)

(defvar tree-sitter-langs--testing)
(eval-and-compile
(unless (bound-and-true-p tree-sitter-langs--testing)
(tree-sitter-langs-install-grammars :skip-if-installed)))

(defun tree-sitter-langs-ensure (lang-symbol)
"Return the language object identified by LANG-SYMBOL.
If it cannot be loaded, this function tries to compile the grammar.

This function also tries to copy highlight query from the language repo, if it
exists.

See `tree-sitter-langs-repos'."
(unwind-protect
(condition-case nil
(tree-sitter-require lang-symbol)
(error
(display-warning 'tree-sitter-langs
(format "Could not load grammar for `%s', trying to compile it"
lang-symbol))
(tree-sitter-langs-compile lang-symbol)
(tree-sitter-require lang-symbol)))
(tree-sitter-langs--copy-query lang-symbol)))

;;; Add the bundle directory.
(cl-pushnew (tree-sitter-langs--bin-dir)
tree-sitter-load-path)

;;; Link known major modes to languages in the bundle.
(pcase-dolist
(`(,major-mode . ,lang-symbol)
(reverse '((agda-mode . agda)
(sh-mode . bash)
(c-mode . c)
(csharp-mode . c-sharp)
(c++-mode . cpp)
(css-mode . css)
(elm-mode . elm)
(go-mode . go)
<<<<<<< HEAD
(haskell-mode . haskell)
=======
(hcl-mode . hcl)
>>>>>>> upstream/master
(html-mode . html)
(mhtml-mode . html)
(java-mode . java)
(javascript-mode . javascript)
(js-mode . javascript)
(js2-mode . javascript)
(js3-mode . javascript)
(json-mode . json)
(jsonc-mode . json)
(julia-mode . julia)
(ocaml-mode . ocaml)
(php-mode . php)
(python-mode . python)
(pygn-mode . pgn)
(rjsx-mode . javascript)
(ruby-mode . ruby)
(rust-mode . rust)
(rustic-mode . rust)
(scala-mode . scala)
(swift-mode . swift)
(tuareg-mode . ocaml)
(typescript-mode . typescript))))
(setf (map-elt tree-sitter-major-mode-language-alist major-mode)
lang-symbol))

(defun tree-sitter-langs--hl-query-path (lang-symbol)
(concat (file-name-as-directory
(concat tree-sitter-langs--queries-dir
(symbol-name lang-symbol)))
"highlights.scm"))

(defun tree-sitter-langs--hl-default-patterns (lang-symbol)
"Return the bundled default syntax highlighting patterns for LANG-SYMBOL.
Return nil if there are no bundled patterns."
(condition-case nil
(with-temp-buffer
;; TODO: Make this less ad-hoc.
(dolist (sym (cons lang-symbol
(pcase lang-symbol
('cpp '(c))
('typescript '(javascript))
('tsx '(typescript javascript))
(_ nil))))
(insert-file-contents (tree-sitter-langs--hl-query-path sym))
(goto-char (point-max))
(insert "\n"))
(buffer-string))
(file-missing nil)))

(defun tree-sitter-langs--set-hl-default-patterns (&rest _args)
"Use syntax highlighting patterns provided by `tree-sitter-langs'."
(unless tree-sitter-hl-default-patterns
(let ((lang-symbol (tsc--lang-symbol tree-sitter-language)))
(setq tree-sitter-hl-default-patterns
(tree-sitter-langs--hl-default-patterns lang-symbol)))))

(advice-add 'tree-sitter-hl--setup :before
#'tree-sitter-langs--set-hl-default-patterns)

(provide 'tree-sitter-langs)
;;; tree-sitter-langs.el ends here

0 comments on commit df5f5e2

Please sign in to comment.