Skip to content

Commit 1f59def

Browse files
committed
feat: support 0.4.0 grammar
1 parent 86d2f30 commit 1f59def

File tree

6 files changed

+194
-22
lines changed

6 files changed

+194
-22
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ file in the repository for details.
203203

204204
## Changes
205205

206+
### Version 0.2.0
207+
208+
* Feature: update the grammar support for the underlying 0.4.0 release of tree-sitter-sdml.
209+
206210
### Version 0.1.9
207211

208212
* Feature: added new `sdml-mode-ctags-mode` minor mode that provides a command to

sdml-mode-cli.el

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,27 @@ to `sdml-cli-default-error-buffer-name'.
116116
117117
The boolean REFRESH-FN indicates that a refresh function should
118118
be added to the buffer with a key binding to \"g\"."
119-
(let ((output-buffer-name (or output-buffer-name sdml-mode-cli-default-output-buffer-name))
119+
(let ((is-special (null output-buffer-name))
120+
(output-buffer-name (or output-buffer-name sdml-mode-cli-default-output-buffer-name))
120121
(load-path (concat (or (getenv "SDML_PATH") "")
121122
(string-join sdml-mode-cli-load-path ":"))))
122123
(with-environment-variables (("SDML_PATH" load-path))
123124
(shell-command command
124125
output-buffer-name
125126
(or error-buffer-name sdml-mode-cli-default-error-buffer-name))
126-
(pop-to-buffer output-buffer-name)
127-
;; colorize output
128-
(ansi-color-apply-on-region (point-min) (point-max))
129-
;; make read-only
130-
(special-mode)
131-
(when refresh-fn
127+
(when is-special
128+
(pop-to-buffer output-buffer-name)
129+
;; colorize output
130+
(ansi-color-apply-on-region (point-min) (point-max))
131+
;; make read-only
132+
(special-mode)
133+
(when refresh-fn
132134
;; install refresh command
133135
(use-local-map (copy-keymap special-mode-map))
134136
(local-set-key "g" (sdml-mode-cli--make-refresh-cmd command
135137
load-path
136138
output-buffer-name
137-
error-buffer-name))))))
139+
error-buffer-name)))))))
138140

139141
(provide 'sdml-mode-cli)
140142

sdml-mode-hl.el

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"assert"
5050
"class"
5151
"datatype"
52+
"dimension"
5253
"entity"
5354
"enum"
5455
"event"
@@ -97,8 +98,12 @@
9798
(import_statement [ "[" "]" ] @punctuation.bracket)
9899

99100
(member_import name: (qualified_identifier) @type)
101+
(member_import "as" @keyword)
102+
(member_import rename: (identifier) @type)
100103

101104
(module_import name: (identifier) @module)
105+
(module_import "as" @keyword)
106+
(module_import rename: (identifier) @module)
102107

103108
;; -------------------------------------------------------------------
104109
;; Annotations and Constraints (Note property => label)
@@ -127,8 +132,6 @@
127132
(function_parameter name: (identifier) @variable.parameter)
128133
(function_parameter target: (_) @type)
129134

130-
(optional) @operator
131-
132135
(function_cardinality_expression (sequence_ordering) @keyword)
133136
(function_cardinality_expression (sequence_uniqueness) @keyword)
134137
(function_cardinality_expression [ "{" "}" ] @punctuation.bracket)
@@ -197,19 +200,22 @@
197200
(data_type_def base: (identifier_reference) @type)
198201
(data_type_def opaque: (opaque) @keyword)
199202

203+
(dimension_def name: (identifier) @type.definition)
204+
200205
(entity_def name: (identifier) @type.definition)
201206

202207
(enum_def name: (identifier) @type.definition)
203208

204-
(event_def "source" @keyword)
205-
(event_def
206-
name: (identifier) @type.definition
207-
source: (identifier_reference) @type)
209+
(event_def name: (identifier) @type.definition)
208210

209211
(structure_def name: (identifier) @type.definition)
210212

211213
(union_def name: (identifier) @type.definition)
212214

215+
(source_entity "source" @keyword entity: (identifier_reference) @type)
216+
(source_entity "with" @keyword)
217+
(source_entity member: (identifier) @variable.field)
218+
213219
;; -------------------------------------------------------------------
214220
;; RDF Definitions
215221
;; -------------------------------------------------------------------
@@ -243,13 +249,19 @@
243249

244250
(entity_identity "identity" @keyword)
245251

246-
(member_def name: (identifier) @variable.field)
247-
(member_def target: (type_reference) @type)
252+
(member_def
253+
name: (identifier) @variable.field
254+
target: (type_reference) @type)
248255

249256
(property_ref
250257
"ref" @keyword
251258
property: (identifier_reference) @variable.field)
252259

260+
(dimension_parent
261+
"parent" @keyword
262+
name: (identifier) @variable.field
263+
parent: (identifier_reference) @type)
264+
253265
(value_variant name: (identifier) @constant)
254266

255267
(type_variant (identifier_reference) @type)

sdml-mode-hydra.el

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
(require 'sdml-mode)
3+
(require 'sdml-mode-ctags)
4+
(require 'pretty-hydra)
5+
6+
(cond
7+
((featurep 'pretty-hydra)
8+
(pretty-hydra-define sdml-mode-hydra
9+
(:color blue :quit-key "q" :title "SDML")
10+
("Edit"
11+
(("t" sdml-mode-current-buffer-dependency-tree "Open dependency tree")
12+
("T" sdml-mode-current-buffer-dependency-graph "Open dependency graph")
13+
("v" sdml-mode-validate-current-buffer "Validate current buffer")
14+
("V" sdml-mode-validate-file "Validate file")
15+
("g" sdml-mode-ctags-generate "Generate ctags")
16+
("f" flycheck-list-errors "Open Flycheck errors")
17+
("n" display-line-numbers-mode "Toggle line numbers" :toggle t))
18+
"Document"
19+
(("d d" sdml-mode-document-module "Document module")
20+
("d b" sdml-mode-document-project "Document project")
21+
("d c" sdml-mode-draw-concept "Draw concept diagram")
22+
("d e" sdml-mode-draw-entities "Draw E/R diagram")
23+
("d u" sdml-mode-draw-uml "Draw UML diagram"))
24+
"Generate"
25+
(("c r" sdml-mode-generate-rdf "Generate RDF representation")
26+
("c s" sdml-mode-generate-scheme "Generate scheme representation")
27+
("c j" sdml-mode-generate-json "Generate JSON representation")
28+
("c t" sdml-mode-generate-with-tera "Generate using Tera templates"))
29+
"Debug"
30+
(("h d" tree-sitter-debug-mode "Toggle ts debug tree mode" :toggle t)
31+
("h q" tree-sitter-query-builder "Open ts query builder"))))
32+
(bind-key "C-c C-s h" 'sdml-mode-hydra/body)
33+
(bind-key "<f9> s" 'sdml-mode-hydra/body))
34+
35+
36+
;; ((featurep 'hydra) (message "plain")
37+
;; (defhydra sdml-mode-hydra (:color pink :hint nil)
38+
;; "
39+
;; ^Edit^ ^Document^ ^Tree-Sitter^
40+
;; ^^^^^^^^-----------------------------------------------------------------
41+
;; _t_: dependency tree _u_: unmark _d_: debug tree
42+
;; _T_: dependency graph _U_: unmark up _q_: query builder
43+
;; _v_: validate buffer
44+
;; _V_: validate file
45+
;; "
46+
;; ("t" sdml-mode-current-buffer-dependency-tree)
47+
;; ("T" sdml-mode-current-buffer-dependency-graph)
48+
;; ("v" sdml-mode-validate-current-buffer)
49+
;; ("V" sdml-mode-validate-file)
50+
;; ("u" nil)
51+
;; ("U" Buffer-menu-save)
52+
;; ("d" tree-sitter-debug-mode)
53+
;; ("q" tree-sitter-query-builder)))
54+
(t
55+
(message "Install 'hydra or 'pretty-hydra")))

sdml-mode-indent.el

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
function_body
4949
constant_def
5050
informal_constraint
51-
constraint_sentence))
51+
constraint_sentence
52+
source_entity
53+
dimension_parent))
5254

5355
;; If parent node is one of this and current node is not first → indent
5456
(indent-rest . ())
@@ -58,8 +60,8 @@
5860
import_statement
5961
annotation_only_body
6062
;; entity_body << this double indents.
63+
dimension_body
6164
enum_body
62-
property_body
6365
structure_body
6466
union_body
6567
type_class_body

sdml-mode.el

Lines changed: 101 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
;;; sdml-mode.el --- Major mode for SDML -*- lexical-binding: t; -*-
22

33
;; Author: Simon Johnston <[email protected]>
4-
;; Version: 0.1.9
5-
;; Package-Requires: ((emacs "28.1") (tree-sitter "0.18.0") (tree-sitter-indent "0.3"))
4+
;; Version: 0.2.0
5+
;; Package-Requires: ((emacs "28.1") (tree-sitter "0.18.0") (tree-sitter-indent "0.4"))
66
;; URL: https://github.com/johnstonskj/emacs-sdml-mode
77
;; Keywords: languages tools
88

@@ -180,7 +180,7 @@ platform-specific extension in `tree-sitter-load-suffixes'."
180180
'(sdml-mode . sdml))))
181181

182182
;; --------------------------------------------------------------------------
183-
;; Buffer Commands  Validation
183+
;; Commands  Validation
184184
;; --------------------------------------------------------------------------
185185

186186
(defconst sdml-mode-validation-error-regexp
@@ -239,7 +239,7 @@ usual."
239239

240240

241241
;; --------------------------------------------------------------------------
242-
;; Buffer Commands  Dependencies
242+
;; Commands  Dependencies
243243
;; --------------------------------------------------------------------------
244244

245245

@@ -285,6 +285,103 @@ using the key `q', and it's content may be refreshed with the key
285285
(sdml-mode-cli-run-command cmd-line "*SDML Dependencies*" nil t))))
286286

287287

288+
;; --------------------------------------------------------------------------
289+
;; Commands  Placeholders
290+
;; --------------------------------------------------------------------------
291+
292+
(defun sdml-mode-document-module ()
293+
"Generate standard documentation for module in current buffer."
294+
(interactive nil sdml-mode)
295+
(let* ((inp-file (buffer-file-name))
296+
(out-file (if (null inp-file) "-"
297+
(concat (file-name-sans-extension inp-file) ".org")))
298+
(out-buffer (if (null inp-file) "*SDML Documentation*" nil)))
299+
(let ((cmd-line (sdml-mode-cli-make-command
300+
"doc"
301+
(sdml-mode-cli-make-arg 'output-format 'org-mode)
302+
(sdml-mode-cli-make-arg 'output out-file)
303+
'current-buffer)))
304+
(when cmd-line
305+
(sdml-mode-cli-run-command cmd-line out-buffer nil t)
306+
(cond
307+
((not (null out-buffer))
308+
(with-current-buffer out-buffer
309+
(org-mode)))
310+
((not (eq out-file "-"))
311+
(find-file out-file)))))))
312+
313+
(defun sdml-mode-document-project ()
314+
"Do something."
315+
(interactive nil sdml-mode)
316+
t)
317+
318+
(defun sdml-mode-draw-concept ()
319+
"Do something."
320+
(interactive nil sdml-mode)
321+
t)
322+
323+
(defun sdml-mode-draw-entities ()
324+
"Do something."
325+
(interactive nil sdml-mode)
326+
t)
327+
328+
(defun sdml-mode-draw-uml ()
329+
"Do something."
330+
(interactive nil sdml-mode)
331+
t)
332+
333+
(defun sdml-mode-generate-rdf ()
334+
"Do something."
335+
(interactive nil sdml-mode)
336+
t)
337+
338+
(defun sdml-mode-generate-scheme ()
339+
"Generate Scheme representation of the current buffer."
340+
(interactive nil sdml-mode)
341+
(let* ((inp-file (buffer-file-name))
342+
(out-file (if (null inp-file) "-"
343+
(concat (file-name-sans-extension inp-file) ".scm")))
344+
(out-buffer (if (null inp-file) "*SDML Parse-tree Scheme*" nil)))
345+
(let ((cmd-line (sdml-mode-cli-make-command
346+
"convert"
347+
(sdml-mode-cli-make-arg 'output-format 's-expr)
348+
(sdml-mode-cli-make-arg 'output out-file)
349+
'current-buffer)))
350+
(when cmd-line
351+
(sdml-mode-cli-run-command cmd-line out-buffer nil t)
352+
(cond
353+
((and (not (null out-buffer)) (featurep 'scheme-mode))
354+
(with-current-buffer out-buffer
355+
(scheme-mode)))
356+
((not (eq out-file "-"))
357+
(find-file out-file)))))))
358+
359+
(defun sdml-mode-generate-json ()
360+
"Generate JSON representation of current buffer."
361+
(interactive nil sdml-mode)
362+
(let* ((inp-file (buffer-file-name))
363+
(out-file (if (null inp-file) "-"
364+
(concat (file-name-sans-extension inp-file) ".json")))
365+
(out-buffer (if (null inp-file) "*SDML Parse-tree JSON*" nil)))
366+
(let ((cmd-line (sdml-mode-cli-make-command
367+
"convert"
368+
(sdml-mode-cli-make-arg 'output-format 'json-pretty)
369+
(sdml-mode-cli-make-arg 'output out-file)
370+
'current-buffer)))
371+
(when cmd-line
372+
(sdml-mode-cli-run-command cmd-line out-buffer nil t)
373+
(cond
374+
((and (not (null out-buffer)) (featurep 'json-mode))
375+
(with-current-buffer out-buffer
376+
(json-mode)))
377+
((not (eq out-file "-"))
378+
(find-file out-file)))))))
379+
380+
(defun sdml-mode-generate-with-tera ()
381+
"Do something."
382+
(interactive nil sdml-mode)
383+
t)
384+
288385
;; --------------------------------------------------------------------------
289386
;; Key Bindings
290387
;; --------------------------------------------------------------------------

0 commit comments

Comments
 (0)