Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 10 commits
  • 2 files changed
  • 0 comments
  • 1 contributor
Apr 01, 2013
Pekka Enberg Upgrade to ANTLR4
Signed-off-by: Pekka Enberg <penberg@kernel.org>
d897f93
Pekka Enberg Revert "Upgrade to ANTLR4"
This reverts commit d897f93. It's not a
matter of simply bumping up the version number in Maven POM.
4673fc0
Pekka Enberg Lexer: Make VerbatimStringChar a fragment
VerbatimStringChar is not a token so turn it into a fragment.

Signed-off-by: Pekka Enberg <penberg@kernel.org>
d758fcf
Pekka Enberg Parser: First take types, expressions, and patterns
Most of the grammar is disabled but it is good enough for expressions
such as:

  let x = "hello"

Signed-off-by: Pekka Enberg <penberg@kernel.org>
4e4a783
Pekka Enberg Parser: Remove duplicate tokens
Signed-off-by: Pekka Enberg <penberg@kernel.org>
396f9e4
Pekka Enberg Parser: Types
Signed-off-by: Pekka Enberg <penberg@kernel.org>
cc10bd2
Pekka Enberg Parser: Fix type grammar rule
Signed-off-by: Pekka Enberg <penberg@kernel.org>
92dc5f6
Pekka Enberg Parser: Expression improvements
Signed-off-by: Pekka Enberg <penberg@kernel.org>
43eb5c9
Apr 02, 2013
Pekka Enberg Lexer: Fix Int32
Signed-off-by: Pekka Enberg <penberg@kernel.org>
625c6a0
Pekka Enberg AST: Constants
Signed-off-by: Pekka Enberg <penberg@kernel.org>
6af8b5a
288  src/main/antlr3/fjord/compiler/Fsharp.g
@@ -6,7 +6,9 @@
6 6
 grammar Fsharp;
7 7
 
8 8
 options {
9  
-  language = Java;
  9
+  language  = Java;
  10
+  backtrack = true;
  11
+  memoize   = true;
10 12
 }
11 13
 
12 14
 @header {
@@ -38,16 +40,24 @@ scriptFragment returns [ScriptFragment f]
38 40
  */
39 41
 
40 42
 moduleElem returns [Node n]
41  
-  : importDecl { $n = $importDecl.n; }
  43
+  : moduleFunctionOrValueDefn { $n = $moduleFunctionOrValueDefn.n; }
  44
+  | importDecl { $n = $importDecl.n; }
42 45
   | compilerDirectiveDecl { $n = $compilerDirectiveDecl.n; }
43 46
   ;
44 47
 
  48
+moduleFunctionOrValueDefn returns [Node n]
  49
+  : attributes? Let functionDefn
  50
+  | attributes? Let valueDefn
  51
+  | attributes? Let Rec? functionOrValueDefns
  52
+  | attributes? Do expr
  53
+  ;
  54
+
45 55
 importDecl returns [ImportDecl n]
46 56
   : Open longIdent { $n = new ImportDecl($longIdent.text); }
47 57
   ;
48 58
 
49 59
 compilerDirectiveDecl returns [CompilerDirectiveDecl n]
50  
-  : '#' Ident { $n = new CompilerDirectiveDecl($Ident.text); }
  60
+  : Hash Ident { $n = new CompilerDirectiveDecl($Ident.text); }
51 61
   ;
52 62
 
53 63
 moduleElems returns [ArrayList n]
@@ -55,10 +65,206 @@ moduleElems returns [ArrayList n]
55 65
     (moduleElem { $n.add($moduleElem.n); } )+
56 66
   ;
57 67
 
58  
-access:
59  
-  | 'private'
60  
-  | 'internal'
61  
-  | 'public'
  68
+access
  69
+  : Private
  70
+  | Internal
  71
+  | Public
  72
+  ;
  73
+
  74
+/*
  75
+ * A.2.2 Types and type constraints
  76
+ */
  77
+
  78
+type
  79
+  : Hash type
  80
+  | LParen type RParen
  81
+  | ( typar (ColonGreater type)?
  82
+    | longIdent ('<' types? '>')?
  83
+    )
  84
+    ( RArrow type
  85
+    | ('*' type)+
  86
+    | longIdent
  87
+    | LBrack type (',' type)* RBrack
  88
+    | typarDefns
  89
+    )?
  90
+  ;
  91
+
  92
+types
  93
+  : type (',' type)*
  94
+  ;
  95
+
  96
+typar
  97
+  : '_'
  98
+  | '\'' Ident
  99
+  | '^' Ident
  100
+  ;
  101
+
  102
+constraint
  103
+  : typar ':>' type
  104
+  | typar ':' 'null'
  105
+/*
  106
+  | staticTypars ':' '(' membersig ')'
  107
+  | typar ':' '(' 'new' ':' 'unit' '->' \''' T ')'
  108
+*/
  109
+  | typar Colon Struct
  110
+  | typar Colon 'not' Struct
  111
+  | typar Colon 'enum' '<' type '>'
  112
+  | typar Colon 'unmanaged'
  113
+  | typar Colon Delegate '<' type ',' type '>'
  114
+  ;
  115
+
  116
+typarDefn
  117
+  : attributes? typar
  118
+  ;
  119
+
  120
+typarDefns
  121
+  : '<' typarDefn (',' typarDefn)* typarConstraints? '>'
  122
+  ;
  123
+
  124
+typarConstraints
  125
+  : 'when' constraint (And constraint)*
  126
+  ;
  127
+
  128
+/*
  129
+ * A.2.3 Expressions
  130
+ */
  131
+
  132
+expr
  133
+  : ( constant
  134
+    | LParen expr RParen
  135
+    | Begin expr End
  136
+    | longIdentOrOp
  137
+    | prefixOp expr
  138
+    | New type expr
  139
+    | Lazy expr
  140
+    | Null
  141
+    | Upcast expr
  142
+    | Downcast expr
  143
+/*
  144
+    | '{' 'new baseCall' objectMembers interfaceImpls '}'
  145
+    | '{' fieldInitializers '}'
  146
+    | '{' expr 'with' fieldInitializers '}'
  147
+    | '[' expr (';' expr)* '|'
  148
+    | '[|' expr (';' expr)* '|]'
  149
+    | '[' compOrRangeExpr ']'
  150
+    | '[|' compOrRangeExpr '|]'
  151
+*/
  152
+    )
  153
+    ( Dot longIdentOrOp
  154
+    | expr
  155
+    | LParen expr RParen
  156
+    | '<' types '>'
  157
+    | infixOp expr
  158
+    | Dot '[' expr ']'
  159
+/*
  160
+    | Dot '[' sliceRange ']'
  161
+    | Dot '[' sliceRange ',' sliceRange ']'
  162
+*/
  163
+    | LArrow expr
  164
+    | (',' expr)+
  165
+/*
  166
+    | '{' compOrRangeExpr '}'
  167
+*/
  168
+    | Colon type
  169
+    | ColonGreater type
  170
+    | ColonQMark type
  171
+    | ColonQMarkGreater type
  172
+    )?
  173
+  ;
  174
+
  175
+functionOrValueDefn
  176
+  : functionDefn
  177
+  | valueDefn
  178
+  ;
  179
+
  180
+functionDefn
  181
+  : Inline? access? identOrOp typarDefns? argumentPats returnType? Equals expr
  182
+  ;
  183
+
  184
+valueDefn
  185
+  : Mutable? access? pat typarDefns? returnType? Equals expr
  186
+  ;
  187
+
  188
+returnType
  189
+  : Colon type
  190
+  ;
  191
+
  192
+functionOrValueDefns
  193
+  : functionOrValueDefn (And functionOrValueDefn)+
  194
+  ;
  195
+
  196
+argumentPats
  197
+  : atomicPat+
  198
+  ;
  199
+
  200
+objectConstruction
  201
+  : type expr
  202
+  | expr
  203
+  ;
  204
+
  205
+/*
  206
+ * A.2.4 Patterns
  207
+ */
  208
+
  209
+pat
  210
+  : constant
  211
+  | longIdent /* patParam? pat? */
  212
+  | Underscore
  213
+/*
  214
+  | pat 'as' Ident
  215
+  | pat '|' pat
  216
+  | pat '&' pat
  217
+  | pat '::' pat
  218
+  | pat ':' type
  219
+  | pat (',' pat)+
  220
+  | '(' pat ')'
  221
+  | listPat
  222
+  | arrayPat
  223
+  | recordPat
  224
+  | ':?' atomicType
  225
+  | ':?' atomicType 'as' ident
  226
+*/
  227
+  | Null
  228
+/*
  229
+  | attributes pat
  230
+*/
  231
+  ;
  232
+
  233
+atomicPat
  234
+  : constant
  235
+  | longIdent
  236
+/*
  237
+  | listPat
  238
+  | recordPat
  239
+  | arrayPat '(' pat ')'
  240
+*/
  241
+  | ColonEquals
  242
+/*
  243
+  | atomicType
  244
+*/
  245
+  | Null
  246
+  ;
  247
+
  248
+/*
  249
+ * A.2.7 Custom attributes and reflection
  250
+ */
  251
+
  252
+attribute
  253
+  : (attributeTarget Colon)? objectConstruction
  254
+  ;
  255
+
  256
+attributeSet
  257
+  : LBrackLess attribute (Semicolon attribute)* GreaterRBrack
  258
+  ;
  259
+
  260
+attributes
  261
+  : attributeSet+
  262
+  ;
  263
+
  264
+attributeTarget
  265
+  : Module
  266
+  | Type
  267
+  | Ident
62 268
   ;
63 269
 
64 270
 /*****************************************************************************
@@ -126,11 +332,11 @@ longIdent
126 332
   ;
127 333
 
128 334
 LongIdentWithDots
129  
-  : Ident ('.' Ident)+
  335
+  : Ident (Dot Ident)+
130 336
   ;
131 337
 
132 338
 longIdentOrOp
133  
-  : longIdent '.' identOrOp
  339
+  : longIdent Dot identOrOp
134 340
   | identOrOp
135 341
   ;
136 342
 
@@ -1497,6 +1703,7 @@ String
1497 1703
   : '"' StringChar* '"'
1498 1704
   ;
1499 1705
 
  1706
+fragment
1500 1707
 VerbatimStringChar
1501 1708
   : (SimpleCharChar | NonEscapeChars | NewLine | '\\' | '""')
1502 1709
   ;
@@ -1586,7 +1793,7 @@ Uint16
1586 1793
   ;
1587 1794
 
1588 1795
 Int32
1589  
-  : (Int | Xint) 'l'
  1796
+  : (Int | Xint) 'l'?
1590 1797
   ;
1591 1798
 
1592 1799
 Uint32
@@ -1630,8 +1837,8 @@ Decimal
1630 1837
 
1631 1838
 fragment
1632 1839
 Float
1633  
-  : Digit+ '.' Digit+
1634  
-  | Digit+ ( '.' Digit* )? ('e' | 'E') ('+' | '-')? Digit+
  1840
+  : Digit+ Dot Digit+
  1841
+  | Digit+ ( Dot Digit* )? ('e' | 'E') ('+' | '-')? Digit+
1635 1842
   ;
1636 1843
 
1637 1844
 /*
@@ -1640,9 +1847,9 @@ Float
1640 1847
 
1641 1848
 fragment
1642 1849
 LineDirective
1643  
-  : '#' Int
1644  
-  | '#' Int String
1645  
-  | '#' Int VerbatimString
  1850
+  : Hash Int
  1851
+  | Hash Int String
  1852
+  | Hash Int VerbatimString
1646 1853
   | '#line' Int
1647 1854
   | '#line' Int String
1648 1855
   | '#line' Int VerbatimString
@@ -1698,7 +1905,7 @@ FirstOpChar
1698 1905
   | '.'
1699 1906
   | '/'
1700 1907
   | '<'
1701  
-  | '='
  1908
+  | Equals
1702 1909
   | '>'
1703 1910
   | '@'
1704 1911
   | '^'
@@ -1772,7 +1979,7 @@ infixOp
1772 1979
   | '||'
1773 1980
   | '<' OP
1774 1981
   | '>' OP
1775  
-  | '='
  1982
+  | Equals
1776 1983
   | (~('|='))=> '|' OP
1777 1984
   | (~('&&'))=> '&' OP
1778 1985
   | '^' OP
@@ -1791,30 +1998,29 @@ infixOp
1791 1998
  * A.1.9.4 Constants
1792 1999
  */
1793 2000
 
1794  
-fragment
1795  
-Constant
1796  
-  : Sbyte
1797  
-  | Int16
1798  
-  | Int32
1799  
-  | Int64
1800  
-  | Byte
1801  
-  | Uint16
1802  
-  | Uint32
1803  
-  | Int
1804  
-  | Uint64
1805  
-  | Ieee32
1806  
-  | Ieee64
1807  
-  | Bignum
1808  
-  | Char
1809  
-  | String
1810  
-  | VerbatimString
1811  
-  | TripleQuotedString
1812  
-  | Bytearray
1813  
-  | VerbatimBytearray
1814  
-  | Bytechar
1815  
-  | 'false'
1816  
-  | 'true'
1817  
-  | '()'
  2001
+constant returns [Node n]
  2002
+  : Sbyte              { $n = new Const($Sbyte.text);              }
  2003
+  | Int16              { $n = new Const($Int16.text);              }
  2004
+  | Int32              { $n = new Const($Int32.text);              }
  2005
+  | Int64              { $n = new Const($Int64.text);              }
  2006
+  | Byte               { $n = new Const($Byte.text);               }
  2007
+  | Uint16             { $n = new Const($Uint16.text);             }
  2008
+  | Uint32             { $n = new Const($Uint32.text);             }
  2009
+  | Int                { $n = new Const($Int.text);                }
  2010
+  | Uint64             { $n = new Const($Uint64.text);             }
  2011
+  | Ieee32             { $n = new Const($Ieee32.text);             }
  2012
+  | Ieee64             { $n = new Const($Ieee64.text);             }
  2013
+  | Bignum             { $n = new Const($Bignum.text);             }
  2014
+  | Char               { $n = new Const($Char.text);               }
  2015
+  | String             { $n = new Const($String.text);             }
  2016
+  | VerbatimString     { $n = new Const($VerbatimString.text);     }
  2017
+  | TripleQuotedString { $n = new Const($TripleQuotedString.text); }
  2018
+  | Bytearray          { $n = new Const($Bytearray.text);          }
  2019
+  | VerbatimBytearray  { $n = new Const($VerbatimBytearray.text);  }
  2020
+  | Bytechar           { $n = new Const($Bytechar.text);           }
  2021
+  | False              { $n = new Const($False.text);              }
  2022
+  | True               { $n = new Const($True.text);               }
  2023
+  | '()'               { $n = new Const("()");                     }
1818 2024
 /*
1819 2025
   | Sbyte '<' MeasureLiteral '>'
1820 2026
   | Int16 '<' MeasureLiteral '>'
9  src/main/java/fjord/ast/Const.java
... ...
@@ -1,8 +1,17 @@
1 1
 package fjord.ast;
2 2
 
3 3
 public class Const implements Node {
  4
+  public Const(String value) {
  5
+    this.value = value;
  6
+  }
4 7
 
5 8
   @Override public void accept(NodeVisitor visitor) {
6 9
     visitor.visit(this);
7 10
   }
  11
+
  12
+  @Override public String toString() {
  13
+    return value;
  14
+  }
  15
+
  16
+  private final String value;
8 17
 }

No commit comments for this range

Something went wrong with that request. Please try again.