lean2js

Lean2Js.Ident

source

Imports 1

Whether a name is safe as an identifier in the generated JS #

Checks whether a name is safe as an identifier in the generated JS.

If a user of the subset could name something new or Math or __i53, the artifact would either be a syntax error or trample a runtime helper. Checking names is the compiler's responsibility.

def

Lean2Js.jsReserved

source

Beyond the reserved words, also rejects names that exist as values and break when rebound.

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

      Lean2Js.isIdentStart

      source
      (c : Char) :
      Equations
      Instances For
        Used by
          def

          Lean2Js.isIdentPart

          source
          (c : Char) :
          Equations
          Instances For
            Used by
              def

              Lean2Js.okName

              source
              (s : String) :

              Whether a name is spelled as a JavaScript identifier. Written on the characters rather than through String.front for the reason isReserved is: the reader in Parse has to be shown that a name the compiler let through is one it can read back, and that argument reads the characters.

              Equations
              Instances For
                Used by
                  def

                  Lean2Js.reservedPrefix

                  source

                  Every helper in the generated code starts with __. The prefix is reserved so that user names cannot collide with them.

                  Equations
                  Instances For
                    Used by
                      def

                      Lean2Js.isReserved

                      source
                      (name : String) :

                      The same test as String.startsWith reservedPrefix, written on the characters so that it reduces: the generated code's helper dispatch is guarded by it, and a proof about a call has to see that a name the compiler let through is not a helper.

                      Equations
                      Instances For
                        Used by
                          def

                          Lean2Js.bodyPrefix

                          source

                          The prefix a declaration's unchecked body is named under. Inside the reserved prefix, so nothing a program can write reaches it, and no runtime helper carries a _ in that position, so the two names the compiler writes stay apart from each other as well as from the ones it is given.

                          Equations
                          Instances For
                            Used by
                              def

                              Lean2Js.bodyName

                              source
                              (name : String) :

                              The function a call from inside the package lands on: the declaration's body with no entry check in front of it. The declared name stays with the checked function a consumer imports.

                              Equations
                              Instances For
                                Used by
                                  def

                                  Lean2Js.isBodyName

                                  source
                                  (s : String) :

                                  The same test as String.startsWith bodyPrefix, written on the characters for the reason isReserved is: the helper dispatch and the environment both have to be shown that a name is or is not one of these, and those arguments read the characters.

                                  Equations
                                  Instances For
                                    Used by
                                      theorem

                                      Lean2Js.toList_bodyName

                                      source
                                      (name : String) :
                                      (bodyName name).toList = '_' :: '_' :: 'b' :: '_' :: name.toList
                                      Used by
                                        theorem

                                        Lean2Js.isBodyName_bodyName

                                        source
                                        (name : String) :
                                        Used by
                                          theorem

                                          Lean2Js.isReserved_bodyName

                                          source
                                          (name : String) :
                                          Used by
                                            theorem

                                            Lean2Js.isBodyName_of_unreserved

                                            source

                                            A name the compiler was given is never a body name: validateIdent rejects the whole reserved prefix, and the body prefix is inside it.

                                            Used by
                                              theorem

                                              Lean2Js.bodyName_inj

                                              source
                                              {a b : String} (h : bodyName a = bodyName b) :
                                              a = b
                                              Used by
                                                theorem

                                                Lean2Js.okName_bodyName

                                                source
                                                {name : String} (h : okName name = true) :
                                                Used by
                                                  def

                                                  Lean2Js.validateIdent

                                                  source
                                                  (kind name : String) :
                                                  Equations
                                                  • One or more equations did not get rendered due to their size.
                                                  Instances For
                                                    Used by
                                                      theorem

                                                      Lean2Js.unreserved_of_validateIdent

                                                      source
                                                      {kind name : String} {u : Unit} (h : validateIdent kind name = Except.ok u) :

                                                      Nothing that passed the check carries the helper prefix, which is what keeps a compiled name from colliding with one the compiler introduces itself.

                                                      Used by
                                                        theorem

                                                        Lean2Js.okName_of_validateIdent

                                                        source
                                                        {kind name : String} {u : Unit} (h : validateIdent kind name = Except.ok u) :

                                                        Nothing that passed the check is spelled as anything but an identifier, which is what lets the reader in Parse take a compiled name back.

                                                        Used by
                                                          def

                                                          Lean2Js.validateDistinct

                                                          source
                                                          (kind : String) (names : List String) :
                                                          Equations
                                                          Instances For
                                                            Used by