Create SOQL Code generator from AST generated by Peg parser

Register
Submit a solution
The challenge is finished.

Challenge Overview

Requirements

For a given SOQL Abstract Syntax Tree (AST), we should be able to generate valid SOQL code.

You should use the AST generated by the FinancialForce SQOL parser (apply for access in the forums if you dont currently have access).

Use the TreeWalker/AST Traverser available here (apply for access in the forums if you dont currently have access).

Resources

 

var GherkinGenerator = {};

GherkinGenerator.generate = function (ast) {

   var gherkinGeneratedFeature = [];

   TreeWalker.traverse(ast, {
       enter : function (node, parent) {
           var nodeText = GherkinGenerator[node.type + '_enter'](node, parent);
           if (nodeText) gherkinGeneratedFeature.push(nodeText);
       },

       leave : function (node, parent){
           var nodeText = GherkinGenerator[node.type + '_leave'](node, parent);
           if (nodeText) gherkinGeneratedFeature.push(nodeText);
       }
   });

   return gherkinGeneratedFeature.join('');
};

GherkinGenerator.Feature_enter = function (node, parent) {
   var Feature = "";

   Feature +=  node.keyword + ":" + node.name + NEWLINE;
   if(node.description)
       Feature += node.description;

   return Feature;
};

GherkinGenerator.Scenario_enter = GherkinGenerator.ScenarioOutline_enter = function (node, parent) {
   var Scenario = "";
   Scenario +=  node.keyword + ":" + node.name + NEWLINE;
   if(node.description)
       Scenario += NEWLINE + node.description;

   return Scenario;
};

GherkinGenerator.Background_enter = function (node, parent) {
   var Background = "";

   Background += TAB + node.keyword + ":" + node.name;

   return Background;
};

// No-op when we leave the node.
GherkinGenerator.Feature_leave =
   GherkinGenerator.Scenario_leave =
   GherkinGenerator.ScenarioOutline_leave =
   GherkinGenerator.Background_leave =
   GherkinGenerator.Step_leave =
   GherkinGenerator.DocString_leave =
   GherkinGenerator.Tag_leave =
   GherkinGenerator.DataTable_leave =
   GherkinGenerator.TableRow_leave =
   GherkinGenerator.TableCell_leave =
   GherkinGenerator.Examples_leave = function(){};

We would then pass the JSON AST to GherkinGenerator.generate and we get back a string which would be the regenerated code.

Repo/Housekeeping

  • You will need to base your work off the git repository provided.

  • You will be required to handle any merge issues that occur from your submission.

Coding Standards

  • All code should be fully unit tested and documented. Please use best practise here (you do not need to document getters and setters, etc)!

  • All existing tests should be fully maintained (ie if you make a change to the existing functionality that breaks a test you need to fix that).

 



Final Submission Guidelines

Code

 

  • All source code must be well commented and following JavaScript best practices

 

Video

 

  • Please provide a demo video covering both a functional demo as well as code walkthrough of your parser implementation

 

Documentation

 

  • Please provide a Deployment Guide containing configuration, installation and verification information as a Word document.

Any submissions which do not include any of the above artefacts will be outrightly rejected.

 

 

Review style

Final Review

Community Review Board

Approval

User Sign-Off

Challenge links

ID: 30053780