0
|
1
|
|
2 /* Digital Mars DMDScript source code.
|
|
3 * Copyright (c) 2000-2002 by Chromium Communications
|
|
4 * D version Copyright (c) 2004-2005 by Digital Mars
|
|
5 * All Rights Reserved
|
|
6 * written by Walter Bright
|
|
7 * www.digitalmars.com
|
|
8 * Use at your own risk. There is no warranty, express or implied.
|
|
9 * License for redistribution is by the GNU General Public License in gpl.txt.
|
|
10 *
|
|
11 * A binary, non-exclusive license for commercial use can be
|
|
12 * purchased from www.digitalmars.com/dscript/buy.html.
|
|
13 *
|
|
14 * DMDScript is implemented in the D Programming Language,
|
|
15 * www.digitalmars.com/d/
|
|
16 *
|
|
17 * For a C++ implementation of DMDScript, including COM support,
|
|
18 * see www.digitalmars.com/dscript/cppscript.html.
|
|
19 */
|
|
20
|
|
21 // Program to generate string files in script data structures.
|
|
22 // Saves much tedious typing, and eliminates typo problems.
|
|
23 // Generates:
|
|
24 // text.d
|
|
25
|
|
26 import std.c.stdio;
|
|
27 import std.c.stdlib;
|
|
28 import std.stdio;
|
|
29
|
|
30
|
|
31 struct Msgtable
|
|
32 {
|
|
33 char[] name;
|
|
34 int value;
|
|
35 char[] ident;
|
|
36 }
|
|
37
|
|
38
|
|
39 Msgtable errtable[] =
|
|
40 [
|
|
41 { "DMDScript fatal runtime error: ", 0, "ERR_RUNTIME_PREFIX" },
|
|
42 { "No default value for COM object", 0, "ERR_COM_NO_DEFAULT_VALUE" },
|
|
43 { "%s does not have a [[Construct]] property", 0, "ERR_COM_NO_CONSTRUCT_PROPERTY" },
|
|
44 { "argument type mismatch for %s", 0, "ERR_DISP_E_TYPEMISMATCH" },
|
|
45 { "wrong number of arguments for %s", 0, "ERR_DISP_E_BADPARAMCOUNT" },
|
|
46 { "%s Invoke() fails with COM error %x", 0, "ERR_COM_FUNCTION_ERROR" },
|
|
47 { "Dcomobject: %s.%s fails with COM error %x", 0, "ERR_COM_OBJECT_ERROR" },
|
|
48 { "unrecognized switch '%s'", 0, "ERR_BAD_SWITCH" },
|
|
49 { "undefined label '%s' in function '%s'", 0, "ERR_UNDEFINED_LABEL" },
|
|
50 { "unterminated /* */ comment", 0, "ERR_BAD_C_COMMENT" },
|
|
51 { "<!-- comment does not end in newline", 0, "ERR_BAD_HTML_COMMENT" },
|
|
52 { "unsupported char '%s'", 0, "ERR_BAD_CHAR_C" },
|
|
53 { "unsupported char 0x%02x", 0, "ERR_BAD_CHAR_X" },
|
|
54 { "escape hex sequence requires 2 hex digits", 0, "ERR_BAD_HEX_SEQUENCE" },
|
|
55 { "undefined escape sequence \\\\%c", 0, "ERR_UNDEFINED_ESC_SEQUENCE" },
|
|
56 { "string is missing an end quote %s", 0, "ERR_STRING_NO_END_QUOTE" },
|
|
57 { "end of file before end of string", 0, "ERR_UNTERMINATED_STRING" },
|
|
58 { "\\\\u sequence must be followed by 4 hex characters", 0, "ERR_BAD_U_SEQUENCE" },
|
|
59 { "unrecognized numeric literal", 0, "ERR_UNRECOGNIZED_N_LITERAL" },
|
|
60 { "Identifier expected in FormalParameterList, not %s", 0, "ERR_FPL_EXPECTED_IDENTIFIER" },
|
|
61 { "comma expected in FormalParameterList, not %s", 0, "ERR_FPL_EXPECTED_COMMA" },
|
|
62 { "identifier expected", 0, "ERR_EXPECTED_IDENTIFIER" },
|
|
63 { "found '%s' when expecting '%s'", 0, "ERR_EXPECTED_GENERIC" },
|
|
64 { "identifier expected instead of '%s'", 0, "ERR_EXPECTED_IDENTIFIER_PARAM" },
|
|
65 { "identifier expected following '%s', not '%s'", 0, "ERR_EXPECTED_IDENTIFIER_2PARAM" },
|
|
66 { "EOF found before closing ']' of block statement", 0, "ERR_UNTERMINATED_BLOCK" },
|
|
67 { "only one variable can be declared for 'in', not %d", 0, "ERR_TOO_MANY_IN_VARS" },
|
|
68 { "';' or 'in' expected, not '%s'", 0, "ERR_IN_EXPECTED" },
|
|
69 { "label expected after goto, not '%s'", 0, "ERR_GOTO_LABEL_EXPECTED" },
|
|
70 { "catch or finally expected following try", 0, "ERR_TRY_CATCH_EXPECTED" },
|
|
71 { "found '%s' instead of statement", 0, "ERR_STATEMENT_EXPECTED" },
|
|
72 { "expression expected, not '%s'", 0, "ERR_EXPECTED_EXPRESSION" },
|
|
73 { "Object literal in initializer", 0, "ERR_OBJ_LITERAL_IN_INITIALIZER" },
|
|
74 { "label '%s' is already defined", 0, "ERR_LABEL_ALREADY_DEFINED" },
|
|
75 { "redundant case %s", 0, "ERR_SWITCH_REDUNDANT_CASE" },
|
|
76 { "case %s: is not in a switch statement", 0, "ERR_MISPLACED_SWITCH_CASE" },
|
|
77 { "redundant default in switch statement", 0, "ERR_SWITCH_REDUNDANT_DEFAULT" },
|
|
78 { "default is not in a switch statement", 0, "ERR_MISPLACED_SWITCH_DEFAULT" },
|
|
79 { "init statement must be expression or var", 0, "ERR_INIT_NOT_EXPRESSION" },
|
|
80 { "can only break from within loop or switch", 0, "ERR_MISPLACED_BREAK" },
|
|
81 { "continue is not in a loop", 0, "ERR_MISPLACED_CONTINUE" },
|
|
82 { "Statement label '%s' is undefined", 0, "ERR_UNDEFINED_STATEMENT_LABEL" },
|
|
83 { "cannot goto into with statement", 0, "ERR_GOTO_INTO_WITH" },
|
|
84 { "can only return from within function", 0, "ERR_MISPLACED_RETURN" },
|
|
85 { "no expression for throw", 0, "ERR_NO_THROW_EXPRESSION" },
|
|
86 { "%s.%s is undefined", 0, "ERR_UNDEFINED_OBJECT_SYMBOL" },
|
|
87 { "Number.prototype.%s() expects a Number not a %s", 0, "ERR_FUNCTION_WANTS_NUMBER" },
|
|
88 { "String.prototype.%s() expects a String not a %s", 0, "ERR_FUNCTION_WANTS_STRING" },
|
|
89 { "Date.prototype.%s() expects a Date not a %s", 0, "ERR_FUNCTION_WANTS_DATE" },
|
|
90 { "%s %s is undefined and has no Call method", 0, "ERR_UNDEFINED_NO_CALL2"},
|
|
91 { "%s %s.%s is undefined and has no Call method", 0, "ERR_UNDEFINED_NO_CALL3"},
|
|
92 { "Boolean.prototype.%s() expects a Boolean not a %s", 0, "ERR_FUNCTION_WANTS_BOOL" },
|
|
93 { "arg to Array(len) must be 0 .. 2**32-1, not %.16g", 0, "ERR_ARRAY_LEN_OUT_OF_BOUNDS" },
|
|
94 { "Number.prototype.%s() %s out of range", 0, "ERR_VALUE_OUT_OF_RANGE" },
|
|
95 { "TypeError in %s", 0, "ERR_TYPE_ERROR" },
|
|
96 { "Error compiling regular expression", 0, "ERR_REGEXP_COMPILE" },
|
|
97 { "%s not transferrable", 0, "ERR_NOT_TRANSFERRABLE" },
|
|
98 { "%s %s cannot convert to Object", 0, "ERR_CANNOT_CONVERT_TO_OBJECT2" },
|
|
99 { "%s %s.%s cannot convert to Object", 0, "ERR_CANNOT_CONVERT_TO_OBJECT3" },
|
|
100 { "cannot convert %s to Object", 0, "ERR_CANNOT_CONVERT_TO_OBJECT4" },
|
|
101 { "cannot assign to %s", 0, "ERR_CANNOT_ASSIGN_TO" },
|
|
102 { "cannot assign %s to %s", 0, "ERR_CANNOT_ASSIGN" },
|
|
103 { "cannot assign to %s.%s", 0, "ERR_CANNOT_ASSIGN_TO2" },
|
|
104 { "cannot assign to function", 0, "ERR_FUNCTION_NOT_LVALUE"},
|
|
105 { "RHS of %s must be an Object, not a %s", 0, "ERR_RHS_MUST_BE_OBJECT" },
|
|
106 { "can't Put('%s', %s) to a primitive %s", 0, "ERR_CANNOT_PUT_TO_PRIMITIVE" },
|
|
107 { "can't Put(%u, %s) to a primitive %s", 0, "ERR_CANNOT_PUT_INDEX_TO_PRIMITIVE" },
|
|
108 { "object cannot be converted to a primitive type", 0, "ERR_OBJECT_CANNOT_BE_PRIMITIVE" },
|
|
109 { "can't Get(%s) from primitive %s(%s)", 0, "ERR_CANNOT_GET_FROM_PRIMITIVE" },
|
|
110 { "can't Get(%d) from primitive %s(%s)", 0, "ERR_CANNOT_GET_INDEX_FROM_PRIMITIVE" },
|
|
111 { "primitive %s has no Construct method", 0, "ERR_PRIMITIVE_NO_CONSTRUCT" },
|
|
112 { "primitive %s has no Call method", 0, "ERR_PRIMITIVE_NO_CALL" },
|
|
113 { "for-in must be on an object, not a primitive", 0, "ERR_FOR_IN_MUST_BE_OBJECT" },
|
|
114 { "assert() line %d", 0, "ERR_ASSERT"},
|
|
115 { "object does not have a [[Call]] property", 0, "ERR_OBJECT_NO_CALL"},
|
|
116 { "%s: %s", 0, "ERR_S_S"},
|
|
117 { "no Default Put for object", 0, "ERR_NO_DEFAULT_PUT"},
|
|
118 { "%s does not have a [[Construct]] property", 0, "ERR_S_NO_CONSTRUCT"},
|
|
119 { "%s does not have a [[Call]] property", 0, "ERR_S_NO_CALL"},
|
|
120 { "%s does not have a [[HasInstance]] property", 0, "ERR_S_NO_INSTANCE"},
|
|
121 { "length property must be an integer", 0, "ERR_LENGTH_INT"},
|
|
122 { "Array.prototype.toLocaleString() not transferrable", 0, "ERR_TLS_NOT_TRANSFERRABLE"},
|
|
123 { "Function.prototype.toString() not transferrable", 0, "ERR_TS_NOT_TRANSFERRABLE"},
|
|
124 { "Function.prototype.apply(): argArray must be array or arguments object", 0, "ERR_ARRAY_ARGS"},
|
|
125 { ".prototype must be an Object, not a %s", 0, "ERR_MUST_BE_OBJECT"},
|
|
126 { "VBArray expected, not a %s", 0, "ERR_VBARRAY_EXPECTED"},
|
|
127 { "VBArray subscript out of range", 0, "ERR_VBARRAY_SUBSCRIPT"},
|
|
128 { "Type mismatch", 0, "ERR_ACTIVEX"},
|
|
129 { "no property %s", 0, "ERR_NO_PROPERTY"},
|
|
130 { "Put of %s failed", 0, "ERR_PUT_FAILED"},
|
|
131 { "Get of %s failed", 0, "ERR_GET_FAILED"},
|
|
132 { "argument not a collection", 0, "ERR_NOT_COLLECTION"},
|
|
133 { "%s.%s expects a valid UTF codepoint not \\\\u%x", 0, "ERR_NOT_VALID_UTF"},
|
|
134
|
|
135 // COM error messages
|
|
136 { "Unexpected", 0, "ERR_E_UNEXPECTED"},
|
|
137 ];
|
|
138
|
|
139 int main()
|
|
140 {
|
|
141 FILE* fp;
|
|
142 uint i;
|
|
143
|
|
144 fp = fopen("errmsgs.d","w");
|
|
145 if (!fp)
|
|
146 {
|
|
147 printf("can't open errmsgs.d\n");
|
|
148 exit(EXIT_FAILURE);
|
|
149 }
|
|
150
|
|
151 fprintf(fp, "// File generated by textgen.d\n");
|
|
152 fprintf(fp, "//\n");
|
|
153
|
|
154 fprintf(fp, "// *** ERROR MESSAGES ***\n");
|
|
155 fprintf(fp, "//\n");
|
|
156 fprintf(fp, "module dmdscript.errmsgs;\n");
|
|
157 fprintf(fp, "enum {\n");
|
|
158 for (i = 0; i < errtable.length; i++)
|
|
159 { char[] id = errtable[i].ident;
|
|
160
|
|
161 if (!id)
|
|
162 id = errtable[i].name;
|
|
163 fwritefln(fp,"\t%s = %d,", id, i);
|
|
164 }
|
|
165 fprintf(fp, "};\n");
|
|
166
|
|
167 fprintf(fp, "// *** ERROR MESSAGES ***\n");
|
|
168 fprintf(fp, "//\n");
|
|
169 fprintf(fp, "char[][] errmsgtbl = [\n");
|
|
170 for (i = 0; i < errtable.length; i++)
|
|
171 { char[] id = errtable[i].ident;
|
|
172 char[] p = errtable[i].name;
|
|
173
|
|
174 fwritefln(fp,"\t\"%s\",", p);
|
|
175 }
|
|
176 fprintf(fp, "];\n");
|
|
177
|
|
178 fclose(fp);
|
|
179
|
|
180 return EXIT_SUCCESS;
|
|
181 }
|