This repository has been archived by the owner on Oct 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
usyntaxcheckingerrors.pas
121 lines (96 loc) · 3.83 KB
/
usyntaxcheckingerrors.pas
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
unit uSyntaxCheckingErrors;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, uTokens;
type
ESyntaxError = class(Exception);
EStopException = class(Exception); //Used as a way to stop the checker... ugly as hell, I know.
type TSyntaxErrorType = (eExpected, //Expected X but found Y.
eUnknown // ttUnknown token found.
);
procedure Error_Expected(Expected: TTokenTypeSet; const Found: TToken);
procedure Error_Expected(Expected: TKeywordTypeSet; const Found: TToken);
procedure Error_Expected(Expected: TCommandTypeSet; const Found: TToken);
procedure Error_Expected(Expected: TSymbolTypeSet; const Found: TToken);
procedure Error_Expected(Expected: TTokenType; const Found: TToken);
procedure Error_Expected(Expected: TKeywordType; const Found: TToken);
procedure Error_Expected(Expected: TCommandType; const Found: TToken);
procedure Error_Expected(Expected: TSymbolType; const Found: TToken);
procedure Error_Expected(const Expected: string; const Found: TToken);
implementation
function GetTokenName(const Token: TToken): string;
begin
case Token.TokenType of
ttSymbol: Result := '"' + SymbolTypeNames[Token.SymbolType] + '"';
ttKeyword: Result := GetKeywordTypeName(Token.KeywordType);
ttCommand: Result := GetCommandTypeName(Token.CommandType);
else
Result := TokenTypeNames[Token.TokenType];
end;
end;
procedure Error_Expected(Expected: TTokenTypeSet; const Found: TToken);
var
Str: string;
TT: TTokenType;
begin
Str := '';
for TT in Expected do
Str := Str + TokenTypeNames[TT] + ', ';
SetLength(Str, Length(Str) - 2);
raise ESyntaxError.Create('Error. Expected [' + Str + '], got ' + GetTokenName(Found) + ' instead.');
end;
procedure Error_Expected(Expected: TKeywordTypeSet; const Found: TToken);
var
Str: string;
KT: TKeywordType;
begin
Str := '';
for KT in Expected do
Str := Str + GetKeywordTypeName(KT) + ', ';
SetLength(Str, Length(Str) - 2);
raise ESyntaxError.Create('Error. Expected [' + Str + '], got ' + GetTokenName(Found) + ' instead.');
end;
procedure Error_Expected(Expected: TCommandTypeSet; const Found: TToken);
var
Str: string;
CT: TCommandType;
begin
Str := '';
for CT in Expected do
Str := Str + GetCommandTypeName(CT) + ', ';
SetLength(Str, Length(Str) - 2);
raise ESyntaxError.Create('Error. Expected [' + Str + '], got ' + GetTokenName(Found) + ' instead.');
end;
procedure Error_Expected(Expected: TSymbolTypeSet; const Found: TToken);
var
Str: string;
ST: TSymbolType;
begin
Str := '';
for ST in Expected do
Str := Str + '"' +SymbolTypeNames[ST] + '", ';
SetLength(Str, Length(Str) - 2);
raise ESyntaxError.Create('Error. Expected [' + Str + '], got ' + GetTokenName(Found) + ' instead.');
end;
procedure Error_Expected(Expected: TTokenType; const Found: TToken);
begin
raise ESyntaxError.Create('Error. Expected ' + TokenTypeNames[Expected] + ', got ' + GetTokenName(Found) + ' instead.');
end;
procedure Error_Expected(Expected: TKeywordType; const Found: TToken);
begin
raise ESyntaxError.Create('Error. Expected ' + GetKeywordTypeName(Expected) + ', got ' + GetTokenName(Found) + ' instead.');
end;
procedure Error_Expected(Expected: TCommandType; const Found: TToken);
begin
raise ESyntaxError.Create('Error. Expected ' + GetCommandTypeName(Expected) + ', got ' + GetTokenName(Found) + ' instead.');
end;
procedure Error_Expected(Expected: TSymbolType; const Found: TToken);
begin
raise ESyntaxError.Create('Error. Expected "' + SymbolTypeNames[Expected] + '", got ' + GetTokenName(Found) + ' instead.');
end;
procedure Error_Expected(const Expected: string; const Found: TToken);
begin
raise ESyntaxError.Create('Error. Expected ' + Expected + ', got ' + GetTokenName(Found) + ' instead.');
end;
end.