comparison trunk/src/dil/SettingsLoader.d @ 516:433d51c18524

Renamed template Cast to TryCast.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Fri, 14 Dec 2007 22:43:44 +0100
parents 7cb97346bc6f
children dd3fe62c8a96
comparison
equal deleted inserted replaced
515:7cb97346bc6f 516:433d51c18524
23 if (modul.hasErrors) 23 if (modul.hasErrors)
24 throw new Exception("There are errors in " ~ filePath ~ "."); 24 throw new Exception("There are errors in " ~ filePath ~ ".");
25 25
26 foreach (decl; modul.root.children) 26 foreach (decl; modul.root.children)
27 { 27 {
28 auto v = Cast!(VariableDeclaration)(decl); 28 auto v = TryCast!(VariableDeclaration)(decl);
29 if (v is null) 29 if (v is null)
30 continue; 30 continue;
31 31
32 auto variableName = v.idents[0].str; 32 auto variableName = v.idents[0].str;
33 auto e = v.values[0]; 33 auto e = v.values[0];
35 throw new Exception(variableName ~ " variable has no value set."); 35 throw new Exception(variableName ~ " variable has no value set.");
36 36
37 switch (variableName) 37 switch (variableName)
38 { 38 {
39 case "langfile": 39 case "langfile":
40 if (auto val = Cast!(StringExpression)(e)) 40 if (auto val = TryCast!(StringExpression)(e))
41 GlobalSettings.langFile = val.getString(); 41 GlobalSettings.langFile = val.getString();
42 break; 42 break;
43 case "import_paths": 43 case "import_paths":
44 if (auto array = Cast!(ArrayInitializer)(e)) 44 if (auto array = TryCast!(ArrayInitializer)(e))
45 { 45 {
46 foreach (value; array.values) 46 foreach (value; array.values)
47 if (auto str = Cast!(StringExpression)(value)) 47 if (auto str = TryCast!(StringExpression)(value))
48 GlobalSettings.importPaths ~= str.getString(); 48 GlobalSettings.importPaths ~= str.getString();
49 } 49 }
50 else 50 else
51 throw new Exception("import_paths variable is set to "~e.classinfo.name~" instead of an ArrayInitializer."); 51 throw new Exception("import_paths variable is set to "~e.classinfo.name~" instead of an ArrayInitializer.");
52 break; 52 break;
53 case "lexer_error": 53 case "lexer_error":
54 if (auto val = Cast!(StringExpression)(e)) 54 if (auto val = TryCast!(StringExpression)(e))
55 GlobalSettings.lexerErrorFormat = val.getString(); 55 GlobalSettings.lexerErrorFormat = val.getString();
56 break; 56 break;
57 case "parser_error": 57 case "parser_error":
58 if (auto val = Cast!(StringExpression)(e)) 58 if (auto val = TryCast!(StringExpression)(e))
59 GlobalSettings.parserErrorFormat = val.getString(); 59 GlobalSettings.parserErrorFormat = val.getString();
60 break; 60 break;
61 case "semantic_error": 61 case "semantic_error":
62 if (auto val = Cast!(StringExpression)(e)) 62 if (auto val = TryCast!(StringExpression)(e))
63 GlobalSettings.semanticErrorFormat = val.getString(); 63 GlobalSettings.semanticErrorFormat = val.getString();
64 break; 64 break;
65 default: 65 default:
66 } 66 }
67 } 67 }
75 throw new Exception("There are errors in "~filePath~"."); 75 throw new Exception("There are errors in "~filePath~".");
76 76
77 char[][] messages; 77 char[][] messages;
78 foreach (decl; modul.root.children) 78 foreach (decl; modul.root.children)
79 { 79 {
80 auto v = Cast!(VariableDeclaration)(decl); 80 auto v = TryCast!(VariableDeclaration)(decl);
81 if (v is null) 81 if (v is null)
82 continue; 82 continue;
83 83
84 auto variableName = v.idents[0].str; 84 auto variableName = v.idents[0].str;
85 auto e = v.values[0]; 85 auto e = v.values[0];
87 throw new Exception(variableName~" variable in "~filePath~" has no value set."); 87 throw new Exception(variableName~" variable in "~filePath~" has no value set.");
88 88
89 switch (variableName) 89 switch (variableName)
90 { 90 {
91 case "messages": 91 case "messages":
92 if (auto array = Cast!(ArrayInitializer)(e)) 92 if (auto array = TryCast!(ArrayInitializer)(e))
93 { 93 {
94 foreach (value; array.values) 94 foreach (value; array.values)
95 { 95 {
96 if (auto str = Cast!(StringExpression)(value)) 96 if (auto str = TryCast!(StringExpression)(value))
97 messages ~= str.getString(); 97 messages ~= str.getString();
98 } 98 }
99 } 99 }
100 else 100 else
101 throw new Exception("messages variable is set to "~e.classinfo.name~" instead of an ArrayInitializer."); 101 throw new Exception("messages variable is set to "~e.classinfo.name~" instead of an ArrayInitializer.");
102 break; 102 break;
103 case "lang_code": 103 case "lang_code":
104 if (auto str = Cast!(StringExpression)(e)) 104 if (auto str = TryCast!(StringExpression)(e))
105 GlobalSettings.langCode = str.getString(); 105 GlobalSettings.langCode = str.getString();
106 break; 106 break;
107 default: 107 default:
108 } 108 }
109 } 109 }