Documentation

Core.Go.Pretty

Pretty-printing for Core/Go/Syntax.lean. Unlike every other Pretty.lean in this repo, this one is not a debug dump — it is Network2Go's code generator: the .go file the compiler ships is whatever this module prints. (Guarded2Network has no pretty-printer at all and dumps via reprStr; that path stays for -d dump-network, and -d dump-go will reuse this one.)

Go's 25 reserved words. These can never be identifiers, in any position, so the printer escapes them unconditionally.

Exported alongside predeclared so that Network2Go can rename a user-chosen name out of this set rather than leaving it to sanitize below — a rename that knows the name's provenance can pick a spelling that stays distinct from every other name, which a blind suffix cannot.

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

    Go's predeclared identifiers — types, constants and builtin functions living in the universe block. Unlike keywords these are ordinary identifiers that a declaration may legally shadow, so the printer must not escape them: the generated code refers to int, any, comparable, error and append/len/make by name constantly, and escaping them would turn those into int__/comparable__.

    A user-chosen name colliding with one of these still has to be renamed — shadowing int in a file that also emits int for TLA⁺'s Int would silently change what the generated code means. That rename belongs to Network2Go, which is the only place that knows whether a name came from the specification or from the compiler; this set is exported for it to consult. Hygiene is enforced per pass, not only by the printer.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      @[inline]
      def Go.sanitize (name : String) :

      Escape an identifier that would otherwise be a Go reserved word. Applied at every identifier-print site — a backstop, not the whole hygiene story: see predeclared.

      Unreachable for anything Network2Go emits, which renames user-chosen names out of keywords itself; this catches only a name reaching the printer from somewhere that did not.

      The suffix is a single _, because Network2Go spends underscore-run parity to separate user-written names from compiler-introduced ones: a doubled suffix lands in the user half, so type and a user's own type_ would both print type__. An odd-length suffix cannot collide with either.

      Equations
      Instances For
        @[implicit_reducible]
        Equations
        partial def Go.Ref.pretty {Expr : Type} (f : ExprStd.Format) :
        Ref ExprStd.Format

        Takes the expression formatter as an argument rather than resolving it from Std.ToFormat: Ref is printed from inside the Expression/Statement mutual block below, where the instance for Expression does not exist yet.

        @[implicit_reducible]
        instance Go.instToFormatRef {Expr : Type} [Std.ToFormat Expr] :
        Equations
        partial def Go.Expression.pretty {α : Type} [Std.ToFormat α] (e : Expression α) (prec : ) :
        @[implicit_reducible]
        Equations
        @[implicit_reducible]
        Equations
        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          @[implicit_reducible]
          Equations

          A top-level declaration. The var form spells its type even when there is an initializer, so that a nil-valued or otherwise uninferable right-hand side still declares the right thing, and because the compilation listings do.

          Equations
          Instances For