Code Monkey home page Code Monkey logo

ont's Issues

Parse `unions` in ont!

Hello! So the ont parser currently does not use unions and this issue is here to change that! If you could think of a suitable implementation for the union great!

The ont parser parses a line of code and then turns it into c++ code. It is a bit like herb sutter's cpp2/cppfront int that it is a different syntax to c++ but eventually it gets parsed into c++. If you aren't familiar with this just have a look around main.cpp found in the code section of this repository!

The layout needs to be as follows:

  • First we need to add it to the function is_keyword near the top of the main.cpp header file. By doing if(s == "YOUR_KEYWORD), note that your YOUR_KEYWORD is the keyword that you choose for the union.
  • Then you need to add an else if(possible_keyword == "YOUR_KEYWORD") to the parse member function. And then parse the input.
  • You will need to only deal with one line of code. That one line of code will be contained in str_.
  • Please use std::string for dealing with the strings.
  • Finally you will need to push_back the finished string onto the vector called dotcppfile which will be how the user will be able to see their input changed into c++ code.
  • OPTIONAL: You can also add an example to the main function using the function parse and passing in your 'ont' code. You could also even add documentation to the readme section of this repository if you were really going for it!

So we will need a keyword here are a few ideas:

  • collection
  • bond
  • together
  • seal

You could just change the keyword and then keep the rest of the union implementation the same!

If you are confused here is an example, the following should be passed to parse (well something similiar because at the end of the day it is whatever you choose is suitable!):

parse("collection c{int a; char b; float c;};");

Then the generated code should be as follows, this will be in the dotcppfile vector!

union c {int a, char b, float c};

Here is an example of how else if(possible_keyword == "YOUR_KEYWORD") might look in the parse member function:

// Other else if's before.
else if(possible_keyword == "YOUR_KEYWORD")
{
    // This is so that the outputed string will be correctly indented
    std::string FINISHED_STRING{amount_str(indent)}; // notice amount_str(indent) is needed.
    // This is where we hold the finished string.

    std::string rest = str_.substr(strlen(12, str_.size());
    // we are making a substring of the string not including the keyword that we are matching.

    // Then we finish parsing, accepting as many types in the *union* as possible. But remember all on one line!

    dotcppfile.push_back(FINISHED_STRING);
}

Any help is greatly appreciated. Thankyou in advance! If you have any questions just comment below in this issue!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.