Skip to content

Commit 5cd6063

Browse files
authored
feat: Add CSV support (#270)
* feat: Add CVS support * Ignore certain queries test * Print skip tests
1 parent 70d0f92 commit 5cd6063

File tree

9 files changed

+46
-19
lines changed

9 files changed

+46
-19
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,3 +496,9 @@
496496
branch = master
497497
update = none
498498
ignore = dirty
499+
[submodule "repos/csv"]
500+
path = repos/csv
501+
url = https://github.com/amaanq/tree-sitter-csv
502+
branch = master
503+
update = none
504+
ignore = dirty

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## Unreleased
4+
- Add `CSV` support
45

56
## 0.12.70 - 2023-10-12
67
- Add `Fish` support

queries/csv/highlights.scm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
; inherits: tsv
2+
3+
"," @punctuation.delimiter

queries/psv/highlights.scm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
; inherits: tsv
2+
3+
"|" @punctuation.delimiter

queries/tsv/highlights.scm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(text) @string
2+
(number) @number
3+
(float) @float
4+
(boolean) @boolean

repos/csv

Submodule csv added at 6c19574

tree-sitter-langs-build.el

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,10 @@ git checkout."
158158
(buffer-substring-no-properties 2 9))
159159
:paths (pcase lang-symbol
160160
;; XXX
161-
('typescript '("typescript" ("tsx" . tsx)))
161+
('csv '("csv" ("csv" . csv)))
162162
('ocaml '("ocaml" ("interface" . ocaml-interface)))
163163
('ocaml-interface '("interface" ("interface" . ocaml-interface)))
164+
('typescript '("typescript" ("tsx" . tsx)))
164165
('xml '("tree-sitter-xml" ("tree-sitter-dtd" . dtd)))
165166
(_ '("")))))))
166167

@@ -182,15 +183,15 @@ git checkout."
182183
"Call FN in each of the language repositories."
183184
(let ((repos-dir (tree-sitter-langs--repos-dir)))
184185
(thread-last (directory-files repos-dir)
185-
(seq-map (lambda (name)
186-
(unless (member name '("." ".."))
187-
(let ((dir (concat repos-dir name)))
188-
(when (file-directory-p dir)
189-
`(,name . ,dir))))))
190-
(seq-filter #'identity)
191-
(seq-map (lambda (d)
192-
(pcase-let ((`(,name . ,default-directory) d))
193-
(funcall fn name)))))))
186+
(seq-map (lambda (name)
187+
(unless (member name '("." ".."))
188+
(let ((dir (concat repos-dir name)))
189+
(when (file-directory-p dir)
190+
`(,name . ,dir))))))
191+
(seq-filter #'identity)
192+
(seq-map (lambda (d)
193+
(pcase-let ((`(,name . ,default-directory) d))
194+
(funcall fn name)))))))
194195

195196
(defun tree-sitter-langs--update-repos ()
196197
"Update lang repos' remotes."
@@ -214,7 +215,7 @@ latest commit."
214215
(let* ((base (or base "origin/master"))
215216
(default-directory tree-sitter-langs-git-dir)
216217
(changed-files (thread-first
217-
(format "git --no-pager diff --name-only %s" base)
218+
(format "git --no-pager diff --name-only %s" base)
218219
shell-command-to-string
219220
string-trim split-string))
220221
grammar-changed queries-changed)
@@ -410,13 +411,13 @@ compile from the current state of the grammar repos, without cleanup."
410411
(unless (executable-find "tar")
411412
(error "Could not find tar executable (needed to bundle compiled grammars)"))
412413
(let ((errors (thread-last
413-
(tree-sitter-langs--map-repos
414-
(lambda (name)
415-
(message "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
416-
(let ((lang-symbol (intern name)))
417-
(condition-case err
418-
(tree-sitter-langs-compile lang-symbol clean target)
419-
(error `[,lang-symbol ,err])))))
414+
(tree-sitter-langs--map-repos
415+
(lambda (name)
416+
(message "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
417+
(let ((lang-symbol (intern name)))
418+
(condition-case err
419+
(tree-sitter-langs-compile lang-symbol clean target)
420+
(error `[,lang-symbol ,err])))))
420421
(seq-filter #'identity))))
421422
(message "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
422423
(unwind-protect
@@ -536,7 +537,8 @@ This assumes the repo has already been set up, for example by
536537
`tree-sitter-langs-compile'.
537538
538539
If the optional arg FORCE is non-nil, any existing file will be overwritten."
539-
(let ((src (thread-first (tree-sitter-langs--repos-dir)
540+
(let ((src (thread-first
541+
(tree-sitter-langs--repos-dir)
540542
(concat (symbol-name lang-symbol))
541543
file-name-as-directory (concat "queries")
542544
file-name-as-directory (concat "highlights.scm"))))

tree-sitter-langs-tests.el

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
(eval-when-compile
2020
(require 'subr-x))
2121

22+
(defvar tree-sitter-langs-tests-ignore-queries
23+
'( psv tsv)
24+
"List of queries to ignore the test.")
25+
2226
(defun tree-sitter-langs-tests-check-queries (lang-symbol)
2327
"Check LANG-SYMBOL's queries."
2428
(let ((language (tree-sitter-require lang-symbol))
@@ -33,6 +37,7 @@
3337
(lang-symbol (intern lang-name)))
3438
(eval
3539
`(ert-deftest ,test-symbol ()
40+
(skip-unless (not (memq (quote ,lang-symbol) tree-sitter-langs-tests-ignore-queries)))
3641
(tree-sitter-langs-tests-check-queries (quote ,lang-symbol))))))))
3742

3843
(tree-sitter-langs--map-repos

tree-sitter-langs.el

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ See `tree-sitter-langs-repos'."
122122
(dart-mode . dart)
123123
(dockerfile-mode . dockerfile)
124124
(css-mode . css)
125+
(csv-mode . csv)
125126
(elm-mode . elm)
126127
(elixir-mode . elixir)
127128
(emacs-lisp-mode . elisp)
@@ -228,6 +229,7 @@ Return nil if there are no bundled patterns."
228229
('arduino '(cpp c))
229230
('astro '(html))
230231
('cpp '(c))
232+
('csv '(tsv))
231233
('hlsl '(cpp c))
232234
('typescript '(javascript))
233235
('tsx '(typescript javascript))

0 commit comments

Comments
 (0)