From 2eb1f773b0b16eeef213bc5739f07551814b3fbe Mon Sep 17 00:00:00 2001 From: Artemy Date: Sun, 14 Aug 2022 23:34:04 +0300 Subject: [PATCH] doc: for 0.3.0 --- ROADMAP.md | 7 ++--- doc/main.md | 28 ++++++++++++++++++++ examples/example.json5 | 59 +++++++++++++++++++++++++++++++++++------- 3 files changed, 81 insertions(+), 13 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index 9a2a2ce..d55a68e 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -7,8 +7,8 @@ - [ ] methods for arrays - [ ] methods for strings - [ ] methods for objects -- [ ] writing objects to a variable -- [x] yaml support? +- [x] writing objects to a variable +- [x] yaml support - [ ] command execution function - [ ] function for random - [x] delete variable @@ -16,6 +16,7 @@ - [ ] checking variable type - [x] checking for the existence of a variable - [x] create scopes without if, else, loop -- [ ] calculate values in arrays +- [x] calculate values in arrays +- [x] References for variables in variables and something else diff --git a/doc/main.md b/doc/main.md index 3b92161..0ab3c2c 100644 --- a/doc/main.md +++ b/doc/main.md @@ -90,6 +90,34 @@ works only with numbers (and variables with number type) calculated: { calc: [{ var: "num" }, "*", 4] }, //result 8 }, }, + + { + let: { + referenceVar: { ref: "calculated" }, + }, + //creates a reference variable, when the "calculated" + // is changed, "referenceVar" will also be changed, in the + // future it will be possible to change "referenceVar" + // and the "calculated" will be changed + }, + + { + let: { + array: { arr: [{ var: "num" }, 4] }, //create calculated array result [2, 4] + }, + }, + + { + let: { + objVar: { obj: { var: "num" } }, //create object (hashmap) variable result {var: "num"} + }, + }, + + { + let: { + wrongObjVar: { var: "num" }, //result 2 + }, + }, ] ``` diff --git a/examples/example.json5 b/examples/example.json5 index 1a13054..4700c96 100644 --- a/examples/example.json5 +++ b/examples/example.json5 @@ -132,6 +132,21 @@ str: "A", num: 2, arr: ["Array", "in", "variable"], + obj: { + obj: { + arr: ["i'm array", "!"], + string: "I'm string!", + calculated: { calc: [2, "*", 2] }, + }, + }, + }, + }, + + { + let: { + calcArr: { + arr: ["Some str", { var: "num" }], + }, }, }, @@ -142,15 +157,19 @@ }, [ - "Created 4 variables with values:\n", + "Created 6 variables with values:\n", "str = ", { var: "str" }, "\nnum = ", { var: "num" }, "\narr = ", { var: "arr" }, + "\nobj = ", + { toString: { var: "obj" } }, "\ncalculated (num * 4) = ", { var: "calculated" }, + '\ncalculated array ["Some str", num] = ', + { var: "calcArr" }, ], "Execute calculated = calculated + 1", @@ -175,7 +194,7 @@ loop: [ { if: { - condition: { comp: [{ var: "num" }, ">=", 100000] }, + condition: { comp: [{ var: "num" }, ">=", 10000] }, body: ["break"], }, }, @@ -204,7 +223,7 @@ }, { if: { - condition: { comp: [{ var: "calculated" }, ">=", 100000] }, + condition: { comp: [{ var: "calculated" }, ">=", 10000] }, body: ["\n", "break"], }, }, @@ -213,17 +232,17 @@ { if: { - condition: { comp: [{ var: "calculated" }, ">=", 99999] }, - body: [["сalculated is >= ", 99999]], - else: [["сalculated is < ", 99999]], + condition: { comp: [{ var: "calculated" }, ">=", 9999] }, + body: [["сalculated is >= ", 9999]], + else: [["сalculated is < ", 9999]], }, }, { if: { - condition: { comp: [{ var: "calculated" }, ">", 100000] }, - body: [["сalculated is > ", 100000]], - else: [["сalculated is <= ", 100000]], + condition: { comp: [{ var: "calculated" }, ">", 10000] }, + body: [["сalculated is > ", 10000]], + else: [["сalculated is <= ", 10000]], }, }, @@ -262,5 +281,25 @@ name: { input: "Your name: " }, }, }, - { print: ["Bye, ", { var: "name" }, "!"] }, + ["Hey, ", { var: "name" }, "!"], + + "Check a var references", + '\nCreate variable refToName with reference variable "name"', + { + let: { + refToName: { ref: "name" }, + }, + }, + + ["refToName = ", { var: "refToName" }], + + "Try assign name with new value", + { + assign: { + name: { input: "Any name: " }, + }, + }, + "", + ["name = ", { var: "name" }], + ["refToName = ", { var: "refToName" }], ]