Repository navigation
Expand file tree
/
Copy pathparser_features_demo_defaults.kerml
More file actions
89 lines (72 loc) · 2.44 KB
/
Copy pathparser_features_demo_defaults.kerml
File metadata and controls
89 lines (72 loc) · 2.44 KB
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
/*
* Parser Features Demo - Default Values
*
* Demonstrates 'default' keyword as alternative to '=' for value assignment.
* This is syntactic sugar that provides clearer intent for default values.
*/
package demo_defaults {
// The library is not implicitly visible: a bare name needs an import.
private import ScalarValues::*;
// Default keyword vs equals sign
feature comparisonExamples {
doc /* Both syntaxes are equivalent */
// Traditional assignment with =
feature timeout: Integer[1] = 30;
// Default keyword (clearer intent)
feature retryCount: Integer[1] default 3;
// Works with multiplicity
feature maxConnections: Integer[0..1] default 100;
}
// Configuration with defaults
feature systemConfig {
doc /* Configuration parameters with sensible defaults */
feature networking {
feature host: String[1] default "localhost";
feature port: Integer[1] default 8080;
feature useSSL: Boolean[1] default false;
}
feature logging {
feature level: String[1] default "INFO";
feature maxFileSize: Integer[1] default 10485760; // 10MB
feature retentionDays: Integer[1] default 7;
}
feature performance {
feature threadPoolSize: Integer[1] default 4;
feature queueCapacity: Integer[1] default 1000;
feature timeout: Real[1] default 30.0;
}
}
// Anonymous features with default (from Task 51 fix)
struct APIEndpoint {
doc /*
* Structure features with defaults.
* Note: Fully anonymous features (just multiplicity + default)
* are an edge case pattern.
*/
feature enabled: Boolean[1] default true;
feature supportedMethods: String[1..*] default "GET";
}
// Behavior parameters with defaults
behavior processRequest {
in feature url: String[1];
in feature method: String[1] default "GET";
in feature timeout: Integer[1] default 30;
in feature retries: Integer[1] default 3;
doc /* Behavior with default parameter values */
}
// Real-world example: HTTP client configuration
struct HttpClient {
feature config {
feature baseURL: String[1];
feature timeout: Real[1] default 30.0;
feature followRedirects: Boolean[1] default true;
feature maxRedirects: Integer[1] default 5;
feature userAgent: String[1] default "OpenSysML/1.0";
feature compression: Boolean[1] default true;
feature headers {
feature contentType: String[1] default "application/json";
feature accept: String[1] default "application/json";
}
}
}
}