CLI ~ Future Documentation - uchicago-cs/chiventure GitHub Wiki

For future CLI teams, the Spring 2022 CLI team would like to provide documentation on the current state of the CLI codebase, our motivation behind potentially using Bison, and changes we've made in the existing parsing and commands modules. We hope that our work with Bison will serve as a foundation for future CLI teams to build off of, and build a better, more efficient parsing algorithm through it.

High-level overview of Chiventure CLI before our additions

Changes to the Existing Parser Module

  • Currently, chiventure uses the standard C library for parsing command line inputs. The parser.c and parser.h files contain the code that dictates how the CLI is parsed and passed along to other teams. We serve as the primary point of contact, so it is important that our parser does not contain any major bugs.
  • During the quarter, various updates were made to parser.c. It now can take tokens that are surrounded by quotes, like "dungeon of dragons". An example command would be go to "dungeon of dragons", with the tokens being separated by spaces, and then by quotes if the parser reaches one.
  • Another addition is the helper function remove_fillers, which increases the range of inputs that users can utilize. remove_fillers does exactly what its name implies - it removes any 'filler' words, like "to" and "the" from the command line input. For example, Chiventure previously would output an error if a user inputs "go to the south". It could only take "go south". With the addition of remove_fillers, the two commands are functionally the same. NOTE: remove_fillers completely removes any tokens that are fillers words. It is important that future CLI teams understand what the function does, as accommodations may be needed if other teams would like to implement commands that include those filler words.

Changes to the Existing Commands Module

  • To the commands module, we added functionality to use multiple commands separated by the ';' character. This was implemented using an array of pointers to cmd types. This is very similar to a feature the 'and' command, which allows you to input multiple commands separated by 'and'. Because these were too similar, we changed them slightly, making it such that the 'and' is conditional, meaning that if one of the commands called fail, the rest of the commands will not be executed. On the other hand, commands separated by ';' will execute unconditionally. There are only two current limitations to this. * Firstly, right now there is only a way to check if commands fail to print to the screen, not if commands just overall do not match an action. This could be a good task to implement in the future such that a command is not executed when another command simply isn't found.
  • Secondly, we have to maually allocate space for the multiple 'and' commands, so a max of 5 commands at a time will be allowed, else the program will seg fault.

Changes to the Existing Operations Module

  • We edited the suggestions function in this module, which now uses the Levenshtein Distance formula to output a uggestion when a command is not matched to an action. This formula calculates the minimum number of changes need to make two words equal each other, so the lower the score the more similar they are. The main advantage of this over the previous method is that it will not break when the first letter inputted is not the same as a potential action, and will still give accurate suggestions (see closed issue #1520 in Chiventure Scrumboard for an example of this).
  • Another addition includes the creation of a new action kind, kind 4, which takes in actions of the format ACTION <self>, acting upon a given self-attribute of the player.
  • We also added a function fight_operation, which runs in conjunction with RPG Battle team's run_battle function to initialize and begin a battle with an npc.

Bison parsing library progress

  • Currently Chiventure runs on a student-written parsing mechanism (as detailed above). We spent lot of time this quarter finding a parsing library that could be integrated into Chiventure and expand the possibilities for CLI.
  • While we didn’t have time this quarter to actually integrate Bison into chiventure, most of our work with Bison and Flex had to do with studying how the library works and experimenting with the potential that it has for making the parsing mechanism in chiventure more robust and making it easier to add support for more complex input.
  • Most of our experimentation happened on the cli/sandbox branch in the src/cli/sandbox directory. At the end of the quarter, we directed our Bison work towards constructing a small example parsing module using Bison (in src/cli/examples) that showcases some of the most notable ways Bison supports more complex input than the current parsing mechanism, so as to demonstrate its potential for future years. This example module has a basic model for parsing with Bison and generally supports the current grammar in chiventure, so feel welcome to use/reference it in future years if Bison ends up getting integrated into chiventure.
  • Some of the features showcased in the demo:
    • Taking in and outputting text
    • No input word limit
    • Recognition action key word synonyms
    • Recognizing grammar for specific action kinds
    • Disregarding prepositions, articles, possessive pronouns
  • Features to add (not exhaustive):
    • Case insensitivity
    • A catch-all case
    • More thorough filtering of prepositions, articles, pronouns
    • Connecting to chiventure (:
    • See more

Going Forward

  • In the future, the main goal will be to complete the switch to Bison, as it is a much more versatile and scalable way to parse the input. This will allow for many additional functionalities to be added, and for the current functions to be done more efficiently. We belive it will be challenging to begin the switch, though we have created example and done much of the initial legwork, which should make it easier
  • In parallel to the Bison goal listed above, the team should work in parallel to keep implementing new features into the current Chiventure parsing framework, as these can easily be transferred over to Bison when it is up and running, but it will be good to in the meantime keep boosting the current functionality.
  • Something to work on may be to create a fifth action kind of the format ACTION <npc> to handle interactions with npc’s, such as fight or talk. Potentially helpful reference
⚠️ **GitHub.com Fallback** ⚠️