]> gerrit.simantics Code Review - simantics/platform.git/blob
6821da83e7014a6d027869b8f111ed87fe103f15
[simantics/platform.git] /
1
2 /******************************************************************************
3  * Initial
4  */
5
6 initial module ;
7 initial commands ;
8 initial import ;
9 initial type ;
10 initial exp ;
11 initial equationBlock ;
12
13 module
14     = (declaration (SEMICOLON declaration)*)?                # Module
15     ;
16
17 commands 
18     = command?                                               # OneCommand
19     | commands SEMICOLON command                             # ManyCommands 
20     ;
21     
22 command
23     = statement                                              # StatementCommand
24     | import                                                 # ImportCommand
25     ;
26
27 /******************************************************************************
28  * Declarations
29  */
30  
31 declarations
32     = LBRACE (declaration (SEMICOLON declaration)*)? RBRACE  # Declarations
33     ;
34
35 declaration
36     = var (COMMA var)* HASTYPE type                          # TypeAnnotation
37     | bexp rhs                                               # ValueDefinition
38     | DATA ID+ (EQUALS constructor (BAR constructor)*)?      # DataDefinition
39     | TYPE ID+ EQUALS type                                   # TypeDefinition
40     | CLASS context? ID+ 
41       (BAR fundeps)?
42       (WHERE declarations)?                                  # ClassDefinition
43     | INSTANCE context? ID atype+ (WHERE declarations)?      # InstanceDefinition
44     | DERIVING INSTANCE context? ID atype+                   # DerivingInstanceDefinition
45     | BEGIN_STRING END_STRING                                # DocumentationString
46     | ANNOTATION_ID aexp*                                    # Annotation
47     | (INFIX | INFIXL | INFIXR) INTEGER var (COMMA var)*     # PrecedenceDefinition
48     | import                                                 # JustImport
49     | IMPORTJAVA BEGIN_STRING END_STRING WHERE declarations  # ImportJava
50     | EFFECT ID BEGIN_STRING END_STRING 
51                 BEGIN_STRING END_STRING                      # EffectDefinition
52     | (RULE | ABSTRACT_RULE) ID 
53       (EXTENDS ID (COMMA ID)*)?
54       WHERE ruleDeclarations                                 # RuleDefinition
55     | MAPPING_RELATION ID atype*                             # MappingRelationDefinition
56     | bexp FOLLOWS ruleDeclarations                          # RelationDefinition
57     ;
58
59 import
60     = (IMPORT | INCLUDE)
61       BEGIN_STRING END_STRING
62       (AS ID)?    
63       importSpec?                                            # Import
64     ;
65     
66 importSpec 
67     = LPAREN (importItem (COMMA importItem)*)? RPAREN         # ImportShowing
68     | HIDING LPAREN (importItem (COMMA importItem)*)? RPAREN  # ImportHiding
69     ;
70
71 importItem 
72     = ID                                                      # ImportValueItem
73 //    | (TYPE | DATA) ID                                        # ImportTypeItem
74 //    | CLASS ID                                                # ImportClassItem
75     ;
76     
77
78 constructor
79     = (ANNOTATION_ID aexp)* ID atype*                        # Constructor
80     | (ANNOTATION_ID aexp)* ID LBRACE
81           fieldDeclaration (COMMA fieldDeclaration)* RBRACE  # RecordConstructor
82     ;
83     
84 fieldDeclaration
85     = ID HASTYPE type                                        # FieldDescription
86     ;
87
88 rhs = EQUALS exp (WHERE statements)?                         # SimpleRhs
89     | guardedExpEq+ (WHERE statements)?                      # GuardedRhs
90     ;
91
92 guardedExpEq
93     = BAR exp (COMMA exp)* EQUALS exp                        # GuardedExpEq
94     ;
95     
96 fundep
97     = ID+ ARROW ID                                           # Fundep
98     ;
99
100 fundeps
101     = fundep (COMMA fundep)*                                 # Fundeps
102     ;
103
104 /******************************************************************************
105  * Rules
106  */
107
108 ruleDeclarations
109     = LBRACE (ruleDeclaration (SEMICOLON ruleDeclaration)*)? RBRACE  # RuleDeclarations
110     ;
111
112 ruleDeclaration
113     = query                                                  # QueryRuleDeclaration
114     | ANNOTATION_ID aexp*                                    # Annotation
115     ;
116     
117 /******************************************************************************
118  * Expressions
119  */
120  
121 exp = bexp (HASTYPE type)?                                   # LocalTypeAnnotation, shift HASTYPE, shift COLON
122     | bexp COLON ID WITH? queryBlock?                        # EntityTypeAnnotation, shift LBRACE, shift WITH
123     ;
124
125 bexp 
126     =  MINUS? lexp (symbol lexp)*                            # Binary, shift MINUS, shift SYMBOL,
127                                                                shift LESS, shift GREATER, shift SEPARATED_DOT,
128                                                                shift ESCAPED_ID
129     ;
130
131 lexp 
132     = faexp+                                                 # Apply, shift ID, shift LAMBDA,
133                                                                shift LET, shift INTEGER, shift BEGIN_STRING,
134                                                                shift IF, shift MATCH, shift DO,
135                                                                shift MDO, shift ENFORCE, shift BLANK,
136                                                                shift FLOAT, shift LPAREN, shift LBRACKET,
137                                                                shift ESCAPED_SYMBOL, shift CHAR, shift LBRACE,
138                                                                shift WHEN, shift ATTACHED_HASH,
139                                                                shift SELECT, shift SELECT_FIRST, shift SELECT_DISTINCT,
140                                                                shift TRANSFORMATION, shift EQ
141     ; 
142
143 faexp
144     = aexp ((ATTACHED_DOT | ATTACHED_HASH) accessor)*        # FieldAccess, shift ATTACHED_DOT, shift ATTACHED_HASH
145     ;
146
147 accessor
148     = ID                                                     # IdAccessor
149     | BEGIN_STRING END_STRING                                # StringAccessor
150     | LPAREN exp RPAREN                                      # ExpAccessor
151     ;
152
153 aexp 
154     = LAMBDA aexp+ ARROW exp                                 # Lambda, shift HASTYPE
155     | LET statements IN exp                                  # Let, shift HASTYPE
156     | IF exp THEN exp ELSE exp                               # If, shift HASTYPE
157     | MATCH exp WITH
158       LBRACE case (SEMICOLON case)* RBRACE                   # Match
159     | (DO | MDO) statements                                  # Do
160     | (SELECT | SELECT_FIRST | SELECT_DISTINCT) 
161       exp WHERE queryBlock                                   # Select
162     | ENFORCE queryBlock                                     # Enforce
163     | WHEN queryBlock SEMICOLON exp                          # When
164     | var                                                    # Var
165     | ATTACHED_HASH ID                                       # HashedId
166     | BLANK                                                  # Blank
167     | INTEGER                                                # Integer
168     | FLOAT                                                  # Float
169     | stringLiteral                                          # String
170     | CHAR                                                   # Char
171     | LPAREN (exp (COMMA exp)*)? RPAREN                      # Tuple
172     | LPAREN symbolWithoutMinus lexp RPAREN                  # RightSection
173     | LPAREN lexp symbol RPAREN                              # LeftSection
174     | LBRACKET (exp (COMMA exp)*)? RBRACKET                  # ListLiteral
175     | LBRACKET exp DOTDOT exp RBRACKET                       # Range
176     | LBRACKET exp BAR 
177       listQualifier (COMMA listQualifier)* RBRACKET          # ListComprehension
178     | ID AT aexp                                             # As
179     | ID LBRACE (field (COMMA field)*)? RBRACE               # Record
180     | TRANSFORMATION ID WHERE queryBlock                     # Transformation
181     | EQ LBRACE equationBlock RBRACE                         # Eq
182     ;
183     
184 stringLiteral
185     = BEGIN_STRING (SUSPEND_STRING exp CONTINUE_STRING)* 
186       END_STRING                                             # StringLiteral
187     ;
188
189 statements
190     = LBRACE statement (SEMICOLON statement)* RBRACE         # Statements
191     ;
192
193 statement
194     = exp                                                    # GuardStatement
195     | exp rhs                                                # LetStatement
196     | exp BINDS exp                                          # BindStatement
197     | exp FOLLOWS queryBlock                                 # RuleStatement
198     ;
199
200 listQualifier
201     = exp                                                    # GuardQualifier
202     | exp EQUALS exp                                         # LetQualifier
203     | exp BINDS exp                                          # BindQualifier
204     | THEN exp (BY exp)?                                     # ThenQualifier
205     ;
206     
207 case
208     = exp caseRhs                                            # Case
209     ;
210
211 caseRhs 
212     = ARROW exp (WHERE statements)?                          # SimpleCaseRhs
213     | guardedExpArrow+ (WHERE statements)?                   # GuardedCaseRhs
214     ;
215
216 guardedExpArrow
217     = BAR exp (COMMA exp)* ARROW exp                         # GuardedExpArrow
218     ;
219
220 field
221     = ID EQUALS exp                                          # Field
222     | ID                                                     # FieldShorthand
223     ;
224
225 /******************************************************************************
226  * Queries
227  */
228
229 queryBlock 
230     = LBRACE (query (SEMICOLON query)*)? RBRACE              # QueryBlock
231     ;
232
233 query
234     = exp                                                    # GuardQuery, shift BINDS, shift EQUALS
235     | exp EQUALS exp                                         # EqualsQuery
236     | exp BINDS exp                                          # BindQuery
237     | QUERY_OP queryBlock                                    # CompositeQuery
238     ;
239
240 /******************************************************************************
241  * Equations
242  */
243  
244 equationBlock
245     = (equation (SEMICOLON equation)*)?                      # EquationBlock
246     ;
247     
248 equation
249     = exp                                                    # GuardEquation
250     | exp EQUALS exp                                         # BasicEquation
251     ;
252  
253 /******************************************************************************
254  * Types
255  */
256
257 context
258     = LPAREN type (COMMA type)* RPAREN IMPLIES               # Context
259     ;
260
261 type 
262     = etype ((ARROW | IMPLIES) etype)*                       # Arrow, shift ARROW, shift IMPLIES
263     ;
264
265 etype
266     = LESS ID (COMMA ID)* GREATER btype                      # Effect
267     | btype                                                  # JustEtype
268     | FORALL ID+ (SEPARATED_DOT | ATTACHED_DOT) type         # ForAll
269     ;
270
271 btype 
272     = atype+                                                 # ApplyType, shift ID, shift LPAREN,
273                                                                shift LBRACKET
274     ;
275
276 atype
277     = ID                                                     # TypeVar
278     | LPAREN (type (COMMA type)*)? RPAREN                    # TupleType
279     | LBRACKET type RBRACKET                                 # ListType
280     | LBRACKET RBRACKET                                      # ListTypeConstructor
281     | LPAREN COMMA+ RPAREN                                   # TupleTypeConstructor
282     ;
283
284 /******************************************************************************
285  * Variables and symbols
286  */
287
288 var = ID                                                     # VarId
289     | ESCAPED_SYMBOL                                         # EscapedSymbol
290     | LPAREN COMMA+ RPAREN                                   # TupleConstructor
291     ;
292
293 symbol
294     = SYMBOL                                                 # Symbol
295     | ESCAPED_ID                                             # EscapedId
296     | MINUS                                                  # Minus
297     | LESS                                                   # Less
298     | GREATER                                                # Greater
299     | SEPARATED_DOT                                          # Dot
300     ;
301     
302 symbolWithoutMinus
303     = SYMBOL                                                 # Symbol
304     | ESCAPED_ID                                             # EscapedId
305     | LESS                                                   # Less
306     | GREATER                                                # Greater
307     | SEPARATED_DOT                                          # Dot
308     ;
309
310 /******************************************************************************
311  * Auxiliary tokens
312  */
313 dummy = COMMENT EOL ;