Skip to content

Commit 75d6274

Browse files
committed
feat: more work on sdml-ts-mode
Enhances new tree-sitter based major mode for SDML with enhanced features: - Modularizes code into separate components for better maintainability - Implements comprehensive font-lock rules with custom faces - Adds code folding support via treesit-fold - Improves indentation handling - Updates abbreviation table with more intuitive shortcuts Reorganizes the codebase to follow a more modular structure while adding new capabilities and improving the overall code organization and maintainability.
1 parent 8b54407 commit 75d6274

10 files changed

+1146
-680
lines changed

sdml-mode-abbrev.el

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"New module."
3333
"Module name: "
3434
> "module " str | "new_module"
35-
> " base <https://example.org/vocabulary/" str | "new_module" "> is" \n
35+
> " <https://example.org/vocabulary/" str | "new_module" "> is" \n
3636
> "" \n
3737
> " import [ dc skos rdfs xsd ]" \n
3838
> "" \n
@@ -67,11 +67,8 @@
6767
(define-skeleton sdml-mode-abbrev--new-property
6868
"New property."
6969
"Property name: "
70-
> "property " str | "NewProperty" " is" \n
71-
> " role_name → Type" \n
72-
> " " _ \n
73-
> "end" \n)
74-
70+
> "property " str | "NewProperty" "→ Type" \n)
71+
7572
(define-skeleton sdml-mode-abbrev--new-event
7673
"New event."
7774
"Event name: "
@@ -156,9 +153,9 @@
156153
;; skeletons or the original text isn't removed.
157154
(define-abbrev-table 'sdml-mode-abbrev-table
158155
'(;; Declaration - Types
159-
("mo" "" sdml-mode-abbrev--new-module)
156+
("mod" "" sdml-mode-abbrev--new-module)
160157
("dt" "" sdml-mode-abbrev--new-datatype)
161-
("en" "" sdml-mode-abbrev--new-enum)
158+
("enu" "" sdml-mode-abbrev--new-enum)
162159
("ev" "" sdml-mode-abbrev--new-event)
163160
("pr" "" sdml-mode-abbrev--new-property)
164161
("st" "" sdml-mode-abbrev--new-structure)
@@ -167,23 +164,23 @@
167164
;; Annotation - Constraints
168165
("ci" "" sdml-mode-abbrev--new-constraint)
169166
("cf" "" sdml-mode-abbrev--new-formal-constraint)
170-
("all" "" sdml-mode-abbrev--new-constraint-forall)
171-
("any" "" sdml-mode-abbrev--new-constraint-exists)
167+
("lall" "" sdml-mode-abbrev--new-constraint-forall)
168+
("lany" "" sdml-mode-abbrev--new-constraint-exists)
172169
;; Annotation - Properties
173170
("pal" "" sdml-mode-abbrev--new-ann-altlabel)
174171
("ppl" "" sdml-mode-abbrev--new-ann-preflabel)
175172
("pdf" "" sdml-mode-abbrev--new-ann-definition)
176173
("ped" "" sdml-mode-abbrev--new-ann-editorial)
177174
("pco" "" sdml-mode-abbrev--new-ann-comment)
178175
;; data types
179-
("uk" "-> unknown")
180-
("db" "boolean")
181-
("dd" "decimal")
182-
("df" "double")
183-
("dh" "binary")
184-
("di" "integer")
185-
("ds" "string")
186-
("du" "unsigned")))
176+
("dt?" "-> unknown")
177+
("dtb" "boolean")
178+
("dtd" "decimal")
179+
("dtf" "double")
180+
("dth" "binary")
181+
("dti" "integer")
182+
("dts" "string")
183+
("dtu" "unsigned")))
187184

188185

189186
(provide 'sdml-mode-abbrev)

sdml-mode-ctags.el

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@
4444
;; --------------------------------------------------------------------------
4545

4646
(defcustom sdml-mode-ctags-command "/opt/homebrew/bin/ctags"
47-
"The command path/name for Universal Ctags."
48-
:tag "U-Ctags command path"
47+
"The command path/name for universal Ctags."
48+
:tag "Universal Ctags command path"
4949
:type 'file
5050
:group 'sdml)
5151

5252

5353
(defcustom sdml-mode-ctags-output-file-name "tags"
5454
"The name of the generated tag file."
55-
:tag "ctags output file name"
55+
:tag "Ctags output file name"
5656
:type 'file
5757
:group 'sdml)
5858

sdml-mode-hl.el

Lines changed: 72 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@
7474
(module_path_root_only "::" @punctuation.separator)
7575
(module_path_relative "::" @punctuation.separator)
7676
(module_path_relative segment: (identifier) @module.special)
77-
(module_path_absolute "::" @punctuation.separator
78-
segment: (identifier) @module.special)
77+
(module_path_absolute
78+
"::" @punctuation.separator
79+
segment: (identifier) @module.special)
7980

8081
(import_statement "import" @keyword)
8182
(import_statement [ "[" "]" ] @punctuation.bracket)
@@ -90,9 +91,7 @@
9091
;; Annotations and Constraints (Note property => label)
9192
;; -------------------------------------------------------------------
9293

93-
(annotation_property
94-
"@" @label
95-
name: (identifier_reference) @label)
94+
(annotation_property "@" @label name: (identifier_reference) @label)
9695

9796
(annotation_property value: (value (identifier_reference) @type))
9897

@@ -103,8 +102,7 @@
103102

104103
(constraint_environment "with" @keyword)
105104

106-
(function_def
107-
(function_signature name: (identifier) @function.definition))
105+
(function_def (function_signature name: (identifier) @function.definition))
108106

109107
(function_signature "def" @keyword)
110108
(function_signature target: (_) @type)
@@ -113,23 +111,22 @@
113111
(function_parameter name: (identifier) @variable.parameter)
114112
(function_parameter target: (_) @type)
115113

116-
(function_cardinality_expression (sequence_ordering) @keyword)
117-
(function_cardinality_expression (sequence_uniqueness) @keyword)
118-
(function_cardinality_expression [ "{" "}" ] @punctuation.bracket)
114+
(cardinality_reference_expression (sequence_ordering) @keyword)
115+
(cardinality_reference_expression (sequence_uniqueness) @keyword)
116+
(cardinality_reference_expression [ "{" "}" ] @punctuation.bracket)
119117

120-
(function_body (function_op_by_definition) @operator)
118+
(function_body [ ":=" "" ] @operator)
121119

122120
(function_composition subject: (reserved_self) @variable.builtin)
123121
(function_composition name: (identifier) @function.call)
124-
(function_composition [ "·" "." ] @operator)
122+
(function_composition [ "." ] @operator)
125123

126124
(constraint_sentence [ "(" ")" ] @punctuation.bracket)
127125

128126
(atomic_sentence
129127
predicate: (term (identifier_reference) @function.call))
130-
131-
(actual_arguments [ "(" ")" ] @punctuation.bracket)
132-
(actual_arguments
128+
(atomic_sentence [ "(" ")" ] @punctuation.bracket)
129+
(atomic_sentence
133130
argument: (term (identifier_reference (identifier) @variable)))
134131

135132
(term (reserved_self) @variable.builtin)
@@ -141,12 +138,17 @@
141138
(quantified_sentence "," @punctuation.separator)
142139

143140
(variable (identifier) @variable)
141+
(variable range: (identifier_reference) @type)
144142

145143
(functional_term
146144
function: (term (identifier_reference) @function.call))
145+
(functional_term [ "(" ")" ] @punctuation.bracket)
146+
(functional_term
147+
argument: (term (identifier_reference (identifier) @variable)))
147148

148-
(sequence_builder [ "{" "}" ] @punctuation.bracket
149-
(set_op_builder) @punctuation.separator)
149+
(sequence_builder
150+
[ "{" "}" ] @punctuation.bracket
151+
(set_op_builder) @punctuation.separator)
150152

151153
(sequence_of_predicate_values [ "{" "}" ] @punctuation.bracket)
152154
(sequence_of_predicate_values (sequence_ordering) @keyword)
@@ -180,6 +182,34 @@
180182
[ (set_op_membership "" @operator)
181183
(set_op_membership "in" @keyword) ])
182184

185+
(set_expression_sentence
186+
[ (set_op_union "" @operator)
187+
(set_op_union "union" @keyword)
188+
(set_op_intersection "" @operator)
189+
(set_op_intersection "intersection" @keyword)
190+
(set_op_complement "" @operator)
191+
(set_op_complement "complement" @keyword)
192+
(set_op_subset "" @operator)
193+
(set_op_subset "subset" @keyword)
194+
(set_op_subset_or_equal "" @operator)
195+
(set_op_subset_or_equal "subseteq" @keyword)
196+
(set_op_supset "" @operator)
197+
(set_op_supset "supset" @keyword)
198+
(set_op_supset_or_equal "" @operator)
199+
(set_op_supset_or_equal "supseteq" @keyword)
200+
(set_op_product "" @operator)
201+
(set_op_product "product" @keyword)
202+
(set_op_membership "" @operator)
203+
(set_op_membership "in" @keyword) ])
204+
205+
(arithmetic_expression_sentence
206+
[ (math_op_multiply [ "*" "" ] @operator)
207+
(math_op_divide [ "/" "÷" ] @operator)
208+
(math_op_modulo "mod" @keyword)
209+
(math_op_modulo "%" @operator)
210+
(math_op_add "+" @operator)
211+
(math_op_subtract "-" @operator) ])
212+
183213
;; -------------------------------------------------------------------
184214
;; Types
185215
;; -------------------------------------------------------------------
@@ -198,33 +228,26 @@
198228

199229
(datatype_def_restriction [ "{" "}" ] @punctuation.bracket)
200230
(length_restriction_facet
201-
[ "length"
202-
"maxLength"
203-
"minLength" ] @property
231+
[ "length" "maxLength" "minLength" ] @property
204232
"=" @operator)
205233
(digit_restriction_facet
206-
[ "fractionDigits"
207-
"totalDigits" ] @property
234+
[ "fractionDigits" "totalDigits" ] @property
208235
"=" @operator)
209236
(value_restriction_facet
210-
[ "maxExclusive"
211-
"maxInclusive"
212-
"minExclusive"
213-
"minInclusive" ] @property
237+
[ "maxExclusive" "maxInclusive" "minExclusive" "minInclusive" ] @property
214238
"=" @operator)
215239
(tz_restriction_facet
216240
"explicitTimezone" @property
217-
"=" @operator)
218-
(pattern_restriction_facet [ "[" "]" ] @punctuation.bracket)
241+
"=" @operator
242+
(tz_restriction_value) @keyword)
219243
(pattern_restriction_facet
220244
"pattern" @property
221245
"=" @operator
222246
(quoted_string) @string)
247+
(pattern_restriction_facet [ "[" "]" ] @punctuation.bracket)
223248

224249
(kw_is_fixed) @keyword
225250

226-
(tz_restriction_value) @keyword
227-
228251
(dimension_def "dimension" @keyword name: (identifier) @type.definition)
229252

230253
(entity_def "entity" @keyword name: (identifier) @type.definition)
@@ -238,12 +261,17 @@
238261
(structure_def "structure" @keyword name: (identifier) @type.definition)
239262

240263
(union_def "union" @keyword name: (identifier) @type.definition)
241-
(from_definition_clause
242-
"from" @keyword
243-
from: (identifier_reference) @type
244-
"with" @keyword)
245-
(from_definition_clause wildcard: (_) @type.builtin)
246-
(from_definition_clause member: (identifier) @variable)
264+
265+
(from_definition_clause "from" @keyword from: (identifier_reference) @type)
266+
267+
(from_definition_with "with" @keyword)
268+
(from_definition_with wildcard: (_) @type.builtin)
269+
(from_definition_with member: (identifier) @variable)
270+
(from_definition_with [ "[" "]" ] @punctuation.bracket)
271+
272+
(from_definition_without "without" @keyword)
273+
(from_definition_without member: (identifier) @variable)
274+
(from_definition_without [ "[" "]" ] @punctuation.bracket)
247275

248276
(source_entity "source" @keyword entity: (identifier_reference) @type)
249277
(source_entity "with" @keyword)
@@ -265,12 +293,13 @@
265293
(type_class_def "class" @keyword name: (identifier) @type.definition)
266294
(type_class_def [ "(" ")" ] @punctuation.bracket)
267295

268-
(type_variable name: (identifier) @type)
269-
(type_variable (type_op_combiner) @operator)
296+
(type_parameter name: (identifier) @type.definition)
297+
(type_parameter (type_op_combiner) @operator)
270298

271-
(type_class_reference name: (identifier_reference) @type)
299+
(type_parameter_restriction class: (identifier_reference) @type)
300+
(type_parameter_restriction [ "(" ")" ] @punctuation.bracket)
272301

273-
(type_class_arguments [ "(" ")" ] @punctuation.bracket)
302+
;;(type_restriction_argument (identifier) @type.definition)
274303

275304
(method_def
276305
(function_signature name: (identifier) @method.definition))
@@ -312,9 +341,9 @@
312341
(string (quoted_string) @string)
313342
(string language: (language_tag) @property)
314343

315-
(iri) @string.special
316-
317-
(binary) @string.special
344+
[
345+
(binary)
346+
(iri) ] @string.special
318347

319348
[
320349
(rational)

0 commit comments

Comments
 (0)