[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/treesit-fold 2014def24a 289/417: feat: Add Verilog support
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/treesit-fold 2014def24a 289/417: feat: Add Verilog support (#75) |
Date: |
Mon, 1 Jul 2024 10:02:36 -0400 (EDT) |
branch: elpa/treesit-fold
commit 2014def24aebf05e2c4a327fbc54be20ab6c8438
Author: Jen-Chieh Shen <jcs090218@gmail.com>
Commit: GitHub <noreply@github.com>
feat: Add Verilog support (#75)
* feat: Add Verilog support
* progress
* match next line
---
CHANGELOG.md | 1 +
README.md | 1 +
ts-fold-parsers.el | 9 +++++++
ts-fold-summary.el | 1 +
ts-fold-util.el | 18 ++++++++++++++
ts-fold.el | 72 +++++++++++++++++++++++++++++++++++++++++-------------
6 files changed, 85 insertions(+), 17 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4c6d7e46e5..5177103cc6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -33,6 +33,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for
recommendations on how
* Add GDScript support (#72)
* Add Scheme support (#73)
* Add Beancount support (#74)
+* Add Verilog support (#75)
## 0.1.0
> Released Oct 18, 2021
diff --git a/README.md b/README.md
index 8def7c4855..276af85532 100644
--- a/README.md
+++ b/README.md
@@ -132,6 +132,7 @@ These languages are fairly complete:
- R / Ruby / Rust
- Scala / Scheme / Swift
- TOML / TypeScript / TSX
+- Verilog
- YAML
These languages are in development:
diff --git a/ts-fold-parsers.el b/ts-fold-parsers.el
index 9cdf533621..1ffe47acd7 100644
--- a/ts-fold-parsers.el
+++ b/ts-fold-parsers.el
@@ -66,6 +66,8 @@
(declare-function ts-fold-range-ruby-if "ts-fold.el")
(declare-function ts-fold-range-rust-macro "ts-fold.el")
(declare-function ts-fold-range-toml-table "ts-fold.el")
+(declare-function ts-fold-range-verilog-list "ts-fold.el")
+(declare-function ts-fold-range-verilog-module "ts-fold.el")
;;
;; (@* "Parsers" )
@@ -386,6 +388,13 @@
"Rule set for TypeScript."
(append (ts-fold-parsers-javascript)))
+(defun ts-fold-parsers-verilog ()
+ "Rule set for Verilog."
+ '((module_declaration . ts-fold-range-verilog-module)
+ (list_of_port_connections . ts-fold-range-verilog-list)
+ (initial_construct . ts-fold-range-initial-construct)
+ (comment . ts-fold-range-c-like-comment)))
+
(defun ts-fold-parsers-yaml ()
"Rule set for YAML."
'((comment
diff --git a/ts-fold-summary.el b/ts-fold-summary.el
index 52a5731da1..0f3d47768d 100644
--- a/ts-fold-summary.el
+++ b/ts-fold-summary.el
@@ -242,6 +242,7 @@ type of content by checking the word boundary's existence."
(toml-mode . ts-fold-summary-javadoc)
(conf-toml-mode . ts-fold-summary-javadoc)
(typescript-mode . ts-fold-summary-javadoc)
+ (verilog-mode . ts-fold-summary-javadoc)
(nxml-mode . ts-fold-summary-xml))
"Alist mapping `major-mode' to doc parser function."
:type '(alist :key-type symbol :value-type function)
diff --git a/ts-fold-util.el b/ts-fold-util.el
index 58face2122..d66850dd37 100644
--- a/ts-fold-util.el
+++ b/ts-fold-util.el
@@ -78,6 +78,24 @@ Optional argument TRIM, see function `ts-fold--get-face'."
Optional argument TRIM, see function `ts-fold--get-face'."
(ts-fold--is-face obj ts-fold--doc-faces trim))
+;;
+;; (@* "Positions" )
+;;
+
+(defun ts-fold--last-eol (pos)
+ "Go to POS then find previous line break, and return its position."
+ (save-excursion
+ (goto-char pos)
+ (max 1 (1- (line-beginning-position)))))
+
+(defun ts-fold--bol (point)
+ "Return line beginning position at POINT."
+ (save-excursion (goto-char point) (line-beginning-position)))
+
+(defun ts-fold--eol (point)
+ "Return line end position at POINT."
+ (save-excursion (goto-char point) (line-end-position)))
+
;;
;; (@* "Math" )
;;
diff --git a/ts-fold.el b/ts-fold.el
index 2aa2969981..dea42f5f17 100644
--- a/ts-fold.el
+++ b/ts-fold.el
@@ -104,6 +104,7 @@
(conf-toml-mode . ,(ts-fold-parsers-toml))
(tuareg-mode . ,(ts-fold-parsers-ocaml))
(typescript-mode . ,(ts-fold-parsers-typescript))
+ (verilog-mode . ,(ts-fold-parsers-verilog))
(yaml-mode . ,(ts-fold-parsers-yaml)))
"An alist of (major-mode . (foldable-node-type . function)).
@@ -485,23 +486,17 @@ more information."
(ts-fold-range-line-comment node offset "///")
(ts-fold-range-line-comment node offset "//")))))
-(defun ts-fold-point-before-line-break (pos)
- "Go to POS then find previous line break, and return its position."
- (save-excursion
- (goto-char pos)
- (max 1 (1- (line-beginning-position)))))
-
;;
;; (@* "Languages" )
;;
(defun ts-fold-range-beancount-transaction (node offset)
- "Define fold range for `transaction' preprocessor.
+ "Define fold range for `transaction' in Beancount.
For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
more information."
(when-let* ((beg (tsc-node-start-position node))
- (beg (save-excursion (goto-char beg) (line-end-position)))
+ (beg (ts-fold--eol beg))
(end (1- (tsc-node-end-position node))))
(ts-fold--cons-add (cons beg end) offset)))
@@ -565,6 +560,8 @@ more information."
(next-node (tsc-get-next-sibling param-node))
(beg (tsc-node-start-position next-node))
(end (1- (tsc-node-end-position node))))
+ (unless ts-fold-on-next-line ; display nicely
+ (setq beg (ts-fold--last-eol beg)))
(ts-fold--cons-add (cons beg end) offset)))
(defun ts-fold-range-elisp-function (node offset)
@@ -576,6 +573,8 @@ more information."
(when-let* ((param-node (tsc-get-nth-child node 4))
(beg (tsc-node-start-position param-node))
(end (1- (tsc-node-end-position node))))
+ (unless ts-fold-on-next-line ; display nicely
+ (setq beg (ts-fold--last-eol beg)))
(ts-fold--cons-add (cons beg end) offset)))
(defun ts-fold-range-elixir (node offset)
@@ -595,7 +594,7 @@ more information."
For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
more information."
(when-let* ((beg (tsc-node-start-position node))
- (beg (save-excursion (goto-char beg) (line-end-position)))
+ (beg (ts-fold--eol beg))
(end-node (ts-fold-last-child node))
(end (tsc-node-end-position end-node)))
(ts-fold--cons-add (cons beg end) offset)))
@@ -654,7 +653,7 @@ more information."
(beg (tsc-node-end-position params))
(end (- (tsc-node-end-position node) 3))) ; fit identifier `end'
(when ts-fold-on-next-line ; display nicely
- (setq end (ts-fold-point-before-line-break end)))
+ (setq end (ts-fold--last-eol end)))
(ts-fold--cons-add (cons beg end) offset)))
(defun ts-fold-range-lua-if (node offset)
@@ -670,7 +669,7 @@ more information."
(tsc-node-start-position (car next))
(- (tsc-node-end-position node) 3))))
(when ts-fold-on-next-line ; display nicely
- (setq end (ts-fold-point-before-line-break end)))
+ (setq end (ts-fold--last-eol end)))
(ts-fold--cons-add (cons beg end) offset)))
(defun ts-fold-range-lua-elseif (node offset)
@@ -685,7 +684,7 @@ more information."
(tsc-node-start-position next)
(tsc-node-end-position node))))
(when ts-fold-on-next-line ; display nicely
- (setq end (ts-fold-point-before-line-break end)))
+ (setq end (ts-fold--last-eol end)))
(ts-fold--cons-add (cons beg end) offset)))
(defun ts-fold-range-lua-else (node offset)
@@ -697,7 +696,7 @@ more information."
(next (tsc-get-next-sibling node)) ; the `end' node
(end (tsc-node-start-position next)))
(when ts-fold-on-next-line ; display nicely
- (setq end (ts-fold-point-before-line-break end)))
+ (setq end (ts-fold--last-eol end)))
(ts-fold--cons-add (cons beg end) offset)))
(defun ts-fold-range-lua-do-loop (node offset)
@@ -709,7 +708,7 @@ more information."
(beg (tsc-node-end-position do))
(end (- (tsc-node-end-position node) 3)))
(when ts-fold-on-next-line ; display nicely
- (setq end (ts-fold-point-before-line-break end)))
+ (setq end (ts-fold--last-eol end)))
(ts-fold--cons-add (cons beg end) offset)))
(defun ts-fold-range-lua-repeat (node offset)
@@ -721,7 +720,7 @@ more information."
(until (car (ts-fold-find-children node "until")))
(end (tsc-node-start-position until)))
(when ts-fold-on-next-line ; display nicely
- (setq end (ts-fold-point-before-line-break end)))
+ (setq end (ts-fold--last-eol end)))
(ts-fold--cons-add (cons beg end) offset)))
;;+ OCaml
@@ -824,7 +823,7 @@ more information."
(end (tsc-node-end-position node))
(end (- end 3)))
(when ts-fold-on-next-line ; display nicely
- (setq end (ts-fold-point-before-line-break end)))
+ (setq end (ts-fold--last-eol end)))
(ts-fold--cons-add (cons beg end) offset)))
(defun ts-fold-range-ruby-if (node offset)
@@ -838,7 +837,7 @@ more information."
((when-let ((parent (ts-fold-find-parent node "if")))
(- (tsc-node-end-position parent) 3))))))
(when ts-fold-on-next-line ; display nicely
- (setq end (ts-fold-point-before-line-break end)))
+ (setq end (ts-fold--last-eol end)))
(ts-fold--cons-add (cons beg end) offset)))
(defun ts-fold-range-rust-macro (node offset)
@@ -863,5 +862,44 @@ more information."
(end (tsc-node-end-position end-child)))
(ts-fold--cons-add (cons beg end) offset)))
+(defun ts-fold-range-initial-construct (node offset)
+ "Return the fold range for `initial' NODE in Verilog.
+
+For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
+more information."
+ (when-let* ((beg (tsc-node-start-position node))
+ (beg (ts-fold--eol beg))
+ (end-child (ts-fold-last-child node))
+ (end (tsc-node-end-position end-child))
+ (end (ts-fold--bol end)))
+ (when ts-fold-on-next-line
+ (setq end (ts-fold--last-eol end)))
+ (ts-fold--cons-add (cons beg end) offset)))
+
+(defun ts-fold-range-verilog-list (node offset)
+ "Return the fold range for `list' NODE in Verilog.
+
+For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
+more information."
+ (when-let* ((prev (tsc-get-prev-sibling node))
+ (next (tsc-get-next-sibling node))
+ (beg (tsc-node-end-position prev))
+ (end (tsc-node-start-position next)))
+ (ts-fold--cons-add (cons beg end) offset)))
+
+(defun ts-fold-range-verilog-module (node offset)
+ "Return the fold range for `module' NODE in Verilog.
+
+For arguments NODE and OFFSET, see function `ts-fold-range-seq' for
+more information."
+ (when-let* ((close-bracket (car (ts-fold-find-children node ";")))
+ (beg (tsc-node-end-position close-bracket))
+ (end-child (ts-fold-last-child node))
+ (end (tsc-node-end-position end-child))
+ (end (ts-fold--bol end)))
+ (when ts-fold-on-next-line
+ (setq end (ts-fold--last-eol end)))
+ (ts-fold--cons-add (cons beg end) offset)))
+
(provide 'ts-fold)
;;; ts-fold.el ends here
- [nongnu] elpa/treesit-fold 0e83f0e5ef 227/417: docs(CHANGELOG): update, (continued)
- [nongnu] elpa/treesit-fold 0e83f0e5ef 227/417: docs(CHANGELOG): update, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 9f24d29c07 233/417: Julia language parser. (#33), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold bbb1eae1a7 234/417: docs(CHANGELOG): fix PR number for #33, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold fe568ebead 246/417: chore: changelog, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold ad1d9b2412 258/417: feat(fold): Add support for Lua (#52), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold eeff646b21 260/417: Optimize performance of ts-fold-close-all with indicators-mode on (#53), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold e8a4110921 261/417: docs: Fix typo, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 7a46b695a1 263/417: Quick fix for ts-fold not checking if tree-sitter is enabled (#55), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 5fd2a5afe2 264/417: fix: Avoid dynamic an already lexical var error, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold aa37d3bb5f 294/417: fix: Improve Elixir UX (#78), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 2014def24a 289/417: feat: Add Verilog support (#75),
ELPA Syncer <=
- [nongnu] elpa/treesit-fold abd12c8fda 146/417: Fix toc, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 790247d439 157/417: Swap demo, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 03872ff486 169/417: Update readme, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold f1297ee040 170/417: Add elpa badge, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 7c2b421d04 163/417: Fill gap, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 9d48ee7937 176/417: Update CI, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 28ec4b244f 192/417: Update ts-fold.el, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 53b78381e9 190/417: Fix installation instruction for straight, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold e4f47602eb 197/417: Update ts-fold.el, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 5be52cde9c 207/417: up, ELPA Syncer, 2024/07/01