scriptreader.cxx

changeset 11
f08abacb46c9
parent 10
2c0f76090372
child 12
1bdbfcca2fc6
equal deleted inserted replaced
10:2c0f76090372 11:f08abacb46c9
52 52
53 return false; 53 return false;
54 } 54 }
55 55
56 ScriptReader::ScriptReader (str path) { 56 ScriptReader::ScriptReader (str path) {
57 extdelimeters = false;
58 atnewline = false; 57 atnewline = false;
59 filepath = path; 58 filepath = path;
60 if (!(fp = fopen (path, "r"))) { 59 if (!(fp = fopen (path, "r"))) {
61 error ("couldn't open %s for reading!\n", path.chars ()); 60 error ("couldn't open %s for reading!\n", path.chars ());
62 exit (1); 61 exit (1);
92 } 91 }
93 92
94 // true if was found, false if not. 93 // true if was found, false if not.
95 bool ScriptReader::Next () { 94 bool ScriptReader::Next () {
96 str tmp = ""; 95 str tmp = "";
97 bool dontreadnext = false;
98 while (!feof (fp)) { 96 while (!feof (fp)) {
99 c = ReadChar (); 97 c = ReadChar ();
100 98
101 // Extended delimeters: basically any non-alnum characters. 99 // Non-alphanumber characters (sans underscore) break the word too.
102 // These delimeters break the word too. If there was prior data, 100 // If there was prior data, the delimeter pushes the cursor back so
103 // the delimeter pushes the cursor back so that the next character 101 // that the next character will be the same delimeter. If there isn't,
104 // will be the same delimeter. If there isn't, the delimeter itself 102 // the delimeter itself is included (and thus becomes a token itself.)
105 // is included (and thus becomes a token itself.) 103 if ((c >= 33 && c <= 47) ||
106 bool shouldBreak = false; 104 (c >= 58 && c <= 64) ||
107 if (extdelimeters) { 105 (c >= 91 && c <= 96 && c != '_') ||
108 if ((c >= 33 && c <= 47) || 106 (c >= 123 && c <= 126)) {
109 (c >= 58 && c <= 64) || 107 if (tmp.len())
110 // underscore isn't a delimeter 108 fseek (fp, ftell (fp) - 1, SEEK_SET);
111 (c >= 91 && c <= 96 && c != 95) || 109 else
112 (c >= 123 && c <= 126)) { 110 tmp += c;
113 if (tmp.len()) 111 break;
114 fseek (fp, ftell (fp) - 1, SEEK_SET);
115 else
116 tmp += c;
117 shouldBreak = true;
118 break;
119 }
120 } 112 }
121 if (shouldBreak)
122 break;
123 113
124 if (IsDelimeter (c)) { 114 if (IsDelimeter (c)) {
125 // Don't break if we haven't gathered anything yet. 115 // Don't break if we haven't gathered anything yet.
126 if (tmp.len()) 116 if (tmp.len())
127 break; 117 break;
205 header, filepath.chars(), curline, curchar, message); 195 header, filepath.chars(), curline, curchar, message);
206 } 196 }
207 197
208 // I guess this should be a void function putting the return value into token? 198 // I guess this should be a void function putting the return value into token?
209 str ScriptReader::MustGetString () { 199 str ScriptReader::MustGetString () {
210 if (!extdelimeters)
211 ParserError ("MustGetString doesn't work with parsers not using extended delimeters!");
212
213 MustNext ("\""); 200 MustNext ("\"");
214 201
215 str string; 202 str string;
216 // Keep reading characters until we find a terminating quote. 203 // Keep reading characters until we find a terminating quote.
217 while (1) { 204 while (1) {

mercurial