'js/ts translate internal commands

I am currently trying to translate some text-based console-log processing into JSON format.

Console.log commands:

give ENTITY.name = "entitytest";
give entity.userid = 99;
give entity.storagenum = 22;
give ENTITY.behaviour = "GIVE entity.storagenum xp to USERID" WHEN entity2.quest = 22

The console input will be processed:

var translatedData = "READ FROM STRING";

result in this kind of translation:

 {
    'entity.name' = "entitytest",
    entity.behaviour: {data: "give entity.storagenum xp to USERID", result: "give 22  xp to 99 when entity2 quest is 22", 
     when: ["entity2.quest": 22}],

}

Thoughts:

  • How will I create this class to build it upon?
  • How can I do the nesting, with multiple behaviours and reasons behind the entity behaviour? How would I be able to build this kind of functionality? I have been trying with javascript, but typescript answers also work.


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source