Skip to content

Poosl.sdf3

pdmosses/metaborg-poosl/org.metaborg.lang.poosl/syntax/Poosl.sdf3

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
module Poosl

imports
    Common
    ExprStat

context-free start-symbols
    Poosl

context-free sorts
    Poosl
    ImportList
    Import
    
    Annotation
    OptAnnotationArgs
    Class
    ClassList
    DataMethodList
    DataMethod
    
    NativeClause
    
    
    
    
    DeclarationOptComma
    
    
    
    
    ProcessMethodList
    ProcessMethod
    
    Port
    MessageSignatureList
    MessageSignature
    
    
    Instance
    OptInstanceParameterList
    InstanceParameter
    
    Channel
    PortInstance
    PortInstanceList
    

context-free syntax
    Poosl.Poosl = [
        [ImportList]
        [ClassList]
    ]

    ImportList.ImportList =                             [[{Import "\n"}*]]
    ClassList.ClassList =                               [[{Class "\n\n"}*]]

    // === Multiple files =======

    Import.Import =                                     [import [STRING]]
    Import.ImportLib =                                  [importlib [STRING]]

    // === Annotation =======

    .AnnotationList =                     Annotation*
    Annotation.Annotation =                             [@[ID][OptAnnotationArgs]]
    OptAnnotationArgs.AnnotationArgs =                  [([{ExpressionConstant ", "}*])]
    OptAnnotationArgs.NoAnnotationArgs =                []

    // === Data Class =======

    Class.DataClass = [
        [AnnotationList]
        [NativeClause] data class [ID] [ExtendsClause]
        variables
            [DeclarationOptCommaList]
        methods
            [DataMethodList]
    ]

    DataMethodList.DataMethodList =                     [[{DataMethod "\n\n"}*]]
    DataMethod.DataMethodNamed = [
        [AnnotationList]
        [ID][OptParameterList] : [ID] [OptLocalVariableList]
            [Expression]
    ]
    DataMethod.DataMethodUnary = [
        [AnnotationList]
        [UnaryOperator][OptEmptyList] : [ID] [OptLocalVariableList]
            [Expression]
    ]
    DataMethod.DataMethodBinary = [
        [AnnotationList]
        [OperatorBinary]([Declaration]) : [ID] [OptLocalVariableList]
            [Expression]
    ]
    DataMethod.DataMethodNamedNative = [
        native [ID][OptParameterList] : [ID]
    ]
    DataMethod.DataMethodUnaryNative = [
        native [UnaryOperator][OptEmptyList] : [ID]
    ]
    DataMethod.DataMethodBinaryNative = [
        native [OperatorBinary]([Declaration]) : [ID]
    ]

    .NoList = []
    .EmptyList = [()]

    .OperatorBinary2 =                    BinaryOperatorLevel2
    .OperatorBinary3 =                    BinaryOperatorLevel3
    .OperatorBinary4 =                    BinaryOperatorLevel4

    NativeClause.Native =                               [native]
    NativeClause.NotNative =                            []

    .Extends =                             [extends [ID]]
    .NoExtends =                           []

    .IDList =                                     [[{ID ", "}*]]
    .Declaration =                           [[IDList] : [ID]]
    DeclarationOptComma.DeclarationWithComma =          [[IDList] : [ID],]
    DeclarationOptComma.DeclarationWithoutComma =       [[IDList] : [ID]]

    .DeclarationOptCommaList =   [[{DeclarationOptComma "\n"}*]] 
    .ParameterList =                       [([{Declaration ", "}*])]
    .Parameters =                       [([{Declaration ", "}*])]
    .NoParameters =                     []
    .LocalVariables =               [| [{Declaration ", "}*] |]
    .NoLocalVariables =             []

    // === Process Class =======

    Class.ProcessClass = [
        [AnnotationList]
        process class [ID][OptParameterList] [ExtendsClause]
        ports
            [PortList]
        messages
            [MessageSignatureList]
        variables
            [DeclarationOptCommaList]
        init
            [ProcessMethodCall]
        methods
            [ProcessMethodList]
    ]

    ProcessMethodList.ProcessMethodList =               [[{ProcessMethod "\n\n"}*]]
    ProcessMethod.ProcessMethod = [
        [AnnotationList]
        [ID][ParameterList][ParameterList] [OptLocalVariableList]
            [Statement]
    ]

    .PortList =                                 [[{Port "\n"}*]]
    Port.Port =                                         [[ID][OptionalComma]]

    MessageSignatureList.MessageSignatureList =         [[{MessageSignature "\n"}*]]
    MessageSignature.MessageReceiveSignature =          [[ID]?[ID][OptMessageParameterList][OptionalComma]] 
    MessageSignature.MessageSendSignature =             [[ID]![ID][OptMessageParameterList][OptionalComma]]

    .MessageParameters =         [([{ID ", "}*])]
    .NoMessageParameters =       []


    // === System and Cluster Class =======

    Class.System =  [
        [AnnotationList]
        system
        instances
            [InstanceList]
        channels
            [ChannelList]
    ]

    Class.ClusterClass = [
        [AnnotationList]
        cluster class [ID][OptParameterList]
        ports
            [PortList]
        instances
            [InstanceList]
        channels
            [ChannelList]
    ]

    .InstanceList =                         [[{Instance "\n"}*]]
    Instance.Instance = [
        [AnnotationList]
        [ID] : [ID][OptInstanceParameterList]
    ]

    OptInstanceParameterList.InstanceParameters =       [([{InstanceParameter ", "}*])]
    OptInstanceParameterList.NoInstanceParameters =     []

    InstanceParameter.InstanceParameter =               [[ID] := [Expression]]

    .ChannelList =                           [[{Channel "\n"}*]]
    Channel.Channel = [
        [AnnotationList]
        { [PortInstanceList] }
    ]

    PortInstanceList.PortInstanceList =                 [[{PortInstance ", "}+]]
    PortInstance.InternalPort =                         [[ID].[ID]]
    PortInstance.ExternalPort =                         ID

    // === Workarounds =======

    .Comma =                               [,]
    .NoComma =                             []

lexical syntax      // keywords
     = "import"       {reject}
     = "importlib"    {reject}

     = "data"         {reject}
     = "process"      {reject}
     = "cluster"      {reject}
     = "system"       {reject}

     = "native"       {reject}

// Note: No reserved words!
//  ID = "class"        {reject}
//  ID = "extends"      {reject}
//  ID = "variables"    {reject}
//  ID = "methods"      {reject}
//  ID = "ports"        {reject}
//  ID = "messages"     {reject}
//  ID = "init"         {reject}
//  ID = "channels"     {reject}
//  ID = "instances"    {reject}