Mercurial > projects > dil
annotate trunk/src/dil/Messages.d @ 390:4d36eea1bbc9
Refactored Lexer.scan().
Illegal characters are not ignored anymore. They are reported as errors.
Added a new member 'ws' to Token. When a token is scanned the lexer sets
ws to the leading whitespace or leaves it at null when no whitespace was found.
Added Illegal to enum TOK and IllegalCharacter to enum MID.
Added localized messages for MID.IllegalCharacter.
Adapted code of cmd.Generate to make use of Token.ws.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Wed, 12 Sep 2007 21:03:41 +0200 |
parents | c4bfceab7246 |
children | 33b566df6af4 |
rev | line source |
---|---|
54 | 1 /++ |
2 Author: Aziz Köksal | |
249 | 3 License: GPL3 |
54 | 4 +/ |
326 | 5 module dil.Messages; |
327 | 6 import dil.Settings; |
309 | 7 import std.stdarg; |
54 | 8 |
309 | 9 /// Index into table of compiler messages. |
54 | 10 enum MID |
11 { | |
309 | 12 // Lexer messages: |
390
4d36eea1bbc9
Refactored Lexer.scan().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
389
diff
changeset
|
13 IllegalCharacter, |
54 | 14 InvalidUnicodeCharacter, |
15 InvalidUTF8Sequence, | |
16 // '' | |
17 UnterminatedCharacterLiteral, | |
18 EmptyCharacterLiteral, | |
19 // #line | |
20 ExpectedIdentifierSTLine, | |
388
ae154eceba65
Applied some fixes to scanning and printing #line tokens.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
21 ExpectedIntegerAfterSTLine, |
323 | 22 ExpectedFilespec, |
23 UnterminatedFilespec, | |
54 | 24 UnterminatedSpecialToken, |
25 // "" | |
26 UnterminatedString, | |
27 // x"" | |
28 NonHexCharInHexString, | |
29 OddNumberOfDigitsInHexString, | |
30 UnterminatedHexString, | |
31 // /* */ /+ +/ | |
32 UnterminatedBlockComment, | |
33 UnterminatedNestedComment, | |
34 // `` r"" | |
35 UnterminatedRawString, | |
36 UnterminatedBackQuoteString, | |
37 // \x \u \U | |
38 UndefinedEscapeSequence, | |
39 InsufficientHexDigits, | |
40 // \&[a-zA-Z][a-zA-Z0-9]+; | |
272
0bde32503976
- Added module HtmlEntities. It contains a table for converting HTML entities to Unicode characters.
aziz
parents:
249
diff
changeset
|
41 UndefinedHTMLEntity, |
54 | 42 UnterminatedHTMLEntity, |
43 InvalidBeginHTMLEntity, | |
56
63af7ddf52e1
- Started properly implementing number scanner. Added stub for real numbers.
aziz
parents:
54
diff
changeset
|
44 // integer overflows |
58 | 45 OverflowDecimalSign, |
56
63af7ddf52e1
- Started properly implementing number scanner. Added stub for real numbers.
aziz
parents:
54
diff
changeset
|
46 OverflowDecimalNumber, |
63af7ddf52e1
- Started properly implementing number scanner. Added stub for real numbers.
aziz
parents:
54
diff
changeset
|
47 OverflowHexNumber, |
63af7ddf52e1
- Started properly implementing number scanner. Added stub for real numbers.
aziz
parents:
54
diff
changeset
|
48 OverflowBinaryNumber, |
63af7ddf52e1
- Started properly implementing number scanner. Added stub for real numbers.
aziz
parents:
54
diff
changeset
|
49 OverflowOctalNumber, |
63 | 50 OverflowFloatNumber, |
51 OctalNumberHasDecimals, | |
59
3e594725899a
- Issuing error when no digits were found in hex and binary numbers.
aziz
parents:
58
diff
changeset
|
52 NoDigitsInHexNumber, |
3e594725899a
- Issuing error when no digits were found in hex and binary numbers.
aziz
parents:
58
diff
changeset
|
53 NoDigitsInBinNumber, |
62
96af5653acef
- Fixed loop of hex number scanner. Moved checks under the switch block.
aziz
parents:
59
diff
changeset
|
54 HexFloatExponentRequired, |
389
c4bfceab7246
Applied fixes and improvements to hex float scanner.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
388
diff
changeset
|
55 HexFloatExpMustStartWithDigit, |
c4bfceab7246
Applied fixes and improvements to hex float scanner.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
388
diff
changeset
|
56 FloatExpMustStartWithDigit, |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
81
diff
changeset
|
57 |
309 | 58 // Parser messages: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
81
diff
changeset
|
59 ExpectedButFound, |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
86
diff
changeset
|
60 RedundantStorageClass, |
341
3ac651ea83fb
- Fix: created TemplateAliasParameter instead of TemplateTypeParameter.
aziz
parents:
329
diff
changeset
|
61 TemplateTupleParameter, |
342
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
62 InContract, |
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
63 OutContract, |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
342
diff
changeset
|
64 MissingLinkageType, |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
342
diff
changeset
|
65 UnrecognizedLinkageType, |
309 | 66 |
67 // Help messages: | |
68 HelpMain, | |
329 | 69 HelpGenerate, |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
359
diff
changeset
|
70 HelpImportGraph, |
309 | 71 } |
72 | |
73 string GetMsg(MID mid) | |
74 { | |
75 assert(mid < GlobalSettings.messages.length); | |
76 return GlobalSettings.messages[mid]; | |
77 } | |
78 | |
79 char[] format(MID mid, ...) | |
80 { | |
81 auto args = arguments(_arguments, _argptr); | |
82 return format_args(GetMsg(mid), args); | |
83 } | |
84 | |
85 char[] format(char[] format_str, ...) | |
86 { | |
87 auto args = arguments(_arguments, _argptr); | |
88 return format_args(format_str, args); | |
54 | 89 } |
90 | |
309 | 91 char[] format_args(char[] format_str, char[][] args) |
92 { | |
93 char[] result = format_str; | |
94 | |
95 foreach (i, arg; args) | |
96 result = std.string.replace(result, std.string.format("{%s}", i+1), arg); | |
97 | |
98 return result; | |
99 } | |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
81
diff
changeset
|
100 |
309 | 101 char[][] arguments(TypeInfo[] tinfos, void* argptr) |
102 { | |
103 char[][] args; | |
104 foreach (ti; tinfos) | |
105 { | |
106 if (ti == typeid(char[])) | |
107 args ~= va_arg!(char[])(argptr); | |
108 else if (ti == typeid(int)) | |
109 args ~= std.string.format(va_arg!(int)(argptr)); | |
110 else if (ti == typeid(dchar)) | |
111 args ~= std.string.format(va_arg!(dchar)(argptr)); | |
112 else | |
113 assert(0, "argument type not supported yet."); | |
114 } | |
115 return args; | |
116 } |