Update 'How to Parse'

Sasha Koshka 2022-10-12 07:04:38 +00:00
parent 91f5029b54
commit ceaa92b1dd

@ -12,7 +12,7 @@ These structs are not used outside of their respective modules, and are created
# Operation Methods
All methods of an operation struct are private, since they are called by the aforementioned public facing function. There is one main method that is named after the kind of operation being done (e.g. `LexingOperation.tokenize()`, `ParsingOperation.parse()`). This method runs through the source material, and should generally call dedicated methods when it encounters something that needs to be parsed/lexed. An example of one of these methods would be `LexingOperation.tokenizeNumber()`.
All methods of an operation struct are private, since they are called by the aforementioned public facing function. There is one main method that is named after the kind of operation being done (e.g. `lexingOperation.tokenize()`, `parsingOperation.parse()`). This method runs through the source material, and should generally call dedicated methods when it encounters something that needs to be parsed/lexed. An example of one of these methods would be `lexingOperation.tokenizeNumber()`.
Each of these methods must:
@ -25,4 +25,4 @@ Each of these methods must:
- For example, a method meant to tokenize a string should advance the parser to the rune *after* the closing quotation. This ensures that methods can be properly called one after another.
- If the method consumes an entire line up until a newline, it should advance to the beginning of the next one before exiting.
Methods can return their results in one of two ways. The first, most robust, and most obvious way is for them to simply *return* the result. Sometimes, however, this option is not preferable. In this case, the method should take in a parameter called `into`, which should be a pointer of the "container" in which to put the result. For example, the method `ParsingOperation.parseEnumMembers()` takes in a pointer to an enum struct where the enum members need to go. As it parses each enum member, it adds it to the enum section's member slice. This approach is primarily for methods that parse *multiple* things, and in order to ensure good error handling, it is advisable to handle the parsing of individual items in a separate method.
Methods can return their results in one of two ways. The first, most robust, and most obvious way is for them to simply *return* the result. Sometimes, however, this option is not preferable. In this case, the method should take in a parameter called `into`, which should be a pointer of the "container" in which to put the result. For example, the method `parsingOperation.parseEnumMembers()` takes in a pointer to an enum struct where the enum members need to go. As it parses each enum member, it adds it to the enum section's member slice. This approach is primarily for methods that parse *multiple* things, and in order to ensure good error handling, it is advisable to handle the parsing of individual items in a separate method.