Update 'How to Parse'
parent
785d3a96a9
commit
e05fbde3f9
@ -23,5 +23,6 @@ Each of these methods must:
|
||||
4. Run through until the end, gathering the result
|
||||
5. Advance the operation struct to the element *after* the end, if need be
|
||||
- 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.
|
Reference in New Issue
Block a user