Fix dynamic vars and fields
This commit is contained in:
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
This is a book for my language found [here](https://crosslang.tesseslanguage.com/)
|
This is a book for my language found [here](https://crosslang.tesseslanguage.com/)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Statements and loops
|
## Statements and loops
|
||||||
|
|
||||||
|
|
||||||
@ -22,6 +20,25 @@ var myVariable = 42;
|
|||||||
myVariable = "I have set the variable to a string";
|
myVariable = "I have set the variable to a string";
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Reflective variables
|
||||||
|
|
||||||
|
```js
|
||||||
|
var nameOfVariable = "Var 1";
|
||||||
|
.[nameOfVariable] = 42; //the variable name in this instance will be Var 1
|
||||||
|
Console.WriteLine(.[nameOfVariable]); //prints 42
|
||||||
|
|
||||||
|
|
||||||
|
var nameOfVariable2 = "Var 2";
|
||||||
|
var nameOfField = "This field has spaces and \n New Lines";
|
||||||
|
.[nameOfVariable2] = {
|
||||||
|
.[nameOfField] = "Hello, world"
|
||||||
|
};
|
||||||
|
|
||||||
|
Console.WriteLine(.[nameOfVariable2].[nameOfField]); //should print Hello, world
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
#### If statements
|
#### If statements
|
||||||
|
|
||||||
The {} are optional if you only need one statement
|
The {} are optional if you only need one statement
|
||||||
@ -579,27 +596,3 @@ myHtml = <null>Hello</null>; //would just be Hello (useful for templating as it
|
|||||||
|
|
||||||
myHtml = <raw(stringExpr)>; //allowing you to emit unescaped html from string into html litteral (useful for templating)
|
myHtml = <raw(stringExpr)>; //allowing you to emit unescaped html from string into html litteral (useful for templating)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -766,18 +766,18 @@ namespace Tesses::CrossLang
|
|||||||
if(std::holds_alternative<AdvancedSyntaxNode>(item))
|
if(std::holds_alternative<AdvancedSyntaxNode>(item))
|
||||||
{
|
{
|
||||||
auto tkn = std::get<AdvancedSyntaxNode>(item);
|
auto tkn = std::get<AdvancedSyntaxNode>(item);
|
||||||
if(tkn.nodeName == GetVariableExpression && !tkn.nodes.empty() && std::holds_alternative<std::string>(tkn.nodes[0]))
|
if(tkn.nodeName == GetVariableExpression && !tkn.nodes.empty())
|
||||||
{
|
{
|
||||||
instructions.push_back(new StringInstruction(GetString(std::get<std::string>(tkn.nodes[0]))));
|
GenNode(instructions,tkn.nodes[0],scope,contscope,brkscope,contI,brkI);
|
||||||
GenNode(instructions,item,scope,contscope,brkscope,contI,brkI);
|
GenNode(instructions,item,scope,contscope,brkscope,contI,brkI);
|
||||||
instructions.push_back(new SimpleInstruction(APPENDDICT));
|
instructions.push_back(new SimpleInstruction(APPENDDICT));
|
||||||
}
|
}
|
||||||
else if(tkn.nodeName == AssignExpression && tkn.nodes.size()==2 && std::holds_alternative<AdvancedSyntaxNode>(tkn.nodes[0]))
|
else if(tkn.nodeName == AssignExpression && tkn.nodes.size()==2 && std::holds_alternative<AdvancedSyntaxNode>(tkn.nodes[0]))
|
||||||
{
|
{
|
||||||
auto myTn = std::get<AdvancedSyntaxNode>(tkn.nodes[0]);
|
auto myTn = std::get<AdvancedSyntaxNode>(tkn.nodes[0]);
|
||||||
if(myTn.nodeName == GetVariableExpression && !myTn.nodes.empty() && std::holds_alternative<std::string>(myTn.nodes[0]))
|
if(myTn.nodeName == GetVariableExpression && !myTn.nodes.empty())
|
||||||
{
|
{
|
||||||
instructions.push_back(new StringInstruction(GetString(std::get<std::string>(myTn.nodes[0]))));
|
GenNode(instructions,myTn.nodes[0],scope,contscope,brkscope,contI,brkI);
|
||||||
GenNode(instructions,tkn.nodes[1],scope,contscope,brkscope,contI,brkI);
|
GenNode(instructions,tkn.nodes[1],scope,contscope,brkscope,contI,brkI);
|
||||||
instructions.push_back(new SimpleInstruction(APPENDDICT));
|
instructions.push_back(new SimpleInstruction(APPENDDICT));
|
||||||
}
|
}
|
||||||
@ -1098,7 +1098,7 @@ namespace Tesses::CrossLang
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(varNode.nodeName == GetFieldExpression && varNode.nodes.size() == 2 && std::holds_alternative<std::string>(varNode.nodes[1]))
|
else if(varNode.nodeName == GetFieldExpression && varNode.nodes.size() == 2)
|
||||||
{
|
{
|
||||||
GenNode(instructions,varNode.nodes[0],scope,contscope,brkscope,contI,brkI);
|
GenNode(instructions,varNode.nodes[0],scope,contscope,brkscope,contI,brkI);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user