How user input is being processed (General algorithm) (obsolete!) - abseabse/peos GitHub Wiki

Idea

Each function should perform a check if it gets a proper input, and that check should be just enough to return correct result. For example, function, which disassembles string (on step 2), should not perform the check if the output (dictionary, which goes to the specific functions of the level below) is correct (function below do not raise an error).

Step 1: Initial input check

The only check is this:

  1. Input is not empty. More specifically, it passes regex check: any symbols (before hash symbols) + any number of whitespaces + hash symbol + any number of whitespaces + any symbols (after). This check should be just enough to proof disassembling of input (the next check) will produce at least some results (and not crash).

Step 2: String disassembling

  1. Check the input string;
  2. Split input string into 2 parts with hash symbol as a delimiter;
  3. The first word in the first part becomes a beginning;
  4. The second word in the first part becomes a command word;
  5. Trailing part is converted to a list of tags. At the end, we should have a dictionary, which is passed to the next step – Command choice.

Step 3: Command check

This nonscecific function takes the dictionary from the previous step and checks if this dictionary can be passed to the next step.

Step 4: Command choice

This special function should include:

  1. General check if input is correct (can be procecced by this function);
  2. Defining the first word (user command);
  3. Navigating through dictionary of commands available to define one (exactly one), that is appropriate;
  4. Launching the function associated with this command (mentioned as value for key, in Python terms).

Step 5: Command execution

  1. Specific check if input is correct (the function can be implemented);
  2. Command execution.