Cleaned up the formatting a bit. Switched parser over to using charBetween, which significantly improves
readability of the early parsing rules.
This commit is contained in:
parent
21253043d1
commit
556e7ad916
@ -519,7 +519,8 @@ namespace chaiscript
|
||||
* Prints the contents of an AST node, including its children, recursively
|
||||
*/
|
||||
void debug_print(TokenPtr t, std::string prepend = "") {
|
||||
std::cout << prepend << "(" << token_type_to_string(t->identifier) << ") " << t->text << " : " << t->start.line << ", " << t->start.column << std::endl;
|
||||
std::cout << prepend << "(" << token_type_to_string(t->identifier) << ") "
|
||||
<< t->text << " : " << t->start.line << ", " << t->start.column << std::endl;
|
||||
for (unsigned int j = 0; j < t->children.size(); ++j) {
|
||||
debug_print(t->children[j], prepend + " ");
|
||||
}
|
||||
|
@ -895,7 +895,8 @@ namespace chaiscript
|
||||
try {
|
||||
if (function_name == class_name) {
|
||||
ss.add(Proxy_Function
|
||||
(new Dynamic_Object_Constructor(class_name, Proxy_Function(new Dynamic_Proxy_Function(boost::bind(&eval_function<Eval_System>,
|
||||
(new Dynamic_Object_Constructor(class_name, Proxy_Function
|
||||
(new Dynamic_Proxy_Function(boost::bind(&eval_function<Eval_System>,
|
||||
boost::ref(ss), node->children.back(),
|
||||
param_names, _1), numparams,
|
||||
annotation, guard)))), function_name);
|
||||
@ -909,7 +910,8 @@ namespace chaiscript
|
||||
// No biggie, the type name is just not known
|
||||
}
|
||||
ss.add(Proxy_Function
|
||||
(new Dynamic_Object_Function(class_name, Proxy_Function(new Dynamic_Proxy_Function(boost::bind(&eval_function<Eval_System>,
|
||||
(new Dynamic_Object_Function(class_name, Proxy_Function
|
||||
(new Dynamic_Proxy_Function(boost::bind(&eval_function<Eval_System>,
|
||||
boost::ref(ss), node->children.back(),
|
||||
param_names, _1), numparams,
|
||||
annotation, guard)), ti)), function_name);
|
||||
@ -944,9 +946,9 @@ namespace chaiscript
|
||||
numparams = 0;
|
||||
}
|
||||
|
||||
return Boxed_Value(Proxy_Function(
|
||||
new Dynamic_Proxy_Function(
|
||||
boost::bind(&eval_function<Eval_System>, boost::ref(ss), node->children.back(), param_names, _1), numparams)));
|
||||
return Boxed_Value(Proxy_Function(new Dynamic_Proxy_Function
|
||||
(boost::bind(&eval_function<Eval_System>, boost::ref(ss), node->children.back(), param_names, _1),
|
||||
numparams)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -151,6 +151,18 @@ namespace chaiscript
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Does ranged char check
|
||||
*/
|
||||
inline bool charBetween(char start, char end) {
|
||||
if ((*input_pos >= start) && (*input_pos <= end)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips any multi-line or single-line comment
|
||||
*/
|
||||
@ -214,17 +226,17 @@ namespace chaiscript
|
||||
bool retval = false;
|
||||
std::string::iterator start = input_pos;
|
||||
|
||||
if ((input_pos != input_end) && (((*input_pos >= '0') && (*input_pos <= '9')) || (*input_pos == '.'))) {
|
||||
while ((input_pos != input_end) && (*input_pos >= '0') && (*input_pos <= '9')) {
|
||||
if ((input_pos != input_end) && (charBetween('0', '9') || (*input_pos == '.'))) {
|
||||
while ((input_pos != input_end) && charBetween('0', '9')) {
|
||||
++input_pos;
|
||||
++col;
|
||||
}
|
||||
if ((input_pos != input_end) && (*input_pos == '.')) {
|
||||
++input_pos;
|
||||
++col;
|
||||
if ((input_pos != input_end) && (*input_pos >= '0') && (*input_pos <= '9')) {
|
||||
if ((input_pos != input_end) && charBetween('0', '9')) {
|
||||
retval = true;
|
||||
while ((input_pos != input_end) && (*input_pos >= '0') && (*input_pos <= '9')) {
|
||||
while ((input_pos != input_end) && charBetween('0', '9')) {
|
||||
++input_pos;
|
||||
++col;
|
||||
}
|
||||
@ -250,13 +262,13 @@ namespace chaiscript
|
||||
if ((input_pos != input_end) && ((*input_pos == 'x') || (*input_pos == 'X'))) {
|
||||
++input_pos;
|
||||
++col;
|
||||
if ((input_pos != input_end) && (((*input_pos >= '0') && (*input_pos <= '9')) ||
|
||||
((*input_pos >= 'a') && (*input_pos <= 'f')) ||
|
||||
((*input_pos >= 'A') && (*input_pos <= 'F')))) {
|
||||
if ((input_pos != input_end) && (charBetween('0', '9') ||
|
||||
charBetween('a', 'f') ||
|
||||
charBetween('A', 'F'))) {
|
||||
retval = true;
|
||||
while ((input_pos != input_end) && (((*input_pos >= '0') && (*input_pos <= '9')) ||
|
||||
((*input_pos >= 'a') && (*input_pos <= 'f')) ||
|
||||
((*input_pos >= 'A') && (*input_pos <= 'F')))) {
|
||||
while ((input_pos != input_end) && (charBetween('0', '9') ||
|
||||
charBetween('a', 'f') ||
|
||||
charBetween('A', 'F'))) {
|
||||
++input_pos;
|
||||
++col;
|
||||
}
|
||||
@ -287,9 +299,9 @@ namespace chaiscript
|
||||
if ((input_pos != input_end) && ((*input_pos == 'b') || (*input_pos == 'B'))) {
|
||||
++input_pos;
|
||||
++col;
|
||||
if ((input_pos != input_end) && ((*input_pos >= '0') && (*input_pos <= '1'))) {
|
||||
if ((input_pos != input_end) && charBetween('0', '1')) {
|
||||
retval = true;
|
||||
while ((input_pos != input_end) && ((*input_pos >= '0') && (*input_pos <= '1'))) {
|
||||
while ((input_pos != input_end) && charBetween('0', '1')) {
|
||||
++input_pos;
|
||||
++col;
|
||||
}
|
||||
@ -321,7 +333,7 @@ namespace chaiscript
|
||||
std::string::iterator start = input_pos;
|
||||
int prev_col = col;
|
||||
int prev_line = line;
|
||||
if ((input_pos != input_end) && (((*input_pos >= '0') && (*input_pos <= '9')) || (*input_pos == '.')) ) {
|
||||
if ((input_pos != input_end) && (charBetween('0', '9') || (*input_pos == '.')) ) {
|
||||
if (Hex_()) {
|
||||
std::string match(start, input_pos);
|
||||
std::stringstream ss(match);
|
||||
@ -389,10 +401,10 @@ namespace chaiscript
|
||||
*/
|
||||
bool Id_() {
|
||||
bool retval = false;
|
||||
if ((input_pos != input_end) && (((*input_pos >= 'A') && (*input_pos <= 'Z')) || (*input_pos == '_') || ((*input_pos >= 'a') && (*input_pos <= 'z')))) {
|
||||
if ((input_pos != input_end) && (charBetween('A', 'Z') || (*input_pos == '_') || charBetween('a', 'z'))) {
|
||||
retval = true;
|
||||
while ((input_pos != input_end) && (((*input_pos >= 'A') && (*input_pos <= 'Z')) || (*input_pos == '_') || ((*input_pos >= 'a') && (*input_pos <= 'z'))
|
||||
|| ((*input_pos >= '0') && (*input_pos <= '9')))) {
|
||||
while ((input_pos != input_end) && (charBetween('A', 'Z') || (*input_pos == '_') ||
|
||||
charBetween('a', 'z') || charBetween('0', '9'))) {
|
||||
++input_pos;
|
||||
++col;
|
||||
}
|
||||
@ -843,8 +855,8 @@ namespace chaiscript
|
||||
bool retval = Keyword_(s);
|
||||
if (retval) {
|
||||
//todo: fix this. Hacky workaround for preventing substring matches
|
||||
if ((input_pos != input_end) && (((*input_pos >= 'A') && (*input_pos <= 'Z')) || (*input_pos == '_') || ((*input_pos >= 'a') && (*input_pos <= 'z'))
|
||||
|| ((*input_pos >= '0') && (*input_pos <= '9')))) {
|
||||
if ((input_pos != input_end) && (charBetween('A', 'Z') || (*input_pos == '_') || charBetween('a', 'z')
|
||||
|| charBetween('0', '9'))) {
|
||||
input_pos = start;
|
||||
col = prev_col;
|
||||
line = prev_line;
|
||||
@ -862,8 +874,8 @@ namespace chaiscript
|
||||
int prev_line = line;
|
||||
if (Keyword_(s)) {
|
||||
//todo: fix this. Hacky workaround for preventing substring matches
|
||||
if ((input_pos != input_end) && (((*input_pos >= 'A') && (*input_pos <= 'Z')) || (*input_pos == '_') || ((*input_pos >= 'a') && (*input_pos <= 'z'))
|
||||
|| ((*input_pos >= '0') && (*input_pos <= '9')))) {
|
||||
if ((input_pos != input_end) && (charBetween('A', 'Z') || (*input_pos == '_') ||
|
||||
charBetween('a', 'z') || charBetween('0', '9'))) {
|
||||
input_pos = start;
|
||||
col = prev_col;
|
||||
line = prev_line;
|
||||
@ -916,8 +928,10 @@ namespace chaiscript
|
||||
bool retval = Symbol_(s);
|
||||
if (retval) {
|
||||
//todo: fix this. Hacky workaround for preventing substring matches
|
||||
if ((input_pos != input_end) && (disallow_prevention == false) && ((*input_pos == '+') || (*input_pos == '-') || (*input_pos == '*') || (*input_pos == '/')
|
||||
|| (*input_pos == '|') || (*input_pos == '&') || (*input_pos == '^') || (*input_pos == '=') || (*input_pos == '.') || (*input_pos == '<') || (*input_pos == '>'))) {
|
||||
if ((input_pos != input_end) && (disallow_prevention == false) &&
|
||||
((*input_pos == '+') || (*input_pos == '-') || (*input_pos == '*') || (*input_pos == '/') ||
|
||||
(*input_pos == '|') || (*input_pos == '&') || (*input_pos == '^') || (*input_pos == '=') ||
|
||||
(*input_pos == '.') || (*input_pos == '<') || (*input_pos == '>'))) {
|
||||
input_pos = start;
|
||||
col = prev_col;
|
||||
line = prev_line;
|
||||
@ -935,8 +949,10 @@ namespace chaiscript
|
||||
int prev_line = line;
|
||||
if (Symbol_(s)) {
|
||||
//todo: fix this. Hacky workaround for preventing substring matches
|
||||
if ((input_pos != input_end) && (disallow_prevention == false) && ((*input_pos == '+') || (*input_pos == '-') || (*input_pos == '*') || (*input_pos == '/')
|
||||
|| (*input_pos == '|') || (*input_pos == '&') || (*input_pos == '^') || (*input_pos == '=') || (*input_pos == '.') || (*input_pos == '<') || (*input_pos == '>'))) {
|
||||
if ((input_pos != input_end) && (disallow_prevention == false) &&
|
||||
((*input_pos == '+') || (*input_pos == '-') || (*input_pos == '*') || (*input_pos == '/') ||
|
||||
(*input_pos == '|') || (*input_pos == '&') || (*input_pos == '^') || (*input_pos == '=') ||
|
||||
(*input_pos == '.') || (*input_pos == '<') || (*input_pos == '>'))) {
|
||||
input_pos = start;
|
||||
col = prev_col;
|
||||
line = prev_line;
|
||||
@ -1858,5 +1874,4 @@ namespace chaiscript
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif /* CHAISCRIPT_PARSER_HPP_ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user