branch: elpa/treesit-fold
commit 9f24d29c07d3954c6e1a4e86cb9ffeed64b1c297
Author: Ferruccio Aceves <[email protected]>
Commit: GitHub <[email protected]>
Julia language parser. (#33)
* Julia language parser.
* fix byte positioning translation.
* indentation fix.
* Report Julia language support in README.
* Changelog update.
* Alphabetically sort associated functions.
* forward declare `ts-fold-range-julia`.
* Checkdoc style fix.
* Parser function placed alphabetic order.
Co-authored-by: dmct <[email protected]>
---
CHANGELOG.md | 1 +
README.md | 2 +-
ts-fold-parsers.el | 16 ++++++++++++++++
ts-fold-summary.el | 5 +++++
ts-fold.el | 14 ++++++++++++++
5 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2d5cbf7e4d..ba4eaf8c63 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for
recommendations on how
* Render indicators once it's mode is enabled (#19)
* OCaml parser and first functions added (#21)
* Enhance Ruby parser (#26)
+* Julia language support (#8)
## 0.1.0
> Released Oct 18, 2021
diff --git a/README.md b/README.md
index 4cc83c6b11..2a0863c377 100644
--- a/README.md
+++ b/README.md
@@ -88,7 +88,7 @@ These languages are fairly complete:
* Elixir
* Go
* HTML
-* Java / JavaScript / JSX / JSON
+* Java / JavaScript / JSX / JSON / Julia
* Nix
* PHP / Python
* R / Ruby / Rust
diff --git a/ts-fold-parsers.el b/ts-fold-parsers.el
index 35b4fbb216..d7087b94a0 100644
--- a/ts-fold-parsers.el
+++ b/ts-fold-parsers.el
@@ -45,6 +45,7 @@
(declare-function ts-fold-range-c-preproc-elif "ts-fold.el")
(declare-function ts-fold-range-c-preproc-else "ts-fold.el")
(declare-function ts-fold-range-html "ts-fold.el")
+(declare-function ts-fold-range-julia "ts-fold.el")
(declare-function ts-fold-range-ocaml "ts-fold.el")
(declare-function ts-fold-range-python "ts-fold.el")
(declare-function ts-fold-range-ruby-class-def "ts-fold.el")
@@ -154,6 +155,21 @@
'((object . ts-fold-range-seq)
(array . ts-fold-range-seq)))
+(defun ts-fold-parsers-julia ()
+ "Rule set for Julia."
+ '((block_comment . (ts-fold-range-seq 1 -1))
+ (for_statement . (ts-fold-range-seq 2 -2))
+ (function_definition . ts-fold-range-julia)
+ (if_statement . (ts-fold-range-seq 1 -2))
+ (let_statement . (ts-fold-range-seq 2 -2))
+ (macro_definition . ts-fold-range-julia)
+ (module_definition . ts-fold-range-julia)
+ (quote_statement . ts-fold-range-julia)
+ (struct_definition . ts-fold-range-julia)
+ (triple_string . (ts-fold-range-seq 2 -2))
+ (try_statement . (ts-fold-range-seq 2 -2))
+ (while_statement . ts-fold-range-julia)))
+
(defun ts-fold-parsers-nix ()
"Rule set for Nix."
'((attrset . ts-fold-range-seq)
diff --git a/ts-fold-summary.el b/ts-fold-summary.el
index 35be90df75..66e49cdbff 100644
--- a/ts-fold-summary.el
+++ b/ts-fold-summary.el
@@ -160,6 +160,10 @@ type of content by checking the word boundary's existence."
"Extract summary from DOC-STR in XML."
(ts-fold-summary--generic doc-str "-"))
+(defun ts-fold-summary-julia-doc (doc-str)
+ "Extract summary from DOC-STR in julia."
+ (ts-fold-summary--generic doc-str "\"\"\""))
+
;;
;; (@* "Core" )
;;
@@ -208,6 +212,7 @@ type of content by checking the word boundary's existence."
(js-mode . ts-fold-summary-javadoc)
(js2-mode . ts-fold-summary-javadoc)
(js3-mode . ts-fold-summary-javadoc)
+ (julia-mode . ts-fold-summary-julia-doc)
(kotlin-mode . ts-fold-summary-javadoc)
(lua-mode . ts-fold-summary-lua-doc)
(markdown-mode . ts-fold-summary-markdown)
diff --git a/ts-fold.el b/ts-fold.el
index 427a2231fb..768b22c797 100644
--- a/ts-fold.el
+++ b/ts-fold.el
@@ -81,6 +81,7 @@ The alist is in form of (major-mode . (foldable-node-type)).")
(js3-mode . ,(ts-fold-parsers-javascript))
(json-mode . ,(ts-fold-parsers-json))
(jsonc-mode . ,(ts-fold-parsers-json))
+ (julia-mode . ,(ts-fold-parsers-julia))
(nix-mode . ,(ts-fold-parsers-nix))
(ocaml-mode . ,(ts-fold-parsers-ocaml))
(php-mode . ,(ts-fold-parsers-php))
@@ -594,5 +595,18 @@ more information."
(beg (tsc-node-start-position do_child))
(end (tsc-node-start-position end_child)))
(ts-fold--cons-add (cons beg end) offset)))
+
+(defun ts-fold-range-julia (node offset)
+ "Return the fold range for a NODE in Julia.
+
+It excludes the NODE's first child and the `end' keyword. For
+argument OFFSET, see function `ts-fold-range-seq' for more
+information."
+ (let* ((identifier (tsc-get-nth-named-child node 0))
+ (end-position (byte-to-position (aref (tsc-node-range identifier) 1)))
+ (start-position (byte-to-position (aref (tsc-node-range node) 0)))
+ (fold-begin (1- (- end-position start-position))))
+ (ts-fold-range-seq node (ts-fold--cons-add (cons fold-begin -2) offset))))
+
(provide 'ts-fold)
;;; ts-fold.el ends here