Lean2Js.Ident
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.
Lean2Js.jsReserved
sourceBeyond 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
Lean2Js.isIdentStart
sourceInstances For
Used by
Lean2Js.isIdentPart
sourceEquations
Instances For
Used by
Lean2Js.okName
sourceWhether 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
- Lean2Js.okName s = match s.toList with | [] => false | c :: cs => Lean2Js.isIdentStart c && (c :: cs).all Lean2Js.isIdentPart
Instances For
Used by
Lean2Js.reservedPrefix
sourceEvery helper in the generated code starts with __. The prefix is reserved so that user names cannot
collide with them.
Equations
- Lean2Js.reservedPrefix = "__"
Instances For
Used by
Lean2Js.isReserved
sourceThe 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.
Instances For
Used by
Lean2Js.bodyPrefix
sourceThe 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
- Lean2Js.bodyPrefix = "__b_"
Instances For
Used by
Lean2Js.bodyName
sourceThe 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
- Lean2Js.bodyName name = Lean2Js.bodyPrefix ++ name
Instances For
Used by
Lean2Js.isBodyName
sourceThe 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
Lean2Js.toList_bodyName
sourceUsed by
Lean2Js.isBodyName_bodyName
sourceUsed by
Lean2Js.isReserved_bodyName
sourceUsed by
Lean2Js.isBodyName_of_unreserved
sourceA 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
Lean2Js.bodyName_inj
sourceUsed by
Lean2Js.okName_bodyName
sourceUsed by
Lean2Js.validateIdent
sourceEquations
- One or more equations did not get rendered due to their size.
Instances For
Used by
Lean2Js.unreserved_of_validateIdent
sourceNothing 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
Lean2Js.okName_of_validateIdent
sourceNothing that passed the check is spelled as anything but an identifier, which is what lets the reader
in Parse take a compiled name back.