Repository navigation
Expand file tree
/
Copy pathMCFunctionTypes.mc4
More file actions
69 lines (61 loc) · 2 KB
/
Copy pathMCFunctionTypes.mc4
File metadata and controls
69 lines (61 loc) · 2 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.types;
/* This is a MontiCore stable grammar.
* Adaptations -- if any -- are conservative. */
import de.monticore.types.*;
/**
* This grammar introduces function types
* such as int -> int, (String -> int) -> void, (boolean, int) -> int
*
* Function types are useful when functions shall be passed around
* as arguments or stored in a data structure (for later use).
* This is typically the case in higher-order functional programming
* languages, such as Haskell.
* The syntax here is actually inspired by Haskell.
*
* The language developer may choose the subset of types
* of interest and combine these with the appropriate expressions
*
* This modularity of types and associated expressions greatly eases
* the reuse of type structures in languages similar to Java / Haskell
*
* This grammar is part of a hierarchy of types, which can be found
* under
* https://github.com/MontiCore/monticore/blob/dev/monticore-grammar/
* src/main/grammars/de/monticore/types/Types.md
*
*/
component grammar MCFunctionTypes
extends MCBasicTypes {
/** MCFunctionParTypes describes the parameters in brackets, i.e.
* (int,long), (int), etc. but also allows ellipses at the end
* (int,long,Person...)
*/
MCFunctionParTypes =
"(" (
(MCType || ",")+
(isElliptic:"...")?
)? ")"
;
/** ASTMCFunctionTypesType represents function types.
*
* Any number of arguments is possible.
* A -> B -> C parses as usual as A -> (B -> C)
*/
MCFunctionType implements MCType <80> =
<rightassoc>
MCFunctionParTypes "->"
MCReturnType
;
/** ASTMCUnaryFunctionType represents function types
* that have exactly one parameter without any parentheses.
*
* This non-terminal is separate from MCFunctionType
* to avoid parsing issues due to mutual left recursion.
*/
MCUnaryFunctionType implements MCType <60> =
<rightassoc>
MCType "->"
MCReturnType
;
}