Mercurial > projects > dil
comparison src/dil/SourceText.d @ 818:372fa4fbbb1d
Added error messages and applied fixes.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Thu, 13 Mar 2008 02:21:26 +0100 |
parents | bcb74c9b895c |
children |
comparison
equal
deleted
inserted
replaced
817:e6fb7ed87d3a | 818:372fa4fbbb1d |
---|---|
4 +/ | 4 +/ |
5 module dil.SourceText; | 5 module dil.SourceText; |
6 | 6 |
7 import dil.Converter; | 7 import dil.Converter; |
8 import dil.Information; | 8 import dil.Information; |
9 import dil.Location; | |
10 import dil.Messages; | |
9 import common; | 11 import common; |
10 | 12 |
11 import tango.io.File; | 13 import tango.io.File; |
14 import tango.io.FilePath; | |
12 | 15 |
13 /// Represents D source code. | 16 /// Represents D source code. |
14 /// | 17 /// |
15 /// The source text may come from a file or from a memory buffer. | 18 /// The source text may come from a file or from a memory buffer. |
16 final class SourceText | 19 final class SourceText |
43 void load(InfoManager infoMan = null) | 46 void load(InfoManager infoMan = null) |
44 { | 47 { |
45 if (!infoMan) | 48 if (!infoMan) |
46 infoMan = new InfoManager; | 49 infoMan = new InfoManager; |
47 assert(filePath.length); | 50 assert(filePath.length); |
51 | |
52 scope(failure) | |
53 { | |
54 if (!(new FilePath(this.filePath)).exists()) | |
55 infoMan ~= new LexerError(new Location(filePath, 0), | |
56 MSG.InexistantFile); | |
57 else | |
58 infoMan ~= new LexerError(new Location(filePath, 0), | |
59 MSG.CantReadFile); | |
60 data = "\0"; | |
61 return; | |
62 } | |
63 | |
48 // Read the file. | 64 // Read the file. |
49 auto rawdata = cast(ubyte[]) (new File(filePath)).read(); | 65 auto rawdata = cast(ubyte[]) (new File(filePath)).read(); |
50 // Convert the data. | 66 // Convert the data. |
51 auto converter = Converter(filePath, infoMan); | 67 auto converter = Converter(filePath, infoMan); |
52 data = converter.data2UTF8(rawdata); | 68 data = converter.data2UTF8(rawdata); |