projects
/
supertux.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Patch by Matt McCutchen to find levels in current directory when selected from comman...
[supertux.git]
/
src
/
lisp
/
lexer.cpp
diff --git
a/src/lisp/lexer.cpp
b/src/lisp/lexer.cpp
index
e1a4220
..
90f4aa2
100644
(file)
--- a/
src/lisp/lexer.cpp
+++ b/
src/lisp/lexer.cpp
@@
-22,6
+22,7
@@
#include <cstring>
#include <stdexcept>
#include <iostream>
#include <cstring>
#include <stdexcept>
#include <iostream>
+#include <stdio.h>
#include "lexer.hpp"
#include "lexer.hpp"
@@
-65,6
+66,16
@@
Lexer::nextChar()
}
}
c = *bufpos++;
}
}
c = *bufpos++;
+ if(c == '\n')
+ ++linenumber;
+}
+
+void
+Lexer::addChar()
+{
+ if(token_length < MAX_TOKEN_LENGTH)
+ token_string[token_length++] = c;
+ nextChar();
}
Lexer::TokenType
}
Lexer::TokenType
@@
-73,21
+84,15
@@
Lexer::getNextToken()
static const char* delims = "\"();";
while(isspace(c)) {
static const char* delims = "\"();";
while(isspace(c)) {
- if(c == '\n')
- ++linenumber;
nextChar();
nextChar();
- }
;
+ }
token_length = 0;
switch(c) {
case ';': // comment
token_length = 0;
switch(c) {
case ';': // comment
- while(
true
) {
+ while(
c != '\n'
) {
nextChar();
nextChar();
- if(c == '\n') {
- ++linenumber;
- break;
- }
}
return getNextToken(); // and again
case '(':
}
return getNextToken(); // and again
case '(':
@@
-107,7
+112,6
@@
Lexer::getNextToken()
case '\r':
continue;
case '\n':
case '\r':
continue;
case '\n':
- linenumber++;
break;
case '\\':
nextChar();
break;
case '\\':
nextChar();
@@
-140,9
+144,7
@@
string_finished:
nextChar();
while(isalnum(c) || c == '_') {
nextChar();
while(isalnum(c) || c == '_') {
- if(token_length < MAX_TOKEN_LENGTH)
- token_string[token_length++] = c;
- nextChar();
+ addChar();
}
token_string[token_length] = 0;
}
token_string[token_length] = 0;
@@
-176,10
+178,7
@@
string_finished:
else if(isalnum(c) || c == '_')
have_nondigits = true;
else if(isalnum(c) || c == '_')
have_nondigits = true;
- if(token_length < MAX_TOKEN_LENGTH)
- token_string[token_length++] = c;
-
- nextChar();
+ addChar();
} while(!isspace(c) && !strchr(delims, c));
token_string[token_length] = 0;
} while(!isspace(c) && !strchr(delims, c));
token_string[token_length] = 0;
@@
-194,9
+193,7
@@
string_finished:
return TOKEN_INTEGER;
} else {
do {
return TOKEN_INTEGER;
} else {
do {
- if(token_length < MAX_TOKEN_LENGTH)
- token_string[token_length++] = c;
- nextChar();
+ addChar();
} while(!isspace(c) && !strchr(delims, c));
token_string[token_length] = 0;
} while(!isspace(c) && !strchr(delims, c));
token_string[token_length] = 0;