taalhavras / ucal

a martian calendar
53 stars 6 forks source link

Valarm parsing #2

Closed taalhavras closed 4 years ago

taalhavras commented 4 years ago

Code Breakdown: ucalendar-test.hoon: A generator that parses a calendar file (txt) at the path passed as an argument.

components.hoon: File containing definitions of various types used to represent the parsed ics file. Should be fairly self explanatory.

parser.hoon: Where the rubber meets the road. Contains logic for going from a path to a vcalendar (via calendar-from-file). Here's a high level overview of what happens during this process, along with the code that corresponds to each part.

  1. Read the file and "unfold" the lines. see ++read-file and 1++unfold-lines` unfolding is explaned in section 3.1 of rfc 5545

  2. Now that we've gotten the lines, we call ++parse-calendar to produce a calendar. This function follows a similar pattern to vevent parsing. There's a tag type (vcal-tag) representing the properties we're looking for (in this case, just version and prodid), and a required-tags type that has a flag for each of the tags. After isolating the lines we want, pass them to ++parse-calendar-props. This function goes through the lines, calling parser functions based on the tag's value. The parsers all consume the tape containing the tag's data, the calendar, and a required-tags object. They produce an updated calendar and required-tags. This lets us ensure that all required tags are parsed and lets us build our calendar incrementally. This is very similar to how vevents are parsed - there's some extra bookkeeping necessary since some tags are unique but not required, but it's the same fundamental idea.

  3. Once we have a calendar, we can start parsing vevents. We get all the indices where events begin/end, and pass the lines for each event to parse-vevent. This is the meat of the code and while it's long, it follows the same basic structure as the calendar parsing code did.

  4. valams are a subcomponent that can be nested within vevents. The code for parsing them can be found in ++parse-valarm. It's structured a little differently from the code in ++parse-calendar-props and ++parse-vevent because it simplified things. This code was written the most recently, so this method of parsing might be ported back to vevents and calendars as well at some point (if it proves to be an actual simplification in those cases).