-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exceptions.cs
70 lines (61 loc) · 2.4 KB
/
Exceptions.cs
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
using System;
using System.Linq;
using System.Collections.Generic;
class LexerException : Exception
{
public LexerException(Position start, Position end, string err) : base(
String.Concat(new[]{String.Format("LexerException: {0}\n", err), "File ", start.fn, " in line number ", (start.ln + 1).ToString()})
){}
}
class InvalidSyntaxError : Exception
{
public InvalidSyntaxError(Position start, Position end, string err) : base(
String.Concat(new[]{String.Format("InvalidSyntaxError: {0}\n", err), "File ", start.fn, " in line number ", (start.ln + 1).ToString()})
){}
}
class ValidationError : Exception
{
public ValidationError(Position start, Position end, string err) : base(
String.Concat(new[]{String.Format("ValidationError: {0}\n", err), "File ", start.fn, " in line number ", (start.ln + 1).ToString()})
){}
}
class NestedExtensionError : Exception
{
public NestedExtensionError(Position start, Position end) : base(
String.Concat(new[]{"NestedExtensionError: Nesting extensions is impossible\n", "File ", start.fn, " in line number ", (start.ln + 1).ToString()})
){}
}
class ModelError : ValidationError
{
public ModelError(HashSet<string> requiredEnv, HashSet<string> modelKeys) : base(
Position.Nothing(), Position.Nothing(),
string.Format("Required keys [{0}] are missing", string.Join(", ", requiredEnv.Except(modelKeys)))
){}
}
class CyclicExtensionError : ValidationError
{
public CyclicExtensionError(string point, IEnumerable<string> cycle) : base(
Position.Nothing(), Position.Nothing(),
string.Format("{0} is a cycle and cyclical inheritance in not allowed", string.Format("{0} -> {1}", string.Join(" -> ", extractCycle(point, cycle)), point))
){}
static private List<string> extractCycle(string point, IEnumerable<string> visiting)
{
var cycle = new List<string>();
var found = false;
foreach(var vertex in visiting)
{
if(found) cycle.Add(vertex);
else if(point == vertex) {
found = true;
cycle.Add(vertex);
}
}
return cycle;
}
}
class RuntimeError : Exception
{
public RuntimeError(Position start, Position end, string err) : base(
String.Concat(new[]{String.Format("RuntimeError: {0}\n", err), "File ", start.fn, " in line number ", (start.ln + 1).ToString()})
){}
}