summaryrefslogtreecommitdiff
path: root/src/Transfer/Core/Core.cf
blob: c68a5502ec58a29bc3db9b2e404b1549dd58fcca (plain)
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
-- This is a subset of the front-end language

entrypoints Module, Exp ;

comment "--" ;
comment "{-" "-}" ;

Module. Module ::= [Decl] ;
separator Decl ";" ;

DataDecl.  Decl ::= "data" CIdent ":" Exp "where" "{" [ConsDecl] "}" ;
TypeDecl.  Decl ::= CIdent ":" Exp ;
ValueDecl. Decl ::= CIdent "=" Exp ;

ConsDecl. ConsDecl ::= CIdent ":" Exp ;
separator ConsDecl ";" ;

separator Pattern "";

-- Constructor patterns.
PCons.     Pattern ::= "(" CIdent [Pattern] ")" ;

-- Variable patterns. Note that in the core language,
-- constructor patterns must have parantheses.
PVar.      Pattern ::= PatternVariable ;
-- Record patterns.
PRec.      Pattern ::= "rec" "{" [FieldPattern] "}";
-- Patterns matching the constant Type.
PType.     Pattern ::= "Type" ;
-- String literal patterns.
PStr.      Pattern ::= String ;
-- Integer literal patterns.
PInt.      Pattern ::= Integer ;

FieldPattern. FieldPattern ::= CIdent "=" Pattern ;
separator FieldPattern ";" ;

-- Variable patterns
PVVar. PatternVariable  ::= CIdent ;
-- Wild card patterns
PVWild. PatternVariable ::= "_" ;

-- Let expressions.
ELet.      Exp  ::= "let" "{" [LetDef] "}" "in" Exp ;
LetDef.    LetDef ::= CIdent ":" Exp "=" Exp ;
separator LetDef ";" ;

-- Case expressions.
ECase.     Exp  ::= "case" Exp "of" "{" [Case] "}" ;

-- Lambda abstractions.
EAbs.      Exp2 ::= "\\" PatternVariable "->" Exp ;
-- Function types.
EPi.       Exp2 ::= "(" PatternVariable ":" Exp ")" "->" Exp ;

-- Function application.
EApp.      Exp3 ::= Exp3 Exp4 ;

-- Record field projection.
EProj.     Exp4 ::= Exp4 "." CIdent ;

-- Record types.
ERecType.  Exp5 ::= "sig" "{" [FieldType] "}" ;
FieldType. FieldType  ::= CIdent ":" Exp ;
separator FieldType ";" ;

-- Record expressions.
ERec.      Exp5 ::= "rec" "{" [FieldValue] "}" ;
FieldValue.FieldValue ::= CIdent "=" Exp ;
separator FieldValue ";" ;


-- Functions, constructors and local variables.
EVar.      Exp5 ::= CIdent ;
-- The constant Type.
EType.     Exp5 ::= "Type" ;
-- String literal expressions.
EStr.      Exp5 ::= String ;
-- Integer literal expressions.
EInt.      Exp5 ::= Integer ;
-- Meta variables
EMeta.     Exp5 ::= TMeta ;

token TMeta ('?' digit+) ;

coercions Exp 5 ;


Case. Case ::= Pattern "->" Exp ;
separator Case ";" ;


-- Identifiers in core can start with underscore to allow
-- generating unique identifiers easily.
token CIdent ((letter | '_') (letter | digit | '_' | '\'')*) ;