better handling of comments
This commit is contained in:
30
ml.cpp
30
ml.cpp
@@ -736,8 +736,22 @@ MlValue MlValue::eval(MlEnvironment &env) {
|
||||
}
|
||||
}
|
||||
|
||||
void skip_whitespace(const std::string &s, int &ptr) {
|
||||
while (isspace(s[ptr])) { ptr++; }
|
||||
void skip_whitespace(std::string &s, int &ptr);
|
||||
|
||||
void erase_comments(std::string &s, int &ptr) {
|
||||
while (s[ptr] == ';') {
|
||||
int save_ptr = ptr;
|
||||
while (s[save_ptr] != '\n' && save_ptr < int(s.length())) { save_ptr++; }
|
||||
s.erase(ptr, save_ptr - ptr);
|
||||
|
||||
skip_whitespace(s, ptr);
|
||||
}
|
||||
}
|
||||
|
||||
void skip_whitespace(std::string &s, int &ptr) {
|
||||
while (isspace(s[ptr])) { ptr++; }
|
||||
|
||||
erase_comments(s, ptr);
|
||||
}
|
||||
|
||||
// Parse a single value and increment the pointer
|
||||
@@ -745,16 +759,8 @@ void skip_whitespace(const std::string &s, int &ptr) {
|
||||
MlValue parse(std::string &s, int &ptr) {
|
||||
skip_whitespace(s, ptr);
|
||||
|
||||
while (s[ptr] == ';') {
|
||||
// If this is a comment
|
||||
int save_ptr = ptr;
|
||||
while (s[save_ptr] != '\n' && save_ptr < int(s.length())) { save_ptr++; }
|
||||
s.erase(ptr, save_ptr - ptr);
|
||||
skip_whitespace(s, ptr);
|
||||
|
||||
if (s.substr(ptr, s.length() - ptr - 1) == "")
|
||||
return MlValue();
|
||||
}
|
||||
if (s[ptr] == ';')
|
||||
throw std::runtime_error("this should never happen!");
|
||||
|
||||
|
||||
if (s == "") {
|
||||
|
||||
Reference in New Issue
Block a user