scriptreader.cxx

changeset 9
d279af9afd6d
parent 8
c8bfa7e6ae1b
child 10
2c0f76090372
equal deleted inserted replaced
8:c8bfa7e6ae1b 9:d279af9afd6d
94 bool quote = false; 94 bool quote = false;
95 tokenquoted = false; 95 tokenquoted = false;
96 while (!feof (fp)) { 96 while (!feof (fp)) {
97 char c = ReadChar (); 97 char c = ReadChar ();
98 98
99 // Quotation mark.
100 if (c == '"') {
101 // End-quote ends the token.
102 if (quote)
103 break;
104
105 tokenquoted = true;
106 quote = !quote;
107 continue;
108 }
109
110 // Extended delimeters: parenthesis, quote marks, braces and brackets. 99 // Extended delimeters: parenthesis, quote marks, braces and brackets.
111 // These delimeters break the word too. If there was prior data, 100 // These delimeters break the word too. If there was prior data,
112 // the delimeter pushes the cursor back so that the next character 101 // the delimeter pushes the cursor back so that the next character
113 // will be the same delimeter. If there isn't, the delimeter itself 102 // will be the same delimeter. If there isn't, the delimeter itself
114 // is included (and thus becomes a token itself.) 103 // is included (and thus becomes a token itself.)
115 // TODO: quotation marks should be here too..
116 bool shouldBreak = false; 104 bool shouldBreak = false;
117 if (extdelimeters) { 105 if (extdelimeters) {
118 switch (c) { 106 switch (c) {
119 case '(': case ')': 107 case '(': case ')':
120 case '{': case '}': 108 case '{': case '}':
121 case '[': case ']': 109 case '[': case ']':
110 case '"':
122 // Push the cursor back 111 // Push the cursor back
123 if (tmp.len()) 112 if (tmp.len())
124 fseek (fp, ftell (fp)-1, SEEK_SET); 113 fseek (fp, ftell (fp)-1, SEEK_SET);
125 else 114 else
126 tmp += c; 115 tmp += c;
212 201
213 void ScriptReader::ParserMessage (const char* header, char* message) { 202 void ScriptReader::ParserMessage (const char* header, char* message) {
214 fprintf (stderr, "%sIn file %s, on line %d: %s\n", 203 fprintf (stderr, "%sIn file %s, on line %d: %s\n",
215 header, filepath.chars(), curline, message); 204 header, filepath.chars(), curline, message);
216 } 205 }
206
207 str ScriptReader::MustGetString () {
208 if (!extdelimeters)
209 ParserError ("MustGetString doesn't work with parsers not using extended delimeters!");
210
211 MustNext ("\"");
212
213 str string;
214 // Keep reading characters until we find a terminating quote.
215 while (1) {
216 // can't end here!
217 if (feof (fp))
218 ParserError ("unterminated string");
219
220 char c = ReadChar ();
221 if (c == '"')
222 break;
223
224 string += c;
225 }
226
227 return string;
228 }

mercurial