Lean2Js.Text
Decimal numerals and JS / JSON string escaping, for the printers #
The text primitives the printers reach for: decimal numerals and JS / JSON string escaping.
Both are written as recursions over List Char rather than over String, and neither goes through
toString. The generated file has to be something a proof can unfold, and Nat.repr and String.foldl
are both walls to a proof that wants to read the characters back.
Lean2Js.digitChar
sourceEquations
- Lean2Js.digitChar d = Char.ofNat ('0'.toNat + d)
Instances For
Used by
Lean2Js.natDigits
source@[irreducible]
The decimal digits, most significant first.
Equations
- Lean2Js.natDigits n = if n < 10 then [Lean2Js.digitChar n] else Lean2Js.natDigits (n / 10) ++ [Lean2Js.digitChar (n % 10)]
Instances For
Used by
Lean2Js.renderNat
sourceEquations
Instances For
Used by
Lean2Js.renderInt
sourceEquations
- Lean2Js.renderInt (Int.ofNat n) = Lean2Js.renderNat n
- Lean2Js.renderInt (Int.negSucc n) = "-" ++ Lean2Js.renderNat (n + 1)
Instances For
Used by
Lean2Js.hexDigit
sourceEquations
- Lean2Js.hexDigit d = if d < 10 then Char.ofNat ('0'.toNat + d) else Char.ofNat ('a'.toNat + d - 10)
Instances For
Used by
Lean2Js.hex4
sourceEquations
- Lean2Js.hex4 n = String.ofList [Lean2Js.hexDigit (n / 4096 % 16), Lean2Js.hexDigit (n / 256 % 16), Lean2Js.hexDigit (n / 16 % 16), Lean2Js.hexDigit (n % 16)]
Instances For
Used by
Lean2Js.escapeChar
sourceJSON string escaping. It works as is for JS string literals too. U+2028 / U+2029 are not passed through because, legal as they are in JSON, placing them directly in JS source can have them read as line terminators.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Used by
Lean2Js.escapeChars
sourceEquations
- Lean2Js.escapeChars [] = ""
- Lean2Js.escapeChars (c :: rest) = Lean2Js.escapeChar c ++ Lean2Js.escapeChars rest