-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanguageSpecification.ebnf
361 lines (292 loc) · 6.6 KB
/
languageSpecification.ebnf
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
using MyNamespace
namespace MyNamespaceName
{
infix func MyInfixFunction(MyTypeA myParamA, MyTypeA myParamB) -> MyReturnType
{
...
return myResult
}
protocol MyProtocolName
{
func MyFunc(MyTypeA myParameterName)
func MyFunc2(MyType myParameterName, ..MyType myParamsParameters) -> MyReturnType
}
func GenericFunction!(TypeA, TypeB)(TypeA a, TypeB b)
{
...
}
func GenericFunctionSingleArg!(TypeA)(TypeA a) -> int
{
let anonFunc : func!(TypeX, TypeY)(TypeX x, TypeY y) -> return x
anonFunc!(a, a)
}
class GenericClass(TypeA, TypeB)
{
var mutable1 : None TypeA
var mutable2 : None TypeB
Constructor(TypeA arg1, TypeB arg2)
{
mutable1 : arg1
mutable2 : arg2
var i : GenericFunctionSingleArg!(arg1)
var b : GenericFunction!(arg1, arg2)
}
}
abstract class BaseClass
{
func PrivateFoo(){}
open func OpenFoo(){}
open func OpenFoo2(){}
open func OpenFoo3(){}
abstract func AbstractFoo(){}
public abstract func AbstractFoo2(){}
protected func ProtectedFoo(){}
}
class MyDerivedClass is BaseClass, MyProtocolName
{
func MyFunc(MyTypeA myParameterName){}
func MyFunc2(MyType myParameterName, ..MyType myParamsParameters) -> MyReturnType
{
return new MyReturnType(localA)
}
override func OpenFoo(){}
open override func OpenFoo2(){}
override func OpenFoo3(){}
override func AbstractFoo(){}
public override func AbstractFoo2(){ProtectedFoo()}
}
class MyClassName is MyProtocolName
{
let myImmutableReferenceA : new myTypeA()
let myImmutableReferenceB
var myMutableReferenceC : None MyTypeA
primary Constructor(MyTypeA constructorParameterA)
{
myImmutableReferenceB : constructorParameterA
}
operator Div(MyClassName opA, MyClassName opB) -> int
{
//div operator for MyClassName
}
func MyFunc(MyTypeA myParameterName)
{
myMutableReferenceC : myParameterName MyInfixFunction myParameterName
}
func MyFunc2(MyType myParameterName, ..MyType myParamsParameters) -> MyReturnType
{
var localA : GetLength(myParamsParameters)
{
let immutableLocalScopeB : localA
if(immutableLocalScopeB is int)
{
WorkWithInt(immutableLocalScopeB)
}
else throw new Error("Expected int");
}
return new MyReturnType(localA)
}
func GetLength(MyType[] arr) -> return arr.Length(0)
func WorkWithInt(int myInt) -> myInt * 2
func LookAtMyAwesomeMatch()
{
match(1)
{
case is Int -> ...
case !0 -> ...
case in 1..10 -> ...
case !in 11.20 -> ...
case > 30 -> ...
else ->
{
}
}
}
func LookAtMyAwesomeFor(MyType[] arr)
{
for(var index, var item in arr)
{
}
forr(var index, var item in arr)
{
}
for(var i : 0; i < arr.Length(0); i+:1)
{
}
}
func LookAtMyFunctions(func(int, string, TypeA) functionParameter)
{
var funcA : func(int a, int b) -> return a * b
var val : funcA(1, 2)
var inferredTypedFunc : func(val, val) -> return a * b
}
func LookAtMyAwesomeIf(int paramA)
{
var a : if(paramA > 1) true
else if(paramA < 3) true
else if(paramA is int) false
else false
if(a)
{
}
else throw Error("wtf")
}
func LookVariableDeclaration()
{
var a : 1
var b : 1, c : new None!(int), d : "string"
let e : 3, f : "string"
}
var field : new None!(int)
func LookOptionalVariables(Optional!(int) integer, Optional!(string) sstring)
{
let a : integer
var c : integer * integer //Error
if(a is Some!(int))
{
//work with int, inferred from condition
}
else throw new ArgumentException("'integer' not initialized")
}
}
class PrimaryConstructorClass
{
let immutFieldFromPrimaryConstructor
primary Constructor(int val)
{
immutFieldFromPrimaryConstructor : val
}
Constructor() : this(1)
{
}
}
abstract class Optional!(T)
{
}
class Some!(T) is Optional!(T)
{
private var _some
primary Constructor(T val)
{
_some = val
}
public Get() -> return _some
public Set(T val)
{
_some = val
}
}
class None!(T) is Optional!(T)
{
}
class Empty
class NoneInt is None!(int)
class SomeGenericClass!(T1, T2)
class SomeEmptySpecifiedGenericClass!(T) is SomeGenericClass!(Empty, T) where T is MyProtocolName, this, fits Concept
{
operator Div(T, T) -> T
func Size() -> int
}, Addable!(T)
Concept Square!(T) where T : Mult!(T)
{
func Square(T val) -> return val * val
}
Concept Addable!(T)
{
operator Add(T, T) -> T
}
Concept Mult!(T)
{
operator Mult(T, T) -> T
}
impl Addable!(int) //implies imlp Addable!(T) { operator Add(int a, int b) -> return a.Add(b) }
impl Mult!(int) //implies imlp Mult!(T) { operator Mult(int a, int b) -> return a.Mult(b) }
func Func!(T)(T val) where T : Addable!(T) + Mult!(T) + DefaultConstructor!(T)
{
}
Concept Enumerable!(T)
{
func Current() -> T
func Next()
}
impl Enumerable!(int)
{
func Current() -> return this
func Next()
{
this : this + 1
}
}
extend int : Enumerable!(int)
{
func Current() -> return this
func Next()
{
this : this + 1
}
}
Enumerable!(int)
{
func Current() -> return this
func Next()
{
this : this + 1
}
}
class int : Enumerable!(int)
{
func Current() -> return this
func Next()
{
this : this + 1
}
}
impl Square!(int)
{
}
Concept DefaultConstructor!(T)
{
Constructor()
}
func Enumerable!(T).Where!(T)(func(T, bool) predicate) -> T
{
var result : new List!(T)
for(T item in this)
{
if(predicate(item))
{
result.Add(item)
}
}
return result
}
func CalcAverage()
{
var ints : new int[](1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
var doubles : new dobule[](1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.1, 11.2, 12.3)
var float : new float[](1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.1, 11.2, 12.3)
int : Addable!(int)
extend int : Addable!(int)
impl Addable!(int)
impl Divable!(int)
impl Addable!(double)
impl Divable!(double)
impl Addable!(float)
impl Divable!(float)
var avInt : ints.Average()
var avDouble : double.Average()
var avFloat : float.Average()
}
func Enumerable!(TNumber).Average() where TNumber : Addable!(TNumber) + Divable!(TNumber) + DefaultConstructor!(T)
{
return this.Sum() / this.Count()
}
func IEnumerable!(T).Sum!(T)() -> T where T fits Addable!(T) + DefaultConstructor!(T)
{
T result : new T()
for(T item in this)
{
result += item
}
return result
}
}