Mercurial > projects > dil
comparison trunk/src/dil/SettingsLoader.d @ 673:64fec49651cf
Renamed VariableDeclaration to VariablesDeclaration.
Removed TryCast and CastTo template functions.
Renamed Node.iS() to Node.Is().
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Fri, 18 Jan 2008 16:44:20 +0100 |
parents | 2848ce3becf5 |
children | 1ae72234db26 |
comparison
equal
deleted
inserted
replaced
672:d422e5f2f3ea | 673:64fec49651cf |
---|---|
24 if (modul.hasErrors) | 24 if (modul.hasErrors) |
25 throw new Exception("There are errors in " ~ filePath ~ "."); | 25 throw new Exception("There are errors in " ~ filePath ~ "."); |
26 | 26 |
27 foreach (decl; modul.root.children) | 27 foreach (decl; modul.root.children) |
28 { | 28 { |
29 auto v = TryCast!(VariableDeclaration)(decl); | 29 auto v = decl.Is!(VariablesDeclaration); |
30 if (v is null) | 30 if (v is null) |
31 continue; | 31 continue; |
32 | 32 |
33 auto variableName = v.idents[0].str; | 33 auto variableName = v.idents[0].str; |
34 auto e = v.values[0]; | 34 auto e = v.values[0]; |
36 throw new Exception(variableName ~ " variable has no value set."); | 36 throw new Exception(variableName ~ " variable has no value set."); |
37 | 37 |
38 switch (variableName) | 38 switch (variableName) |
39 { | 39 { |
40 case "langfile": | 40 case "langfile": |
41 if (auto val = TryCast!(StringExpression)(e)) | 41 if (auto val = e.Is!(StringExpression)) |
42 GlobalSettings.langFile = val.getString(); | 42 GlobalSettings.langFile = val.getString(); |
43 break; | 43 break; |
44 case "import_paths": | 44 case "import_paths": |
45 if (auto array = TryCast!(ArrayInitializer)(e)) | 45 if (auto array = e.Is!(ArrayInitializer)) |
46 { | 46 { |
47 foreach (value; array.values) | 47 foreach (value; array.values) |
48 if (auto str = TryCast!(StringExpression)(value)) | 48 if (auto str = value.Is!(StringExpression)) |
49 GlobalSettings.importPaths ~= str.getString(); | 49 GlobalSettings.importPaths ~= str.getString(); |
50 } | 50 } |
51 else | 51 else |
52 throw new Exception("import_paths variable is set to "~e.classinfo.name~" instead of an ArrayInitializer."); | 52 throw new Exception("import_paths variable is set to "~e.classinfo.name~" instead of an ArrayInitializer."); |
53 break; | 53 break; |
54 case "lexer_error": | 54 case "lexer_error": |
55 if (auto val = TryCast!(StringExpression)(e)) | 55 if (auto val = e.Is!(StringExpression)) |
56 GlobalSettings.lexerErrorFormat = val.getString(); | 56 GlobalSettings.lexerErrorFormat = val.getString(); |
57 break; | 57 break; |
58 case "parser_error": | 58 case "parser_error": |
59 if (auto val = TryCast!(StringExpression)(e)) | 59 if (auto val = e.Is!(StringExpression)) |
60 GlobalSettings.parserErrorFormat = val.getString(); | 60 GlobalSettings.parserErrorFormat = val.getString(); |
61 break; | 61 break; |
62 case "semantic_error": | 62 case "semantic_error": |
63 if (auto val = TryCast!(StringExpression)(e)) | 63 if (auto val = e.Is!(StringExpression)) |
64 GlobalSettings.semanticErrorFormat = val.getString(); | 64 GlobalSettings.semanticErrorFormat = val.getString(); |
65 break; | 65 break; |
66 default: | 66 default: |
67 } | 67 } |
68 } | 68 } |
76 throw new Exception("There are errors in "~filePath~"."); | 76 throw new Exception("There are errors in "~filePath~"."); |
77 | 77 |
78 char[][] messages; | 78 char[][] messages; |
79 foreach (decl; modul.root.children) | 79 foreach (decl; modul.root.children) |
80 { | 80 { |
81 auto v = TryCast!(VariableDeclaration)(decl); | 81 auto v = decl.Is!(VariablesDeclaration); |
82 if (v is null) | 82 if (v is null) |
83 continue; | 83 continue; |
84 | 84 |
85 auto variableName = v.idents[0].str; | 85 auto variableName = v.idents[0].str; |
86 auto e = v.values[0]; | 86 auto e = v.values[0]; |
88 throw new Exception(variableName~" variable in "~filePath~" has no value set."); | 88 throw new Exception(variableName~" variable in "~filePath~" has no value set."); |
89 | 89 |
90 switch (variableName) | 90 switch (variableName) |
91 { | 91 { |
92 case "messages": | 92 case "messages": |
93 if (auto array = TryCast!(ArrayInitializer)(e)) | 93 if (auto array = e.Is!(ArrayInitializer)) |
94 { | 94 { |
95 foreach (value; array.values) | 95 foreach (value; array.values) |
96 { | 96 { |
97 if (auto str = TryCast!(StringExpression)(value)) | 97 if (auto str = value.Is!(StringExpression)) |
98 messages ~= str.getString(); | 98 messages ~= str.getString(); |
99 } | 99 } |
100 } | 100 } |
101 else | 101 else |
102 throw new Exception("messages variable is set to "~e.classinfo.name~" instead of an ArrayInitializer."); | 102 throw new Exception("messages variable is set to "~e.classinfo.name~" instead of an ArrayInitializer."); |
103 break; | 103 break; |
104 case "lang_code": | 104 case "lang_code": |
105 if (auto str = TryCast!(StringExpression)(e)) | 105 if (auto str = e.Is!(StringExpression)) |
106 GlobalSettings.langCode = str.getString(); | 106 GlobalSettings.langCode = str.getString(); |
107 break; | 107 break; |
108 default: | 108 default: |
109 } | 109 } |
110 } | 110 } |