ソースを参照

parseExpression deprecation, jsGetTokens guard for closing /, doAssignment/doExpression refactor, parseJSON "" support, doAssignment "x in y" support start, dereferenceObject bracket deferencing start, jsParseTokens better if suppor, gcc compile fixt

master
Odilitime 3年前
コミット
a8037472f7
1個のファイルの変更257行の追加337行の削除
  1. 257
    337
      src/parsers/scripting/javascript/JSParser.cpp

+ 257
- 337
src/parsers/scripting/javascript/JSParser.cpp ファイルの表示

@@ -3,6 +3,7 @@

#include <iostream>
#include <fstream>
#include <algorithm>

extern std::ofstream assignfile;
extern std::ofstream execfile;
@@ -148,9 +149,13 @@ std::vector<std::string> jsGetTokens(const std::string &source, const size_t sta
state = 3;
} else if (source[cursor] == '/') {
// regex
size_t endex = locateRegexEnd(source, cursor + 1); // +1 because it can't start on /
cursor = endex; // put here after regex
// state = 9;
if (source.length() > cursor + 1) {
size_t endex = locateRegexEnd(source, cursor + 1); // +1 because it can't start on /
cursor = endex; // put here after regex
// state = 9;
} else {
std::cout << "jsGetTokens - warning - no characters left in state 0\n";
}
} else if (source[cursor] == 'v' && source.length() > cursor + 3 && source[cursor + 1] == 'a'
&& source[cursor + 2] == 'r' && source[cursor + 3] == ' ') {
// var
@@ -285,6 +290,7 @@ js_internal_storage *doFunctionCall(js_function *func, std::string params, js_fu
}

// this should evaluate an expression and return it's return value
int doExpressionLevel = 0;
js_internal_storage *doExpression(js_function &rootScope, std::string token) {
std::vector<std::string> expression_parts;
size_t cursor;
@@ -294,6 +300,7 @@ js_internal_storage *doExpression(js_function &rootScope, std::string token) {
size_t parenLevel = 0;
size_t trinaryLevel = 0;
unsigned char state = 0;
std::cout << "doExpression start[" << token << "]\n";
// parse expression
for (cursor = 0; cursor < token.length(); cursor++) {
if (state == 0) {
@@ -312,32 +319,32 @@ js_internal_storage *doExpression(js_function &rootScope, std::string token) {
quoteStart = cursor;
state = 4;
} else
if (token[cursor] == '"') {
quoteStart = cursor;
state = 5;
} else
if (token[cursor] == '(') {
parenStart = cursor;
parenLevel++;
state = 8;
if (last != cursor) {
// could be a func call or func def (w/ or w/o call)
expression_parts.push_back(token.substr(last, cursor - last));
}
last = cursor + 1;
expression_parts.push_back("(");
} else
if (token[cursor] == '{') {
parenStart = cursor;
parenLevel++;
state = 1;
//std::cout << "last " << last << " cursor " << cursor << std::endl;
if (last != cursor) {
expression_parts.push_back(token.substr(last, cursor - last - 1));
}
last = cursor + 1;
expression_parts.push_back("{");
}
if (token[cursor] == '"') {
quoteStart = cursor;
state = 5;
} else
if (token[cursor] == '(') {
parenStart = cursor;
parenLevel++;
state = 8;
if (last != cursor) {
// could be a func call or func def (w/ or w/o call)
expression_parts.push_back(token.substr(last, cursor - last));
}
last = cursor + 1;
expression_parts.push_back("(");
} else
if (token[cursor] == '{') {
parenStart = cursor;
parenLevel++;
state = 1;
//std::cout << "last " << last << " cursor " << cursor << std::endl;
if (last != cursor) {
expression_parts.push_back(token.substr(last, cursor - last - 1));
}
last = cursor + 1;
expression_parts.push_back("{");
}

// single =
if (token[cursor] == '=' && token.length() > cursor + 1 && token[cursor + 1] != '=') {
@@ -521,13 +528,14 @@ js_internal_storage *doExpression(js_function &rootScope, std::string token) {
state = 0;
std::string callFunc = "";
std::string params = "";
js_function *func = nullptr;
//js_function *func = nullptr;
for(auto it : expression_parts) {
std::string trimmedToken = trim(it);
if (trimmedToken == "") continue;
std::cout << "doExpression part[" << it << "] state[" << std::to_string(state) << "]\n";
if (state == 0) {
// variable
// &&
if (it == "&&") {
if (trimmedToken == "&&") {
// if stack is false abort
std::cout << "typeOf stack is [" << typeOfStorage(stack) << "]\n";
std::string type = typeOfStorage(stack);
@@ -560,14 +568,112 @@ js_internal_storage *doExpression(js_function &rootScope, std::string token) {
} else {
std::cout << "doExpression, I don't know how to process this type - WRITE ME\n";
}
continue;
}
if (it == "!") {
if (trimmedToken == "!") {
state = 4;
continue;
}
if (trimmedToken == "{") {
// parseJSON
state = 5;
continue;
}
std::string first8 = trimmedToken.substr(0, 8);
if (first8 == "function") {
std::string prototype = trimmedToken.substr(9, trimmedToken.length() - 10);
std::cout << "extracted[" << prototype << "]\n";
js_function *jsfunc = new js_function;
jsfunc->parameters = split(prototype, ',');
stack = jsfunc;
continue;
}

// function name
// (
if (trimmedToken == "(") {
// function call
std::cout << "func call param start\n";
state = 2;
continue;
}
// function params
// )
if (trimmedToken == ")") {
std::cout << "func call param end\n";
state = 3;
continue;
}
if (trimmedToken == "}") {
// {return document.getElementById(e)}
/*
doExpression has [3]parts
doExpression part[{] state[0]
doExpression part[return document.getElementById(e)] state[5]
*/
// ?
continue;
}

// variable
// object.property
js_internal_storage *dereferenceTest = dereferenceObject(trimmedToken, &rootScope);
if (dereferenceTest) {
stack = dereferenceTest;
if (typeOfStorage(stack)=="func") {
// it could be a call...
callFunc = it;
state = 1;
}
continue;
}
// it's a string constant
if ((trimmedToken[0] == '"' && trimmedToken[trimmedToken.length() - 1] == '"') ||
(trimmedToken[0] == '\'' && trimmedToken[trimmedToken.length() - 1] == '\'')) {
js_string *jstring = new js_string;
jstring->value = trimmedToken.substr(1, -1);
stack = jstring;
continue;
}
if (trimmedToken == "true") {
js_bool *jbool = new js_bool;
jbool->value = true;
stack = jbool;
continue;
} else if (trimmedToken == "null") {
// FIXME: is null a type?
js_bool *jbool = new js_bool;
jbool->value = false;
stack = jbool;
continue;
} else if (trimmedToken == "false") {
js_bool *jbool = new js_bool;
jbool->value = false;
stack = jbool;
continue;
}
// number constant
bool allDigits = true;
for(auto it2 : trimmedToken) {
if (it2 >= '0' && it2 <= '9') {
} else {
if (it2 != '.') {
allDigits = false;
}
}
}
if (allDigits) {
js_number *jnum = new js_number;
jnum->value = std::stoi(trimmedToken);
std::cout << "allDigits value[" << trimmedToken << "] => jnum[" << jnum->value << "]\n";
stack = jnum;
continue;
}
js_internal_storage **isVar = getObjectKeyPointer(it, &rootScope);
if (isVar != nullptr) {
std::cout << "isVar [" << isVar << "]\n";
@@ -587,7 +693,13 @@ js_internal_storage *doExpression(js_function &rootScope, std::string token) {
}
*/
} else {
std::cout << "is Not a Var\n";
js_internal_storage *scopeTest = jsLocateKey(&rootScope, it);
if (scopeTest) {
stack = scopeTest;
} else {
jsDisplayScope(&rootScope, 0);
std::cout << "is Not a Var\n";
}
}
} else if (state == 1) {
// in func call, double check the (
@@ -604,8 +716,12 @@ js_internal_storage *doExpression(js_function &rootScope, std::string token) {
// in func call, double check the )
if (it == ")") {
js_function *jfunc = dynamic_cast<js_function*>(stack);
if (!jfunc) {
std::cout << "Could cast [" << stack << "] to func\n";
continue;
}
std::cout << "calling [" << callFunc << "](" << params << ") at [" << jfunc << "] with [" << jfunc->tokens.size() << "]tokens\n";
js_internal_storage *retval = doFunctionCall(jfunc, params, rootScope);
stack = doFunctionCall(jfunc, params, rootScope);
state = 0;
} else {
std::cout << "func call did not have (\n";
@@ -618,6 +734,21 @@ js_internal_storage *doExpression(js_function &rootScope, std::string token) {
jb->value = !jsIsFalse(expRes);
stack = jb;
state = 0;
} else if (state == 5) {
js_function *objectScope = new js_function;
js_object *newObject = new js_object;
//doAssignment(*objectScope, it);
parseJSON(*objectScope, it);
// translate the scope into js_object
//std::cout << "JSON object output" << std::endl;
for(auto it2 : objectScope->locals.value) {
//std::cout << "[" << it2.first << "=" << it2.second << "]" << std::endl;
newObject->value[it2.first] = it2.second;
}
//std::cout << "JSON object done" << std::endl;
stack = newObject;
state = 0;
} else {
std::cout << "doExpression unknown state[" << std::to_string(state) << "]\n";
}
@@ -854,7 +985,7 @@ size_t getNextExpression(const std::string source, const size_t start) {
parenLevel++;
state = 2;
}
// minification technique
// minification technique (or list of variables, still an end of an expression tho)
if (source[cursor]==',') {
getNextExpressionLevel--;
return cursor;
@@ -1284,134 +1415,6 @@ void parseArray(js_function &rootScope, std::string token) {
}
}

// we handle right value
// we could be in JSON { key:
// we could be in variable bob=
// token: we have a complete expression
// if right is:
// - object
// - array
// - string
// - function
// we could avoid returning, if a pointer to the lvalue is passed in
js_internal_storage *parseExpression(js_function &rootScope, std::string token) {
js_internal_storage *returnValue = nullptr;
size_t cursor;
size_t last = 0;
size_t quoteStart = 0;
size_t quoteEnd = 0;
size_t parenStart = 0;
size_t parenLevel = 0;
unsigned char state = 0;
for (cursor = 0; cursor < token.length(); cursor++) {
// now we haven't to make sure we don't enter {, } or function
// ', " are ok, but have to turn off parsing until we encounter the next
// a-zA-Z$ for variables assignment
switch(state) {
case 0:
switch(token[cursor]) {
case '{':
parenStart = cursor;
parenLevel++;
state = 1;
break;
case '[':
parenStart = cursor;
parenLevel++;
state = 2;
break;
case '\'':
quoteStart = cursor;
state = 4;
break;
case '"':
quoteStart = cursor;
state = 5;
break;
case ',':
std::string value = "";
if (quoteStart) {
value = token.substr(quoteStart + 1, quoteEnd - quoteStart); // skip the quotes
} else {
value = token.substr(last, cursor - last);
value = trim(value);
}
std::cout << "value[" << value << "] quoted" << quoteStart << std::endl;
// JSON objects will already be assigned and empty
if (value != "") {
js_string *newString = new js_string();
newString->value = value;
}
last = cursor + 1;
state = 0;
quoteStart = 0;
quoteEnd = 0;
break;
}
break;
case 1:
switch(token[cursor]) {
case '{':
parenLevel++;
break;
case '}':
parenLevel--;
if (!parenLevel) {
std::string JSON = token.substr(parenStart + 1, cursor - parenStart);
std::cout << "PE Need to deJSON [" << JSON << "]" << std::endl;
// well we can get a scope back
js_function *objectScope = new js_function;
parseJSON(*objectScope, JSON);
//js_object *newObject = new js_object;
//rootScope.data[json_keys.back()] = *newObject;
last = cursor + 1;
state = 0;
}
break;
}
break;
case 2:
switch(token[cursor]) {
case '[':
parenLevel++;
break;
case ']':
parenLevel--;
if (!parenLevel) {
std::string arrayStr = token.substr(parenStart + 1, cursor - parenStart);
std::cout << "Need to deArray [" << arrayStr << "]" << std::endl;
// well we can get a scope back
js_function *objectScope = new js_function;
parseArray(*objectScope, arrayStr);
//js_object *newObject = new js_object;
//rootScope.data[json_keys.back()] = *newObject;
last = cursor + 1;
state = 0;
}
break;
}
break;
case 4:
if (token[cursor] == '\'') {
if (token[cursor - 1] != '\\') {
quoteEnd = cursor - 1;
state = 0;
}
}
break;
case 5:
if (token[cursor] == '"') {
if (token[cursor - 1] != '\\') {
quoteEnd = cursor - 1;
state = 0;
}
}
break;
}
}
return returnValue;
}

//
void parseJSON(js_function &rootScope, std::string token) {
std::vector<std::string> json_keys;
@@ -1538,6 +1541,15 @@ void parseJSON(js_function &rootScope, std::string token) {
newString->value = value;
assignfile << "JSON." << json_keys.back() << "=_NTRSTRING(,):'" << value << "'\n";
rootScope.locals.value[json_keys.back()] = newString;
} else {
if (quoteStart) {
// likely ""
json_values.push_back("");
js_string *newString = new js_string();
newString->value = "";
assignfile << "JSON." << json_keys.back() << "=_NTRSTRING(,):'" << value << "'\n";
rootScope.locals.value[json_keys.back()] = newString;
}
}
last = cursor + 1;
keyState = 0;
@@ -1678,6 +1690,7 @@ void parseJSON(js_function &rootScope, std::string token) {
jsDisplayScope(&rootScope, 0);
}

// return value is if there was any error (false for error, true for no error)
int doAssignmentLevel = 0;
bool doAssignment(js_function &rootScope, std::string token) {
doAssignmentLevel++;
@@ -1838,6 +1851,10 @@ bool doAssignment(js_function &rootScope, std::string token) {
expression_parts.push_back("?");
trinaryLevel++;
state = 9;
} else if (token[cursor] == 'i' && token.length() > cursor + 2 && token[cursor + 1] == 'n' && token[cursor + 2] == ' ') {
// "property"in object (or new object)
expression_parts.push_back(token.substr(last, cursor - last)); last = cursor + 1;
expression_parts.push_back("in");
}

} else if (state == 1) {
@@ -2023,6 +2040,10 @@ bool doAssignment(js_function &rootScope, std::string token) {
left = lastToken;
state = 1;
}
if (it == "&&") {
// if stack is false...
//return true;
}
// can actually go to 9 (include the space)
std::string first8 = it.substr(0, 8);
if (first8 == "function") {
@@ -2046,192 +2067,36 @@ bool doAssignment(js_function &rootScope, std::string token) {
}
} else if (state == 1) {
if (it == "") continue; // skip empties, don't fire the assignment too early

std::string first8 = it.substr(0, 8);
if (first8 == "function") {
// FIXME: we have params in it...
//cursor = locateFunctionParamsEnd(it, 8); // there's no { here...
prototype = it.substr(9, it.length() - 10);
std::cout << "extracted[" << prototype << "]\n";
state = 3;
} else if (it == "{") {
// FIXME: make sure it's not a function definition!
// could be JSON or a scope
if (it == "{") {
state = 2;
} else if (it == "!") {
negate = true;
} else {
// do assignment
std::string tLeft = trim(left);
std::string value = trim(it);
//std::cout << "left[" << tLeft[0] << "] right[" << tLeft[tLeft.length() - 1] << "]" << std::endl;
if (tLeft[0]=='"' && tLeft[tLeft.length() - 1]=='"') {
//std::cout << "dequoting[" << tLeft << "]" << std::endl;
tLeft=tLeft.substr(1, tLeft.length() - 2);
}

// is value a constant or an other variable
js_internal_storage *storage=nullptr;

// FIXME: too simple, catches quoted strings with . in them
storage = dereferenceObject(value, &rootScope);
/*
size_t dotPos = value.find('.');
if (dotPos != std::string::npos) {
std::cout << "doAssignment - Value Has . might be object deferencing\n";
//displayScope(&rootScope, 0);
std::string baseObj = value.substr(0, dotPos);
//std::cout << "doAssignment - base[" << baseObj << "]" << std::endl;
js_internal_storage *baseStorage = jsLocateKey(&rootScope, baseObj);
if (baseStorage) {
std::string part2 = value.substr(dotPos + 1);
//std::cout << "doAssignment - part2[" << part2 << "]" << std::endl;
js_object *jobj = dynamic_cast<js_object*>(baseStorage);
if (jobj) {
if (jobj->value.find(part2) != jobj->value.end()) {
std::cout << "doAssignment - part2[" << part2 << "] is inside base" << std::endl;
storage = jobj->value[part2]; // we will now point to this storage
} else {
std::cout << "doAssignment - part2[" << part2 << "] not in base" << std::endl;
for(auto it2 : jobj->value) {
std::cout << "[" << it2.first << "]\n";
}
}
} else {
std::cout << "doAssignment - baseStorage couldn't be made a js_object. type[" << typeOfStorage(baseStorage) << "]\n";
}
//
//js_internal_storage *p2Storage = locateKey(&rootScope, value);
} else {
std::cout << "doAssignment - Couldnt find base[" << baseObj << "] in scope" << std::endl;
}
}
*/

if ((value[0] == '"' && value[value.length() - 1] == '"') || (value[0] == '\'' && value[value.length() - 1] == '\'')) {
// it's quote, so definitely a constant
js_string *jstring = new js_string;
jstring->value = value.substr(1, -1);
storage = jstring;
}
if (storage == nullptr) {
if (value == "true") {
js_bool *jbool = new js_bool;
jbool->value = true;
storage = jbool;
} else if (value == "null") {
// FIXME: is null a type?
js_bool *jbool = new js_bool;
jbool->value = false;
storage = jbool;
} else if (value == "false") {
js_bool *jbool = new js_bool;
jbool->value = false;
storage = jbool;
}
}
size_t dotPos;
if (storage == nullptr) {
bool allDigits = true;
for(auto it2 : it) {
if (it2 >= '0' && it2 <= '9') {

} else {
if (it2 != '.') {
allDigits = false;
}
}
}
if (allDigits) {
js_number *jnum = new js_number;
jnum->value = std::stoi(value);
std::cout << "allDigits [" << tLeft << "] value[" << value << "] => jstring[" << jnum->value << "]\n";
storage = jnum;
} else {
// potentially a variable
//jsDisplayScope(&rootScope, 0);
storage = jsLocateKey(&rootScope, value);
if (storage == nullptr) {

// check local parameters
dotPos = value.find('.');
if (dotPos != std::string::npos) {
std::string baseObj = value.substr(0, dotPos);
for(auto it2 : rootScope.parameters) {
std::cout << "param check param[" << it2 << "] == search[" << baseObj << "]\n";
}
if (std::find(rootScope.parameters.begin(), rootScope.parameters.end(), baseObj) != rootScope.parameters.end()) {
// so where do we put this value
// forward declaration
} else {
std::cout << "No [" << baseObj << "] in local prototype either\n";
}
} else {
if (std::find(rootScope.parameters.begin(), rootScope.parameters.end(), value) != rootScope.parameters.end()) {
// so where do we put this value
// forward declaration
} else {
std::cout << "No [" << value << "] in local prototype either\n";
}
}
// forwarding looking variable reference
std::cout << std::string(doAssignmentLevel * 2, ' ') << "doAssignment - creating forward looking ref " << value << "\n";
js_forward *jref = new js_forward;
jref->expression = value;
//jref->ptr = nullptr;
storage = jref;
}
}
}

js_internal_storage *storage = doExpression(rootScope, it);
if (storage) {

bool alreadySet = false;
dotPos = tLeft.find('.');
size_t dotPos = tLeft.find('.');
if (dotPos != std::string::npos) {
js_internal_storage **key = getObjectKeyPointer(tLeft, &rootScope);
if (key != nullptr) {
alreadySet = true;
*key = storage;
}
/*
std::cout << std::string(doAssignmentLevel * 2, ' ') << "doAssignment - Key Has . \n";
std::string baseObj = tLeft.substr(0, dotPos);
std::cout << std::string(doAssignmentLevel * 2, ' ') << "doAssignment - base[" << baseObj << "]" << std::endl;
js_internal_storage *baseStorage = jsLocateKey(&rootScope, baseObj);
if (baseStorage) {
std::string part2 = tLeft.substr(dotPos + 1);
js_object *jobj = dynamic_cast<js_object*>(baseStorage);
if (jobj) {
jobj->value[part2] = storage;
left = ""; // reset left
assignfile << "[" << baseObj << "].[" << part2 << "]=" << value << "\n";
alreadySet = true;
} else {
std::cout << "couldn't cast base[" << baseObj << "] to js_object\n";
}
} else {
std::cout << std::string(doAssignmentLevel * 2, ' ') << "doAssignment - Couldnt find base[" << baseObj << "] in scope" << std::endl;
jsDisplayScope(&rootScope, 0);
}
*/
}
if (!alreadySet) {
std::cout << "doAssignment final assign[" << tLeft << "] of type[" << typeOfStorage(storage) << "] scope[" << &rootScope << "]\n";
rootScope.locals.value[tLeft] = storage;
jsDisplayScope(&rootScope, 0);
left = ""; // reset left
assignfile << tLeft << "=" << value << "\n";
assignfile << tLeft << "=" << it << "\n";
}
} else {
std::cout << std::string(doAssignmentLevel * 2, ' ') << "HALT unknown type [" << value << "]\n";
doAssignmentLevel--;
return false;
std::cout << std::string(doAssignmentLevel * 2, ' ') << "HALT can't get value from [" << it << "]\n";
}

std::cout << std::string(doAssignmentLevel * 2, ' ') << "Assigning [" << tLeft << "=" << value << "]" << std::endl;
state = 0;
}
} else if (state == 2) {
js_function *objectScope = new js_function;
@@ -2317,12 +2182,7 @@ bool doAssignment(js_function &rootScope, std::string token) {
state = 5;
} else if (state == 4) {
if (it == "}") {

//displayScope(&rootScope, 0);

// FIXME: we need to check to see if this function is called
//

state = 5; // reset state
}
} else if (state == 5) { // function definition call check
@@ -2454,6 +2314,8 @@ js_internal_storage **getObjectKeyPointer(const std::string input, const js_func
std::cout << "getObjectKeyPointer - Couldnt find base[" << baseObj << "] in scope" << std::endl;
jsDisplayScope(scope, 0);
}
} else {
// still check our scope for
}
return nullptr;
}
@@ -2484,6 +2346,50 @@ js_internal_storage *dereferenceObject(const std::string input, const js_functio
std::cout << "dereferenceObject - Couldnt find base[" << baseObj << "] in scope" << std::endl;
}
}
dotPos = input.find('[');
if (dotPos != std::string::npos) {
size_t end = input.find(']');
if (end != std::string::npos) {
// we have an open and close
std::string baseObj = input.substr(0, dotPos);
js_internal_storage *baseStorage = jsLocateKey(scope, baseObj);
if (baseStorage) {
std::string part2 = input.substr(dotPos + 1, end - dotPos - 1);
char lastChar = part2[part2.length() - 1];
// probably should run this through doExpression...
// FIXME: "asdf" + var + "zxcv"
if ((part2[0] == '"' && lastChar == '"') || (part2[0] == '\'' && lastChar == '\'')) {
js_object *jobj = dynamic_cast<js_object*>(baseStorage);
if (jobj) {
std::cout << "dereferenceObject bracket style <" << baseObj << ">[<" << part2 << "><" << input.substr(end) << ">\n";
// is constant
std::string constant = part2.substr(1, part2.length() - 2);
std::cout << "constant[" << constant << "]\n";
if (jobj->value.find(constant) != jobj->value.end()) {
std::cout << "dereferenceObject - constant[" << constant << "] is inside base" << std::endl;
return jobj->value[part2]; // we will now point to this storage
} else {
std::cout << "dereferenceObject - constant[" << constant << "] not in base" << std::endl;
for(auto it2 : jobj->value) {
std::cout << "[" << it2.first << "]\n";
}
}
} else {
std::cout << "dereferenceObject - baseStorage[" << baseObj << "] couldn't be made a js_object. type[" << typeOfStorage(baseStorage) << "]\n";
if (typeOfStorage(baseStorage) == "string") {
js_string *jstring = dynamic_cast<js_string *>(baseStorage);
std::cout << "baseStorage string value[" << jstring->value << "]\n";
}
}
} else {
// is variable
std::cout << "dereferenceObject bracket style HALT, expression dereference\n";
}
} else {
std::cout << "dereferenceObject - Couldnt find base[" << baseObj << "] in scope" << std::endl;
}
}
}
return nullptr;
}

@@ -2516,13 +2422,26 @@ js_internal_storage *jsParseTokens(const std::vector<std::string> &tokens, js_fu
// then we'll use !isFalse to figure out if we need to exec this attached scope of code
// also don't forget about the else block and potentially elif
// FIXME: do we have a block start? yes but we won't have the other lines....
// find { (block start)
end = ifStr.find('{');
// if not block start
// else
end = ifStr.find('}');
std::cout << "HALT if not implemented" << std::endl;
return nullptr;
std::cout << "true block start search[" << ttoken.substr(3 + ifCondition.size()) << "]" << std::endl;
size_t start = ttoken.substr(3 + ifCondition.size()).find(')') + 3 + ifCondition.size() + 1; // after the )
end = parseFunctionBody(ttoken, start);
std::cout << "true block[" << ttoken.substr(start, end - start) << "]" << std::endl;
if (conditionRes) {
// a return in an if scope, would return from the function it's in
std::vector<std::string> tokens = jsGetTokens(ttoken, start);
js_internal_storage *val=jsParseTokens(tokens, scope);
std::cout << "value res[" << val << "]\n";
// skip all elses
} else {
// handle else
std::cout << "looking for else [" << ttoken.substr(end) << "]\n";
start = ttoken.substr(end).find("else");
if (start != std::string::npos) {
std::cout << "false condition ELSE not implemented" << std::endl;
}
}
//std::cout << "HALT if not implemented" << std::endl;
//return nullptr;
} else if (ttoken.substr(0, 3)=="var") {
std::string listStr = it.substr(3);
// FIXME: , in quotes or {} (JSON) <= top priority for 4chan
@@ -2676,6 +2595,7 @@ js_internal_storage *jsParseTokens(const std::vector<std::string> &tokens, js_fu

void JavaScript::parse(const std::string source) {
// tokenize source
std::cout << "JavaScript::parse source[" << source << "]\n\n";
this->tokens = jsGetTokens(source, 0);
jsParseTokens(this->tokens, &this->rootScope);
}

読み込み中…
キャンセル
保存