43 #include "string.h" |
43 #include "string.h" |
44 #include "str.h" |
44 #include "str.h" |
45 #include "common.h" |
45 #include "common.h" |
46 #include "scriptreader.h" |
46 #include "scriptreader.h" |
47 |
47 |
48 bool IsWhitespace (char c) { |
48 bool IsDelimeter (char c) { |
49 // These characters are invisible, thus considered whitespace |
49 // These characters are invisible, thus considered whitespace |
50 if (c <= 32 || c == 127 || c == 255) |
50 if (c <= 32 || c == 127 || c == 255) |
51 return true; |
51 return true; |
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; |
57 atnewline = false; |
58 atnewline = false; |
58 filepath = path; |
59 filepath = path; |
59 if (!(fp = fopen (path, "r"))) { |
60 if (!(fp = fopen (path, "r"))) { |
60 error ("couldn't open %s for reading!\n", path.chars ()); |
61 error ("couldn't open %s for reading!\n", path.chars ()); |
61 exit (1); |
62 exit (1); |
104 tokenquoted = true; |
105 tokenquoted = true; |
105 quote = !quote; |
106 quote = !quote; |
106 continue; |
107 continue; |
107 } |
108 } |
108 |
109 |
109 if (IsWhitespace (c) && !quote) { |
110 // Extended delimeters: parenthesis, quote marks, braces and brackets. |
|
111 // These delimeters break the word too. If there was prior data, |
|
112 // the delimeter pushes the cursor back so that the next character |
|
113 // will be the same delimeter. If there isn't, the delimeter itself |
|
114 // is included (and thus becomes a token itself.) |
|
115 // TODO: quotation marks should be here too.. |
|
116 bool shouldBreak = false; |
|
117 if (extdelimeters) { |
|
118 switch (c) { |
|
119 case '(': case ')': |
|
120 case '{': case '}': |
|
121 case '[': case ']': |
|
122 // Push the cursor back |
|
123 if (tmp.len()) |
|
124 fseek (fp, ftell (fp)-1, SEEK_SET); |
|
125 else |
|
126 tmp += c; |
|
127 shouldBreak = true; |
|
128 break; |
|
129 } |
|
130 } |
|
131 if (shouldBreak) |
|
132 break; |
|
133 |
|
134 if (IsDelimeter (c) && !quote) { |
110 // Don't break if we haven't gathered anything yet. |
135 // Don't break if we haven't gathered anything yet. |
111 if (tmp.len()) |
136 if (tmp.len()) |
112 break; |
137 break; |
113 } else { |
138 } else { |
114 tmp += c; |
139 tmp += c; |