-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathLambdaExpressions.mc4
More file actions
69 lines (57 loc) · 2.02 KB
/
Copy pathLambdaExpressions.mc4
File metadata and controls
69 lines (57 loc) · 2.02 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
// (c) https://github.com/MontiCore/monticore
package de.monticore.expressions;
/* This is a MontiCore stable grammar.
* Adaptations -- if any -- are conservative. */
import de.monticore.expressions.*;
import de.monticore.symbols.*;
import de.monticore.types.*;
component grammar LambdaExpressions
extends BasicSymbols,
MCBasicTypes,
ExpressionsBasis {
/**
* This grammar defines lambda expressions, e.g.
* (int x, int y) -> x * y, () -> 5, x -> x * 2
*
* Not part of this grammar are Java-like lambdas with codeblocks, e.g.
* (int x) -> {int y = x + 2; return y;}
*
* The grammar has the extension point LambdaBody which can be used to
* allow different kinds of lambda bodies, e.g. codeblocks.
*
* There are also other kinds of expressions defined in the
* grammars mentioned below. These expression definitions can safely be
* composed if desired.
*
* This grammar is part of a hierarchy of expressions, which can be found
* under
* https://github.com/MontiCore/monticore/blob/dev/monticore-grammar/
* src/main/grammars/de/monticore/expressions/Expressions.md
*
*/
/*=================================================================*/
/**
* LambdaParameters have optional explicit typing.
* However, not setting the type explicitly requires
* some sort of type inference to be present.
*/
LambdaParameter implements Variable = MCType? Name;
LambdaParameters =
LambdaParameter
| parenthesis:"(" (LambdaParameter || ",")* ")"
;
/**
* Extension point that can be used to allow different bodies for
* lambda statements, e.g codeblocks.
*/
interface LambdaBody;
astrule LambdaBody =
type: de.monticore.types.check.SymTypeExpression ;
LambdaExpressionBody implements LambdaBody = Expression;
scope (shadowing non_exporting ordered) LambdaExpression
implements Expression <50> =
<rightassoc>
LambdaParameters "->"
LambdaBody
;
}