diff --git a/README.md b/README.md index 4bc7f36..2146abc 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ Tesses Cross Language ![CrossImage](crosslang.png) +> :warning: **NOT READY FOR PRODUCTION (THERE WILL BE BREAKING CHANGES)** + ## What is required to build this project - [TessesFramework](https://onedev.site.tesses.net/tesses-framework) (if you turn CROSSLANG_FETCHCONTENT off otherwise it will be grabbed automaticly) - CMake diff --git a/src/compiler/parser.cpp b/src/compiler/parser.cpp index 8c34f95..04f0bf2 100644 --- a/src/compiler/parser.cpp +++ b/src/compiler/parser.cpp @@ -144,21 +144,21 @@ namespace Tesses::CrossLang nodes.push_back(AdvancedSyntaxNode::Create(CompoundAssignExpression,true,{AdvancedSyntaxNode::Create(AddExpression,true,{AdvancedSyntaxNode::Create(GetVariableExpression,true,{var}),Tesses::Framework::Http::HttpUtils::HtmlEncode(this->tokens[i].whiteSpaceCharsBefore)})})); this->i++; - if(this->IsIdentifier("else",false) || this->IsIdentifier("elif",false)) - { - this->i--; - return; - } if(this->IsSymbol("/")) { + if(this->IsIdentifier("if",false) && tagName == "if") + { + this->i-=2; + break; + } if(!this->IsIdentifier(tagName)) { //error } this->EnsureSymbol(">"); - if(tagName != "if" && tagName != "for" && tagName != "while" && tagName != "do" && tagName != "each") + if(tagName != "if" && tagName != "true" && tagName != "false" && tagName != "for" && tagName != "while" && tagName != "do" && tagName != "each") { std::string myVal = "tokens[this->i++].text; - if(tagName == "if") - { - std::function readIf; - readIf = [this,&parseFn,var,&readIf]()->SyntaxNode { - EnsureSymbol("("); - auto expr = ParseExpression(); - EnsureSymbol(")"); - EnsureSymbol(">"); - - std::vector trueNodes; - - SyntaxNode falseNode=nullptr; - - parseFn(trueNodes,"if"); - - if(this->IsSymbol("<",false) && this->i + 1 < this->tokens.size()) - { - auto tkn = this->tokens[i+1]; - if(tkn.type == LexTokenType::Identifier && tkn.text == "else") - { - i += 2; - EnsureSymbol(">"); - std::vector falseNodes; - parseFn(falseNodes,"if"); - falseNode = AdvancedSyntaxNode::Create(ScopeNode,false,falseNodes); - } - else if(tkn.type == LexTokenType::Identifier && tkn.text == "elif") - { - - i += 2; - falseNode = readIf(); - - } - } - - - return AdvancedSyntaxNode::Create(IfStatement,false,{ - expr, - AdvancedSyntaxNode::Create(ScopeNode,false,trueNodes), - falseNode - }); - } ; - nodes.push_back(readIf()); - } - else if(tagName == "raw") + if(tagName == "raw") { EnsureSymbol("("); SyntaxNode expr = ParseExpression(); @@ -297,6 +253,43 @@ namespace Tesses::CrossLang }) })); } + else if(tagName == "if") + { + EnsureSymbol("("); + SyntaxNode expr = ParseExpression(); + SyntaxNode truth = nullptr; + SyntaxNode falsey = nullptr; + + EnsureSymbol(")"); + EnsureSymbol(">"); + + while(this->IsSymbol("<")) + { + if(this->IsSymbol("/")) + { + if(!this->IsIdentifier("if")) { this->i -= 3;} + this->EnsureSymbol(">"); + break; + } + else if(this->IsIdentifier("true")) + { + this->EnsureSymbol(">"); + + std::vector _nodes; + parseFn(_nodes,"true"); + truth = AdvancedSyntaxNode::Create(ScopeNode,false,_nodes); + + } + else if(this->IsIdentifier("false")) + { + this->EnsureSymbol(">"); + std::vector _nodes; + parseFn(_nodes,"false"); + falsey = AdvancedSyntaxNode::Create(ScopeNode,false,_nodes); + } + } + nodes.push_back(AdvancedSyntaxNode::Create(IfStatement,false,{expr,truth,falsey})); + } else if(tagName == "while") { diff --git a/src/vm/vm.cpp b/src/vm/vm.cpp index 8eaa10a..803cd7b 100644 --- a/src/vm/vm.cpp +++ b/src/vm/vm.cpp @@ -2109,6 +2109,54 @@ namespace Tesses::CrossLang { return false; } } + if(key == "EndsWith") + { + std::string v; + if(GetArgument(args,0,v)) + { + if(str.size() < v.size()) { + cse.back()->Push(gc,false); + return false; + } + + size_t _end = str.size()-v.size(); + for(size_t i = 0; i < v.size(); i++) + { + if(v[i] != str[i+_end]) + { + cse.back()->Push(gc,false); + return false; + } + } + cse.back()->Push(gc,true); + return false; + } + cse.back()->Push(gc,false); + return false; + } + if(key == "StartsWith") + { + std::string v; + if(GetArgument(args,0,v)) + { + if(str.size() < v.size()) { + cse.back()->Push(gc,false); + return false; + } + for(size_t i = 0; i < v.size(); i++) + { + if(v[i] != str[i]) + { + cse.back()->Push(gc,false); + return false; + } + } + cse.back()->Push(gc,true); + return false; + } + cse.back()->Push(gc,false); + return false; + } if(key == "Escape") { bool quote;