Skip to main content

Module parser

Module parser 

Source
Expand description

The parser: lexed Lines → a typed Database of Rule/Zone/Link records.

The parser is deliberately complete with respect to the source grammar — it parses rules, multi-era zones with UNTIL continuations, and links — independently of what the compiler can currently turn into TZif. Keeping the parser general means:

  • we validate the whole file the way zic does (so we don’t silently ignore typos in rules a selected zone happens not to use); and
  • the compiler inherits a stable, complete front-end as its supported subset grows.

The unsupported-construct decision lives in compile, not here: the parser’s job is to represent the source faithfully; the compiler decides what it can turn into TZif correctly (and fails closed otherwise). Record keywords are matched as zic-style unambiguous prefixes (see the record_keyword helper), so the parser reads both the canonical Rule/Zone/Link spelling and the zishrink-abbreviated R/Z/L form used by the installed single-file tzdata.zi — i.e. zic-rs can parse the real installed source directly.

§Zone continuation handling (the one piece of cross-line state)

A Zone line whose era ends with an UNTIL is continued by the following line(s), which omit the Zone keyword and the name. A line is a continuation iff the previous era carried an UNTIL. We track exactly that with expect_continuation.

Functions§

parse_into
Parse a whole source file’s bytes into db, appending its records.