Documentation

Cedar.Thm.Ext.IPAddr.Grammar

IPAddr grammar: definitions #

This file contains only the grammar-level definitions: the well-formedness predicates, component value functions, and relational value specification. IsWfIPNet states the syntax, v4Value/v6Value give the denotation of identified components, and IsIPNetValue str net combines those same witnesses to say that str denotes net. The lemmas connecting these definitions to IPAddr.parse live in Cedar.Thm.Ext.IPAddr.Lemmas.

The accepted syntax (transcribed from the spec parser) is, informally:

IPNet    ::= V4Net | V6Net          -- V4 tried first; a string is V6 only if it is not V4
V4Net    ::= V4Addr ['/' V4Prefix]
V4Addr   ::= NumV4 '.' NumV4 '.' NumV4 '.' NumV4
NumV4    ::= Digit{1,3}             -- no leading zeros unless the group is exactly "0"; value ≤ 255
V4Prefix ::= Digit{1,2}            -- no leading zeros unless exactly "0"; value ≤ 32

V6Net    ::= V6Addr ['/' V6Prefix]
V6Addr   ::= a `::`-compressed sequence of hextets that expands to exactly 8 groups
NumV6    ::= HexDigit{1,4}          -- value ≤ 0xffff (automatic from ≤ 4 hex digits)
V6Prefix ::= Digit{1,3}            -- no leading zeros unless exactly "0"; value ≤ 128

The :: compression may appear at most once and denotes a run of zero hextets that pads the total to 8 groups.

Shared digit/number-token predicates #

A Digit⁺ string that additionally forbids a leading zero unless it is exactly "0" — the "no leading zeros" rule the spec parser enforces on every numeric group and prefix (str.startsWith "0" → str = "0").

Equations
Instances For

    IPv4 grammar #

    V4Addr is four dot-separated groups, each a canonical 1–3 digit number ≤ 255; the optional prefix is a canonical 1–2 digit number ≤ 32.

    The grammar's V4Addr ::= NumV4 '.' NumV4 '.' NumV4 '.' NumV4: four decimal groups.

    Instances For

      Each group is a canonical number of at most 3 digits.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For

        Each group's value is at most 255 (0xff).

        Equations
        Instances For

          Render a V4Addr as g₀ '.' g₁ '.' g₂ '.' g₃.

          Equations
          Instances For

            The IPv4Addr value of well-formed V4 groups.

            Equations
            Instances For

              IPv6 grammar #

              V6Addr is a ::-compressed sequence of hextets. Rather than model the compression syntactically here, a V6Components record holds the eight expanded hextets together with the rendering (the concrete ::-form string), and well-formedness is phrased existentially over that rendering (as in the duration/datetime grammars). Each hextet is a 1–4 character hex-digit string.

              A Digit⁺-style predicate for hex groups: a non-empty string all of whose characters are hex digits, of length at most 4.

              Equations
              Instances For

                Numeric value of a hex group (Σ digit · 16ⁱ), matching the spec parser's foldl.

                Equations
                Instances For

                  A V6 address, as the spec parser accepts it: either a full list of hextets with no :: compression, or a ::-compressed form with a left and right list of hextets and an implicit run of zero hextets between them. This mirrors parseSegsV6's splitOn "::":

                  • full gs ↔ the string has no ::; gs is the ':'-separated hextet list;
                  • gap l r ↔ the string is l₀:…:lₘ '::' r₀:…:rₙ; the gap expands to 8 − (|l|+|r|) zero hextets.
                  Instances For

                    The eight expanded hextet strings a V6Components denotes: the full list itself, or the two sides padded with the appropriate number of "0" hextets between them.

                    Equations
                    Instances For

                      Syntactic well-formedness of a V6 address:

                      • every present hextet is a valid 1–4 digit hex group;
                      • the full form has exactly 8 hextets (no :: ⇒ splitToList ':' must give 8);
                      • the gap form's two sides total strictly fewer than 8 (so the :: denotes ≥ 1 zero hextet — parseSegsV6 requires len < 8).
                      Equations
                      Instances For

                        Render a V6 address to its concrete string: hextets joined by ':', with "::" at the gap. (intercalate ":" matches the parser's splitToList (· = ':') / splitOn "::" inverse.)

                        Equations
                        Instances For

                          The IPv6Addr value: the eight expanded hextets' hex values. Well-formedness guarantees expand has length 8; on other lengths this defaults the missing groups to 0.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For

                            Prefix grammar #

                            An optional CIDR suffix '/' Prefix, where Prefix is a canonical decimal number bounded by the address width (≤ 32 for V4, ≤ 128 for V6). Absence of the suffix denotes the full-width prefix (ADDR_SIZE).

                            The optional prefix, with its digit-count and value bounds (digits, size) ((2, 32) for V4, (3, 128) for V6). none is the implicit full-width prefix.

                            Equations
                            Instances For

                              Top-level well-formedness #

                              An IP-net string is well-formed when it is either a well-formed V4 rendering or a well-formed V6 rendering (with V4 taking precedence, mirroring the parser's if ipv4.isSome then … else …). Both are phrased existentially over the components' asString rendering (as in the duration/datetime grammars), baking the separators, group count, and ::-compression rules into the witness.

                              The IPv4 grammar production witnessed by address components and an optional CIDR prefix.

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For

                                A well-formed IPv4-net string has a valid IPv4 grammar production.

                                Equations
                                Instances For

                                  The IPv6 grammar production witnessed by address components and an optional CIDR prefix.

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For

                                    A well-formed IPv6-net string has a valid IPv6 grammar production.

                                    Equations
                                    Instances For

                                      A string is a well-formed IP-net iff it is a well-formed V4 or V6 net. Because the parser tries V4 first and only falls through to V6 when V4 fails, and the two grammars are disjoint on their accepted strings, this disjunction faithfully characterizes acceptance.

                                      Equations
                                      Instances For

                                        Value relation #

                                        The component value functions are independent of the parser. The relational definitions below tie those values to the same witnesses used by the syntax predicates, so no second string decoder is needed.

                                        The IPNet value of a well-formed V4 string's components.

                                        Equations
                                        Instances For

                                          The IPNet value of a well-formed V6 string's components.

                                          Equations
                                          Instances For

                                            net is the value of a well-formed IPv4-net rendering.

                                            Equations
                                            Instances For

                                              net is the value of a well-formed IPv6-net rendering.

                                              Equations
                                              Instances For

                                                net is the value of the IP-net literal str, through either the V4 or V6 production.

                                                Equations
                                                Instances For

                                                  Canonical-form normalizer: parse the string and re-serialize. Returns none for malformed inputs.

                                                  Equations
                                                  Instances For