Skip to content

Commit 0a09ef5

Browse files
committed
feat: update with latest v4 grammar
1 parent ec86793 commit 0a09ef5

File tree

2 files changed

+109
-77
lines changed

2 files changed

+109
-77
lines changed

sdml-mode-hl.el

Lines changed: 106 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -44,43 +44,17 @@
4444
;; -------------------------------------------------------------------
4545

4646
[
47-
"module"
48-
"import"
49-
"assert"
50-
"class"
51-
"datatype"
52-
"dimension"
53-
"entity"
54-
"enum"
55-
"event"
56-
"property"
57-
"rdf"
58-
"structure"
59-
"union"
6047
"is"
6148
"of"
6249
"end"
63-
] @keyword
50+
] @keyword
6451

6552
;; -------------------------------------------------------------------
6653
;; Operators
6754
;; -------------------------------------------------------------------
6855

6956
[
7057
"="
71-
":="
72-
""
73-
"¬"
74-
""
75-
""
76-
""
77-
"==>"
78-
""
79-
"<==>"
80-
""
81-
""
82-
""
83-
""
8458
"->"
8559
""
8660
"<-"
@@ -92,18 +66,25 @@
9266
;; Module & Imports (Note module => type; definition => scope)
9367
;; -------------------------------------------------------------------
9468

95-
(module name: (identifier) @module.definition)
69+
(module "module" @keyword name: (identifier) @module.definition)
9670
(module "version" @keyword)
9771

72+
(from_clause "from" @keyword)
73+
74+
(module_path_root_only "::" @punctuation.separator)
75+
(module_path_relative "::" @punctuation.separator)
76+
(module_path_relative segment: (identifier) @module.special)
77+
(module_path_absolute "::" @punctuation.separator
78+
segment: (identifier) @module.special)
79+
80+
(import_statement "import" @keyword)
9881
(import_statement [ "[" "]" ] @punctuation.bracket)
9982

10083
(member_import name: (qualified_identifier) @type)
101-
(member_import "as" @keyword)
102-
(member_import rename: (identifier) @type)
84+
(member_import "as" @keyword rename: (identifier) @type)
10385

10486
(module_import name: (identifier) @module)
105-
(module_import "as" @keyword)
106-
(module_import rename: (identifier) @module)
87+
(module_import "as" @keyword rename: (identifier) @module)
10788

10889
;; -------------------------------------------------------------------
10990
;; Annotations and Constraints (Note property => label)
@@ -115,17 +96,17 @@
11596

11697
(annotation_property value: (value (identifier_reference) @type))
11798

118-
(constraint name: (identifier) @label)
99+
(constraint "assert" @keyword name: (identifier) @label)
119100

120101
(informal_constraint (quoted_string) @embedded)
121-
(informal_constraint language: (controlled_language_tag) @property)
102+
(informal_constraint language: (controlled_language_tag) @label)
122103

123-
(constraint_environment (constraint_environment_end) @keyword)
104+
(constraint_environment "with" @keyword)
124105

125-
(environment_def "def" @keyword)
126-
(environment_def (identifier) @function.definition \. (function_def))
127-
(environment_def (identifier) @constant \. (constant_def))
106+
(function_def
107+
(function_signature name: (identifier) @function.definition))
128108

109+
(function_signature "def" @keyword)
129110
(function_signature target: (_) @type)
130111
(function_signature [ "(" ")" ] @punctuation.bracket)
131112

@@ -136,9 +117,11 @@
136117
(function_cardinality_expression (sequence_uniqueness) @keyword)
137118
(function_cardinality_expression [ "{" "}" ] @punctuation.bracket)
138119

120+
(function_body (function_op_by_definition) @operator)
121+
139122
(function_composition subject: (reserved_self) @variable.builtin)
140123
(function_composition name: (identifier) @function.call)
141-
(function_composition "." @punctuation.delimiter)
124+
(function_composition [ "·" "." ] @operator)
142125

143126
(constraint_sentence [ "(" ")" ] @punctuation.bracket)
144127

@@ -157,35 +140,45 @@
157140

158141
(quantified_sentence "," @punctuation.separator)
159142

160-
(quantified_variable source: (reserved_self) @variable.builtin)
161-
(quantified_variable name: (identifier) @variable.parameter)
162-
(quantified_variable "in" @keyword)
143+
(variable (identifier) @variable)
163144

164145
(functional_term
165146
function: (term (identifier_reference) @function.call))
166147

167148
(sequence_builder [ "{" "}" ] @punctuation.bracket
168-
"|" @punctuation.separator)
169-
170-
(named_variable_set (identifier) @variable)
171-
172-
(mapping_variable
173-
domain: (identifier) @variable range: (identifier) @variable)
174-
175-
(sequence_builder_body [ "(" ")" ] @punctuation.bracket)
149+
(set_op_builder) @punctuation.separator)
176150

151+
(sequence_of_predicate_values [ "{" "}" ] @punctuation.bracket)
152+
(sequence_of_predicate_values (sequence_ordering) @keyword)
153+
(sequence_of_predicate_values (sequence_uniqueness) @keyword)
154+
(sequence_of_predicate_values [ "[" "]" ] @punctuation.bracket)
177155
(sequence_of_predicate_values (identifier_reference) @type)
178-
(sequence_of_predicate_values [ "[" "]" ] @punctuation.bracket)
179-
180-
(negation "not" @keyword)
181-
(conjunction "and" @keyword)
182-
(disjunction "or" @keyword)
183-
(exclusive_disjunction "xor" @keyword)
184-
(implication "implies" @keyword)
185-
(biconditional "iff" @keyword)
186156

187-
(universal "forall" @keyword)
188-
(existential "exists" @keyword)
157+
(unary_boolean_sentence
158+
[ (logical_op_negation "¬" @operator)
159+
(logical_op_negation "not" @keyword) ])
160+
161+
(binary_boolean_sentence
162+
[ (logical_op_conjunction "" @operator)
163+
(logical_op_conjunction "and" @keyword)
164+
(logical_op_disjunction "" @operator)
165+
(logical_op_disjunction "or" @keyword)
166+
(logical_op_exclusive_disjunction "" @operator)
167+
(logical_op_exclusive_disjunction "xor" @keyword)
168+
(logical_op_implication [ "==>" "" ] @operator)
169+
(logical_op_implication "implies" @keyword)
170+
(logical_op_biconditional [ "<==>" "" ] @operator)
171+
(logical_op_biconditional "iff" @keyword) ])
172+
173+
(quantified_variable_binding
174+
[ (logical_quantifier_universal "" @operator)
175+
(logical_quantifier_universal "forall" @keyword)
176+
(logical_quantifier_existential "" @operator)
177+
(logical_quantifier_existential "exists" @keyword) ])
178+
179+
(quantified_variable
180+
[ (set_op_membership "" @operator)
181+
(set_op_membership "in" @keyword) ])
189182

190183
;; -------------------------------------------------------------------
191184
;; Types
@@ -196,50 +189,85 @@
196189
(unknown_type)
197190
] @type.builtin
198191

199-
(data_type_def name: (identifier) @type.definition)
192+
(data_type_def
193+
"datatype" @keyword
194+
name: (identifier) @type.definition)
200195
(data_type_def base: (identifier_reference) @type)
196+
(data_type_def base: (builtin_simple_type) @type.builtin)
201197
(data_type_def opaque: (opaque) @keyword)
202198

203-
(dimension_def name: (identifier) @type.definition)
199+
(datatype_def_restriction [ "{" "}" ] @punctuation.bracket)
200+
(length_restriction_facet
201+
[ "length"
202+
"maxLength"
203+
"minLength" ] @property
204+
"=" @operator)
205+
(digit_restriction_facet
206+
[ "fractionDigits"
207+
"totalDigits" ] @property
208+
"=" @operator)
209+
(value_restriction_facet
210+
[ "maxExclusive"
211+
"maxInclusive"
212+
"minExclusive"
213+
"minInclusive" ] @property
214+
"=" @operator)
215+
(tz_restriction_facet
216+
"explicitTimezone" @property
217+
"=" @operator)
218+
(pattern_restriction_facet [ "[" "]" ] @punctuation.bracket)
219+
(pattern_restriction_facet
220+
"pattern" @property
221+
"=" @operator
222+
(quoted_string) @string)
204223

205-
(entity_def name: (identifier) @type.definition)
224+
(kw_is_fixed) @keyword
206225

207-
(enum_def name: (identifier) @type.definition)
226+
(tz_restriction_value) @keyword
208227

209-
(event_def name: (identifier) @type.definition)
228+
(dimension_def "dimension" @keyword name: (identifier) @type.definition)
210229

211-
(structure_def name: (identifier) @type.definition)
230+
(entity_def "entity" @keyword name: (identifier) @type.definition)
212231

213-
(union_def name: (identifier) @type.definition)
232+
(enum_def "enum" @keyword name: (identifier) @type.definition)
233+
234+
(event_def "event" @keyword name: (identifier) @type.definition)
235+
236+
(property_def "property" @keyword)
237+
238+
(structure_def "structure" @keyword name: (identifier) @type.definition)
239+
240+
(union_def "union" @keyword name: (identifier) @type.definition)
214241

215242
(source_entity "source" @keyword entity: (identifier_reference) @type)
216243
(source_entity "with" @keyword)
244+
(source_entity [ "[" "]" ] @punctuation.bracket)
217245
(source_entity member: (identifier) @variable.field)
218246

219247
;; -------------------------------------------------------------------
220248
;; RDF Definitions
221249
;; -------------------------------------------------------------------
222250

223-
(rdf_def name: (identifier) @type.definition)
251+
(rdf_def "rdf" @keyword name: (identifier) @type.definition)
224252
(rdf_types "type" @keyword type: (identifier_reference) @type)
225253
(rdf_types [ "[" "]" ] @punctuation.bracket)
226254

227255
;; -------------------------------------------------------------------
228256
;; Type Classes
229257
;; -------------------------------------------------------------------
230258

231-
(type_class_def name: (identifier) @type.definition)
259+
(type_class_def "class" @keyword name: (identifier) @type.definition)
232260
(type_class_def [ "(" ")" ] @punctuation.bracket)
233261

234262
(type_variable name: (identifier) @type)
235-
(type_variable "+" @operator)
263+
(type_variable (type_op_combiner) @operator)
236264

237265
(type_class_reference name: (identifier_reference) @type)
238266

239267
(type_class_arguments [ "(" ")" ] @punctuation.bracket)
240268

241-
(method_def "def" @keyword)
242-
(method_def name: (identifier) @method.definition)
269+
(method_def
270+
(function_signature name: (identifier) @method.definition))
243271

244272
(wildcard) @type.builtin
245273

@@ -265,8 +293,7 @@
265293
(value_variant name: (identifier) @constant)
266294

267295
(type_variant (identifier_reference) @type)
268-
(type_variant rename: (identifier) @type)
269-
(type_variant "as" @keyword)
296+
(type_variant "as" @keyword rename: (identifier) @type)
270297

271298
(cardinality_expression ordering: (sequence_ordering) @keyword)
272299
(cardinality_expression uniqueness: (sequence_uniqueness) @keyword)
@@ -284,6 +311,7 @@
284311
(binary) @string.special
285312

286313
[
314+
(rational)
287315
(decimal)
288316
(double)
289317
(integer)
@@ -297,8 +325,11 @@
297325

298326
(value (identifier_reference) @type)
299327

300-
(sequence_of_values (identifier_reference) @type)
328+
(sequence_of_values [ "{" "}" ] @punctuation.bracket)
329+
(sequence_of_values (sequence_ordering) @keyword)
330+
(sequence_of_values (sequence_uniqueness) @keyword)
301331
(sequence_of_values [ "[" "]" ] @punctuation.bracket)
332+
(sequence_of_values (identifier_reference) @type)
302333

303334
;; -------------------------------------------------------------------
304335
;; Errors

sdml-mode-indent.el

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
'(;; These nodes are always indented
4646
(indent-all . (member
4747
entity_identity
48+
function_def
4849
function_body
49-
constant_def
5050
informal_constraint
5151
constraint_sentence
5252
source_entity
@@ -59,6 +59,7 @@
5959
(indent-body . (module_body
6060
import_statement
6161
annotation_only_body
62+
datatype_def_restriction
6263
;; entity_body << this double indents.
6364
dimension_body
6465
enum_body
@@ -93,7 +94,7 @@
9394
(multi-line-text . (quoted_string))
9495

9596
;; These nodes always outdent (1 shift in opposite direction)
96-
(outdent . (constraint_environment_end))))
97+
(outdent . (set_op_builder))))
9798

9899

99100
;; --------------------------------------------------------------------------

0 commit comments

Comments
 (0)