From 577f820f4c89e6d02802dc6e48e8062c6e167652 Mon Sep 17 00:00:00 2001 From: Odilitime Date: Sun, 24 Dec 2017 09:56:30 -0800 Subject: [PATCH] some prototype, add bool/reference --- src/parsers/scripting/javascript/JSParser.h | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/parsers/scripting/javascript/JSParser.h b/src/parsers/scripting/javascript/JSParser.h index d10fc45..f8d845f 100644 --- a/src/parsers/scripting/javascript/JSParser.h +++ b/src/parsers/scripting/javascript/JSParser.h @@ -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: parent = nullptr; } std::map variables; - std::map data; + std::map 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: class js_function : public js_internal_storage { public: std::vector tokens; - js_scope *parent; // usually global - js_scope local; + js_scope scope; }; class js_array : public js_internal_storage { @@ -60,10 +68,19 @@ public: class js_object : public js_internal_storage { public: - std::map value; + // I think 2nd needs to be a pointer... + std::map 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); 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 parse(const std::string &javascript) const; + //std::shared_ptr parse(const std::string &javascript) const; + void parseTokens(const std::vector &tokens, js_scope *scope) const; std::vector getTokens(const std::string &source) const; std::shared_ptr append(std::shared_ptr &destination, const std::shared_ptr &source) const; };