Browse Source

some prototype, add bool/reference

master
Odilitime 4 years ago
parent
commit
577f820f4c
  1. 29
      src/parsers/scripting/javascript/JSParser.h

29
src/parsers/scripting/javascript/JSParser.h

@ -13,11 +13,14 @@ @@ -13,11 +13,14 @@
// blocks/scopes?
class js_internal_storage {
public:
// toBool
// toString
// toNumber
// toFunction
// toArray
// toObject
// toReference
virtual ~js_internal_storage() = default;
};
class js_scope {
@ -30,12 +33,18 @@ public: @@ -30,12 +33,18 @@ public:
parent = nullptr;
}
std::map<std::string, std::string> variables;
std::map<std::string, js_internal_storage> data;
std::map<std::string, js_internal_storage *> data;
// maybe a vector of resolve on execution assignments...
// feel like we need an instruction pointer...
// esp. for loops
// but how we address tokens, by index?
};
class js_bool : public js_internal_storage {
public:
bool value;
};
class js_string : public js_internal_storage {
public:
std::string value;
@ -49,8 +58,7 @@ public: @@ -49,8 +58,7 @@ public:
class js_function : public js_internal_storage {
public:
std::vector<std::string> tokens;
js_scope *parent; // usually global
js_scope local;
js_scope scope;
};
class js_array : public js_internal_storage {
@ -60,10 +68,19 @@ public: @@ -60,10 +68,19 @@ public:
class js_object : public js_internal_storage {
public:
std::map<std::string, js_internal_storage> value;
// I think 2nd needs to be a pointer...
std::map<std::string, js_internal_storage *> value;
};
class js_reference : public js_internal_storage {
public:
js_internal_storage *ptr;
};
bool doAssignment(js_scope &rootScope, std::string token);
size_t parseFunctionBody(std::string source, size_t start);
size_t getNextExpression(const std::string source, const size_t start);
class JavaScript {
public:
@ -85,9 +102,11 @@ js_internal_storage *parseExpression(js_scope &rootScope, std::string token); @@ -85,9 +102,11 @@ js_internal_storage *parseExpression(js_scope &rootScope, std::string token);
void parseArray(js_scope &rootScope, std::string token);
void parseJSON(js_scope &rootScope, std::string token);
// this is no members could all be static
class JSParser {
public:
std::shared_ptr<JavaScript> parse(const std::string &javascript) const;
//std::shared_ptr<JavaScript> parse(const std::string &javascript) const;
void parseTokens(const std::vector<std::string> &tokens, js_scope *scope) const;
std::vector<std::string> getTokens(const std::string &source) const;
std::shared_ptr<JavaScript> append(std::shared_ptr<JavaScript> &destination, const std::shared_ptr<JavaScript> &source) const;
};

Loading…
Cancel
Save