rintolang / rinto

In-development open source programming language based on C/C++
https://rintolang.github.io
GNU General Public License v3.0
3 stars 2 forks source link

Finished CMD initial functionality #6

Closed rohan221102 closed 1 year ago

zeim839 commented 2 years ago

Firstly, remove the process and cmd folders. The entirety of the cmd package's functionality should (and easily can) be concentrated into a single pair of cmd.h and cmd.cpp files.

The help section should look like this:

rin is a tool for managing Rinto source code.

Usage:

        rin <command> [flags]

The commands are:

         help        display useful help instructions
         scan        scan a .rin file into its constituent tokens.
         (more to be added later)

Use "rin help <command>" for available flags and more information about a command. 

Note the usage section, a command (an option from "the commands are" section) appears first, then a series of flags follows. So a call to the rin command line application is essentially a single command and then a series of flags. A flag is any word that begins with '--' or '-'.

Given this, the 'cmd.h' file should look like so:

#ifndef CMD_H
#define CMD_H

#include "Scanner.h"
#include <vector>
#include <string>

typedef struct {
        std::string              Cmd;
        std::vector<std::string> Flags;
} ArgCmd;

typedef struct {
        std::string Name;
        std::string ShortHelp;
        std::string LongHelp;
} CmdHelp;

class CMD: private Scanner
{
private:
        std::string VersionStr = "0.0.1";
        std::string HelpStr;

        ArgCmd Arg;
        std::vector<CmdHelp> Commands;

        /*
         * Parses argv.
         * TODO:
         * 1. Arguments should be whitespace seperated, meaning you should
         *    probably write a separate function to skip \n, space and \t
         *    characters until it finds an alphanumeric char.
         * 2. Once the first alphanum char is detected, read it unti you
         *    encounter whitespace again (ensure that the whitespace char
         *    is not included) and isolate the word into its own string
         *    var.
         * 3. If the word doesnt start with a "--", then it is a command.
         *    If you detect a command, create an ArgCmd and set Cmd to
         *    the string of the word you just encountered.
         * 4. If the word starts with a '--', then it is a flag. Gather
         *    each flag and insert it into your ArgCmd's Flags vector.
         *    Note that flags are options for commands, so any flag following
         *    a command is added to that command's ArgCmd structure. If a flag
         *    is detected before the first command, then you print help as
         *    this is an error.
         * 5. Set your detected command to the CMD attriute 'Arg'. Note that
         *    each call to the cmd program should only be 1 command. So if
         *    multiple commands are detected then you have an error.
         */
        void parseArgs();

        /*
         * TODO:
         * Once args are parsed, execArgs should handle execution of the user's
         * command and flags. This should be a switch statement on Arg.Cmd. If
         * the command is unknown, printHelp().
         */
        void execArgs();

        /*
         * TODO
         * 1. Print the generic help text (HelpStr).
         * 2. Iterate through Commands and print their name
         *     and ShortHelp texts.
         */
        void printHelp();

        // Processes commands related to the scanner package. You may ignore this for now.
        void pScanner();
public:
        /*
         * TODO
         * 1. Initialize HelpStr
         * 2. Initialize Commands vector.
         */
        CMD(int argc, char* argv[]);
};

#endif /* CMD_H */

Each available command (help, scanner) should be accompanied by a CmdHelp. The CmdHelp keeps its short description (to be printed on rin help) and its long description (printed when user calls rin help <command>. If CmdHelp definitions prove to be tedious/repetitive, you may want to create a separate flags.h file.

@rohan221102

zeim839 commented 1 year ago

I'm currently rewriting the project as a front-end to the GCC compiler. I will be putting this PR on hold for the time being.

rohan221102 commented 1 year ago

👍

On Mon 15 Aug 2022 at 14:28, zeim839 @.***> wrote:

@.**** commented on this pull request.

In README.md https://github.com/rintolang/rinto/pull/6#discussion_r945599960:

-Watch this thread to see how this development goes! +# Website +rintolang.github.io

Can you also add the website on the repository's about section?

— Reply to this email directly, view it on GitHub https://github.com/rintolang/rinto/pull/6#pullrequestreview-1072469892, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKQCXXGBXBOIY47Y56BHYKDVZILUTANCNFSM545EMLWQ . You are receiving this because you were assigned.Message ID: @.***>