trokhymchuk / rustParser

0 stars 0 forks source link

iCalendar_parser

The iCalendar file contains event with useful information such as begin/end date, invitee, summary and so on.

The parser is inteneded to take that file and parse it into a Rust struct for easier manipulation of the data. The result of the parsed file would be used to determine in which day a particular person have the most events.

See ASCIINEMA of the parser!

Field Description

BEGIN:VCALENDAR / END:VCALENDAR

VERSION

PRODID


Event Fields

BEGIN:VEVENT / END:VEVENT

UID

ORGANIZER

DTSTART

DTEND

SUMMARY

GEO


Summary

These are the core fields present in the provided iCalendar file. The required fields include:

Grammar rules

vc_calendar = { "BEGIN:VCALENDAR" ~ method? ~ ((version  ~ prodid) | (prodid ~ version)) ~ event* ~ "END:VCALENDAR" }
version     = { "VERSION:" ~ float }
prodid      = { "PRODID:" ~ line }
event       = { "BEGIN:VEVENT" ~ uid ~ organizer ~ dtstart ~ dtend ~ summary ~ geo ~ dsc? ~ "END:VEVENT" }
uid         = { "UID:" ~ email_address }
organizer   = { "ORGANIZER;" ~ "CN=" ~ identifier ~ ":" ~ "MAILTO:" ~ email_address }
dtstart     = { "DTSTART:" ~ datetime }
dtend       = { "DTEND:" ~ datetime }
dsc         = { "DESCRIPTION:" ~ line }
summary     = { "SUMMARY:" ~ line }
geo         = { "GEO:" ~ float ~ "," ~ float }

method             = @{ "METHOD:" ~ ("PUBLISH" | "REQUEST") }
email_address      = @{ (letter_or_digit | "." | "_")+ ~ "@" ~ letter_or_digit+ ~ "." ~ letter_or_digit+ }
datetime           = @{ digit{8} ~ "T" ~ digit{6} ~ "Z" }
identifier         = @{ letter_or_digit+ ~ (" " ~ letter_or_digit+)* }
float              = @{ digit+ ~ "." ~ digit+ }
quoted_string      = @{ "\"" ~ (printable_char ~ ANY)* ~ "\"" }
ascii_alphanumeric = @{ ASCII_ALPHANUMERIC }
printable_char     = @{ '\u{20}'..'\u{21}' | '\u{23}'..'\u{5B}' | '\u{5D}'..'\u{7A}' }
digit              = @{ '0'..'9' }
letter_or_digit    = @{ 'a'..'z' | 'A'..'Z' | '0'..'9' }
comment            =  { ";" ~ (ANY ~ "\n")* }
WHITESPACE         = _{ comment | " " | "\t" | "\n" }
line               = @{ (letter_or_digit | " " | "-" | "/" | "." | "," | ":")* }