rumoca 0.7.28

Modelica compiler written in RUST
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
//! MLS §2.3 Identifiers, Names, and Keywords
//!
//! Tests for:
//! - §2.3.1: Identifiers (IDENT and Q-IDENT)
//! - §2.3.2: Names (dot-separated identifiers)
//! - §2.3.3: Modelica Keywords
//!
//! Reference: https://specification.modelica.org/master/lexicalstructure.html

use crate::spec::{expect_parse_failure, expect_parse_success};

// ============================================================================
// §2.3.1 IDENTIFIERS
// ============================================================================

/// MLS §2.3.1: Identifiers
mod section_2_3_1_identifiers {
    use super::*;

    // -------------------------------------------------------------------------
    // Basic IDENT rules
    // -------------------------------------------------------------------------

    #[test]
    fn mls_2_3_1_ident_letter_start() {
        expect_parse_success("model Abc Real x; end Abc;");
    }

    #[test]
    fn mls_2_3_1_ident_lowercase_start() {
        expect_parse_success("model abc Real x; end abc;");
    }

    #[test]
    fn mls_2_3_1_ident_underscore_start() {
        expect_parse_success("model _Test Real _x; end _Test;");
    }

    #[test]
    fn mls_2_3_1_ident_with_digits() {
        expect_parse_success("model Test123 Real x1y2z3; end Test123;");
    }

    #[test]
    fn mls_2_3_1_ident_mixed_case() {
        expect_parse_success("model CamelCase Real mixedCase; end CamelCase;");
    }

    #[test]
    fn mls_2_3_1_ident_all_underscores() {
        expect_parse_success("model Test Real ___; end Test;");
    }

    #[test]
    fn mls_2_3_1_ident_underscore_middle() {
        expect_parse_success("model Test Real my_variable; end Test;");
    }

    #[test]
    fn mls_2_3_1_ident_underscore_end() {
        expect_parse_success("model Test Real x_; end Test;");
    }

    #[test]
    fn mls_2_3_1_ident_single_letter() {
        expect_parse_success("model T Real x; end T;");
    }

    #[test]
    fn mls_2_3_1_ident_single_underscore() {
        expect_parse_success("model Test Real _; end Test;");
    }

    #[test]
    fn mls_2_3_1_ident_long_name() {
        expect_parse_success(
            "model VeryLongModelNameThatIsStillValid Real anotherLongVariableName; end VeryLongModelNameThatIsStillValid;",
        );
    }

    #[test]
    fn mls_2_3_1_ident_all_letters() {
        expect_parse_success(
            "model ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz Real x; end ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz;",
        );
    }

    // Cannot start with digit
    #[test]
    fn mls_2_3_1_ident_digit_start_invalid() {
        expect_parse_failure("model 1Test Real x; end 1Test;");
    }

    #[test]
    fn mls_2_3_1_ident_digit_start_var_invalid() {
        expect_parse_failure("model Test Real 1x; end Test;");
    }

    // -------------------------------------------------------------------------
    // Q-IDENT (quoted identifiers)
    // -------------------------------------------------------------------------

    #[test]
    fn mls_2_3_1_qident_with_dot() {
        expect_parse_success("model Test Real 'a.b'; end Test;");
    }

    #[test]
    fn mls_2_3_1_qident_with_space() {
        expect_parse_success("model Test Real 'my variable'; end Test;");
    }

    #[test]
    fn mls_2_3_1_qident_with_dash() {
        expect_parse_success("model Test Real 'x-y'; end Test;");
    }

    #[test]
    fn mls_2_3_1_qident_with_plus() {
        expect_parse_success("model Test Real 'x+y'; end Test;");
    }

    #[test]
    fn mls_2_3_1_qident_with_slash() {
        expect_parse_success("model Test Real 'x/y'; end Test;");
    }

    #[test]
    fn mls_2_3_1_qident_with_colon() {
        expect_parse_success("model Test Real 'a:b'; end Test;");
    }

    #[test]
    fn mls_2_3_1_qident_starts_with_digit() {
        expect_parse_success("model Test Real '123abc'; end Test;");
    }

    #[test]
    fn mls_2_3_1_qident_keyword_inside() {
        expect_parse_success("model Test Real 'model'; end Test;");
    }

    #[test]
    fn mls_2_3_1_qident_special_chars() {
        expect_parse_success("model Test Real 'x@#$%'; end Test;");
    }

    #[test]
    fn mls_2_3_1_qident_parentheses() {
        expect_parse_success("model Test Real 'f(x)'; end Test;");
    }

    #[test]
    fn mls_2_3_1_qident_brackets() {
        expect_parse_success("model Test Real 'a[1]'; end Test;");
    }

    /// TODO: Unicode in quoted identifiers not yet supported
    #[test]
    #[ignore = "Unicode in quoted identifiers not yet supported"]
    fn mls_2_3_1_qident_unicode() {
        expect_parse_success("model Test Real 'αβγ'; end Test;");
    }

    /// TODO: Unicode in quoted identifiers not yet supported
    #[test]
    #[ignore = "Unicode in quoted identifiers not yet supported"]
    fn mls_2_3_1_qident_unicode_symbols() {
        expect_parse_success("model Test Real 'Δx'; end Test;");
    }
}

// ============================================================================
// §2.3.2 NAMES
// ============================================================================

/// MLS §2.3.2: Names (dot-separated identifiers)
mod section_2_3_2_names {
    use super::*;

    #[test]
    fn mls_2_3_2_simple_name() {
        expect_parse_success("model Test Real x; end Test;");
    }

    #[test]
    fn mls_2_3_2_qualified_name_in_package() {
        expect_parse_success(
            r#"
            package Pkg
                model M Real x; end M;
            end Pkg;
            "#,
        );
    }

    #[test]
    fn mls_2_3_2_name_with_global_prefix() {
        expect_parse_success(
            r#"
            model Test
                .Modelica.Constants.pi x;
            end Test;
            "#,
        );
    }

    #[test]
    fn mls_2_3_2_nested_packages() {
        expect_parse_success(
            r#"
            package A
                package B
                    package C
                        model M Real x; end M;
                    end C;
                end B;
            end A;
            "#,
        );
    }

    #[test]
    fn mls_2_3_2_qualified_type_reference() {
        expect_parse_success(
            r#"
            package Pkg
                type MyReal = Real;
            end Pkg;
            model Test
                Pkg.MyReal x;
            equation
                x = 1;
            end Test;
            "#,
        );
    }
}

// ============================================================================
// §2.3.3 KEYWORDS
// ============================================================================

/// MLS §2.3.3: Keywords cannot be used as identifiers
mod section_2_3_3_keywords {
    use super::*;

    // -------------------------------------------------------------------------
    // Class-related keywords
    // -------------------------------------------------------------------------

    #[test]
    fn mls_2_3_3_keyword_model() {
        expect_parse_failure("model Test Real model; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_class() {
        expect_parse_failure("model Test Real class; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_block() {
        expect_parse_failure("model Test Real block; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_connector() {
        expect_parse_failure("model Test Real connector; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_record() {
        expect_parse_failure("model Test Real record; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_type() {
        expect_parse_failure("model Test Real type; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_package() {
        expect_parse_failure("model Test Real package; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_function() {
        expect_parse_failure("model Test Real function; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_operator() {
        expect_parse_failure("model Test Real operator; end Test;");
    }

    // -------------------------------------------------------------------------
    // Section keywords
    // -------------------------------------------------------------------------

    #[test]
    fn mls_2_3_3_keyword_equation() {
        expect_parse_failure("model Test Real equation; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_algorithm() {
        expect_parse_failure("model Test Real algorithm; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_public() {
        expect_parse_failure("model Test Real public; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_protected() {
        expect_parse_failure("model Test Real protected; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_initial() {
        expect_parse_failure("model Test Real initial; end Test;");
    }

    // -------------------------------------------------------------------------
    // Variability keywords
    // -------------------------------------------------------------------------

    #[test]
    fn mls_2_3_3_keyword_parameter() {
        expect_parse_failure("model Test Real parameter; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_constant() {
        expect_parse_failure("model Test Real constant; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_discrete() {
        expect_parse_failure("model Test Real discrete; end Test;");
    }

    // -------------------------------------------------------------------------
    // Causality keywords
    // -------------------------------------------------------------------------

    #[test]
    fn mls_2_3_3_keyword_input() {
        expect_parse_failure("model Test Real input; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_output() {
        expect_parse_failure("model Test Real output; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_flow() {
        expect_parse_failure("model Test Real flow; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_stream() {
        expect_parse_failure("model Test Real stream; end Test;");
    }

    // -------------------------------------------------------------------------
    // Control flow keywords
    // -------------------------------------------------------------------------

    #[test]
    fn mls_2_3_3_keyword_if() {
        expect_parse_failure("model Test Real if; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_then() {
        expect_parse_failure("model Test Real then; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_else() {
        expect_parse_failure("model Test Real else; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_elseif() {
        expect_parse_failure("model Test Real elseif; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_for() {
        expect_parse_failure("model Test Real for; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_loop() {
        expect_parse_failure("model Test Real loop; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_while() {
        expect_parse_failure("model Test Real while; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_when() {
        expect_parse_failure("model Test Real when; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_break() {
        expect_parse_failure("model Test Real break; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_return() {
        expect_parse_failure("model Test Real return; end Test;");
    }

    // -------------------------------------------------------------------------
    // Modifier keywords
    // -------------------------------------------------------------------------

    #[test]
    fn mls_2_3_3_keyword_extends() {
        expect_parse_failure("model Test Real extends; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_partial() {
        expect_parse_failure("model Test Real partial; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_final() {
        expect_parse_failure("model Test Real final; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_replaceable() {
        expect_parse_failure("model Test Real replaceable; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_redeclare() {
        expect_parse_failure("model Test Real redeclare; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_constrainedby() {
        expect_parse_failure("model Test Real constrainedby; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_encapsulated() {
        expect_parse_failure("model Test Real encapsulated; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_each() {
        expect_parse_failure("model Test Real each; end Test;");
    }

    // -------------------------------------------------------------------------
    // Scope/hierarchy keywords
    // -------------------------------------------------------------------------

    #[test]
    fn mls_2_3_3_keyword_inner() {
        expect_parse_failure("model Test Real inner; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_outer() {
        expect_parse_failure("model Test Real outer; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_import() {
        expect_parse_failure("model Test Real import; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_within() {
        expect_parse_failure("model Test Real within; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_end() {
        expect_parse_failure("model Test Real end; end Test;");
    }

    // -------------------------------------------------------------------------
    // Logical keywords
    // -------------------------------------------------------------------------

    #[test]
    fn mls_2_3_3_keyword_and() {
        expect_parse_failure("model Test Real and; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_or() {
        expect_parse_failure("model Test Real or; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_not() {
        expect_parse_failure("model Test Real not; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_true() {
        expect_parse_failure("model Test Real true; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_false() {
        expect_parse_failure("model Test Real false; end Test;");
    }

    // -------------------------------------------------------------------------
    // Other keywords
    // -------------------------------------------------------------------------

    #[test]
    fn mls_2_3_3_keyword_connect() {
        expect_parse_failure("model Test Real connect; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_der() {
        expect_parse_failure("model Test Real der; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_external() {
        expect_parse_failure("model Test Real external; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_pure() {
        expect_parse_failure("model Test Real pure; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_impure() {
        expect_parse_failure("model Test Real impure; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_annotation() {
        expect_parse_failure("model Test Real annotation; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_in() {
        expect_parse_failure("model Test Real in; end Test;");
    }

    #[test]
    fn mls_2_3_3_keyword_enumeration() {
        expect_parse_failure("model Test Real enumeration; end Test;");
    }
}