Lean2Js.Parse
A reader for the text the printers write #
A reader for the text the printers write, and the proof that it gives the printers' input back.
The grammar it accepts is not JavaScript: it is the subset this compiler emits, which is fully parenthesised and has no optional whitespace. Reading JS is not the goal — reading back what was written is.
Every reader takes a List Char and returns what it read together with the characters left over, so
the roundtrip lemmas compose: each one is stated about a rendering followed by an arbitrary remainder.
Decimal numerals #
Lean2Js.Parse.digitVal
sourceEquations
- Lean2Js.Parse.digitVal c = c.toNat - '0'.toNat
Instances For
Used by
Lean2Js.Parse.parseDigits
sourceEquations
Instances For
Used by
Lean2Js.Parse.parseNat
sourceEquations
- Lean2Js.Parse.parseNat [] = none
- Lean2Js.Parse.parseNat (c :: rest) = if c.isDigit = true then some (Lean2Js.Parse.parseDigits (Lean2Js.Parse.digitVal c) rest) else none
Instances For
Used by
Lean2Js.Parse.parseInt
sourceEquations
- One or more equations did not get rendered due to their size.
Instances For
Used by
Lean2Js.Parse.notDigitFirst
sourceWhat a numeral can be followed by. A reader of digits is greedy, so the character after the numeral has to be one it will not take.
Equations
Instances For
Used by
Lean2Js.Parse.digitVal_digitChar
sourceUsed by
Lean2Js.Parse.isDigit_digitChar
sourceUsed by
Lean2Js.Parse.natDigits_all_digit
sourceUsed by
Lean2Js.Parse.natDigits_ne_nil
sourceUsed by
Lean2Js.Parse.parseDigits_append
sourceReading digits off a rendering of n, with anything that is not a digit behind it, gives n back
and leaves the remainder untouched.
Used by
Lean2Js.Parse.foldl_natDigits
sourceUsed by
Lean2Js.Parse.toList_renderNat
sourceUsed by
Lean2Js.Parse.parseNat_append
sourceUsed by
Lean2Js.Parse.head_natDigits_ne_neg
sourceUsed by
Lean2Js.Parse.parseInt_ofNat
sourceUsed by
Lean2Js.Parse.parseInt_negSucc
sourceUsed by
Lean2Js.Parse.parseInt_append
sourceUsed by
String literals #
Lean2Js.Parse.hexVal
sourceEquations
- One or more equations did not get rendered due to their size.
Instances For
Used by
Lean2Js.Parse.unescape
sourceReads the body of a string literal up to its closing quote, returning the characters it stood for and what follows the quote.
Equations
- One or more equations did not get rendered due to their size.
- Lean2Js.Parse.unescape [] = none
- Lean2Js.Parse.unescape ('\"' :: rest) = some ([], rest)
- Lean2Js.Parse.unescape ('\\' :: 'n' :: rest) = Option.map (fun (p : List Char × List Char) => ('\n' :: p.fst, p.snd)) (Lean2Js.Parse.unescape rest)
- Lean2Js.Parse.unescape ('\\' :: 'r' :: rest) = Option.map (fun (p : List Char × List Char) => ('\x0d' :: p.fst, p.snd)) (Lean2Js.Parse.unescape rest)
- Lean2Js.Parse.unescape ('\\' :: 't' :: rest) = Option.map (fun (p : List Char × List Char) => ('\t' :: p.fst, p.snd)) (Lean2Js.Parse.unescape rest)
- Lean2Js.Parse.unescape ('\\' :: '\"' :: rest) = Option.map (fun (p : List Char × List Char) => ('\"' :: p.fst, p.snd)) (Lean2Js.Parse.unescape rest)
- Lean2Js.Parse.unescape ('\\' :: '\\' :: rest) = Option.map (fun (p : List Char × List Char) => ('\\' :: p.fst, p.snd)) (Lean2Js.Parse.unescape rest)
- Lean2Js.Parse.unescape ('\\' :: tail) = none
- Lean2Js.Parse.unescape (c :: rest) = Option.map (fun (p : List Char × List Char) => (c :: p.fst, p.snd)) (Lean2Js.Parse.unescape rest)
Instances For
Used by
Lean2Js.Parse.parseStr
sourceEquations
- Lean2Js.Parse.parseStr ('\"' :: rest) = Option.map (fun (p : List Char × List Char) => (String.ofList p.fst, p.snd)) (Lean2Js.Parse.unescape rest)
- Lean2Js.Parse.parseStr x✝ = none
Instances For
Used by
Lean2Js.Parse.hex4_toList
sourceUsed by
Lean2Js.Parse.hexVal_hexDigit
sourceUsed by
Lean2Js.Parse.unescape_hex4
sourceUsed by
Lean2Js.Parse.unescape_plain
sourceUsed by
Lean2Js.Parse.unescape_escapeChar
sourceUsed by
Lean2Js.Parse.unescape_escapeChars
sourceUsed by
Lean2Js.Parse.parseStr_append
sourceUsed by
Lean2Js.Parse.parseStr_cons
sourceThe shape a string literal takes inside a larger rendering, where the quotes are part of a neighbouring chunk of literal text rather than of the escaped body.
Used by
Lean2Js.Parse.parseStr_ctors
sourceThe head of a descriptor for a declared type, read back while parseStr stays folded: the key that
follows it is a string the author chose, and reading that one needs parseStr_cons.
Used by
Lean2Js.Parse.parseStr_mu
sourceUsed by
Lean2Js.Parse.parseStr_ref
sourceUsed by
Identifiers #
Lean2Js.Parse.parseIdentChars
sourceEquations
Instances For
Used by
Lean2Js.Parse.parseIdent
sourceEquations
Instances For
Used by
Lean2Js.Parse.notIdentFirst
sourceWhat a name can be followed by. A reader of names is greedy, so the character after the name has to be one it will not take.
Equations
- Lean2Js.Parse.notIdentFirst cs = ∀ (c : Char) (rest : List Char), cs = c :: rest → Lean2Js.isIdentPart c = false
Instances For
Used by
Lean2Js.Parse.parseIdentChars_append
sourceUsed by
Lean2Js.Parse.parseIdent_append
sourceUsed by
Literal chunks #
Lean2Js.Parse.expect
sourceEquations
Instances For
Used by
Lean2Js.Parse.expect_append
sourceUsed by
Type descriptors #
The budget is the descriptor's own size, which the caller reads off the text it is about to hand over. It bounds the descent, not the guarantee: the roundtrip below holds for every budget that is large enough, and the top-level reader takes the length of the text it was given.
Lean2Js.Parse.descSize
sourceEquations
- Lean2Js.Parse.descSize Lean2Js.Js.TyDesc.bool = 1
- Lean2Js.Parse.descSize Lean2Js.Js.TyDesc.int53 = 1
- Lean2Js.Parse.descSize Lean2Js.Js.TyDesc.uint32 = 1
- Lean2Js.Parse.descSize Lean2Js.Js.TyDesc.string = 1
- Lean2Js.Parse.descSize Lean2Js.Js.TyDesc.bigint = 1
- Lean2Js.Parse.descSize t.option = Lean2Js.Parse.descSize t + 1
- Lean2Js.Parse.descSize t.array = Lean2Js.Parse.descSize t + 1
- Lean2Js.Parse.descSize t.dict = Lean2Js.Parse.descSize t + 1
- Lean2Js.Parse.descSize t.dictObj = Lean2Js.Parse.descSize t + 1
- Lean2Js.Parse.descSize (ok.result err) = Lean2Js.Parse.descSize ok + Lean2Js.Parse.descSize err + 1
- Lean2Js.Parse.descSize (Lean2Js.Js.TyDesc.ctors key alts) = Lean2Js.Parse.altsSize alts + 1
- Lean2Js.Parse.descSize (Lean2Js.Js.TyDesc.mu key alts) = Lean2Js.Parse.altsSize alts + 1
- Lean2Js.Parse.descSize (Lean2Js.Js.TyDesc.ref up) = 1
Instances For
Used by
Lean2Js.Parse.altsSize
sourceEquations
- Lean2Js.Parse.altsSize [] = 1
- Lean2Js.Parse.altsSize ((fst, fs) :: rest) = Lean2Js.Parse.fieldsSize fs + Lean2Js.Parse.altsSize rest + 1
Instances For
Used by
Lean2Js.Parse.fieldsSize
sourceEquations
- Lean2Js.Parse.fieldsSize [] = 1
- Lean2Js.Parse.fieldsSize ((fst, d) :: rest) = Lean2Js.Parse.descSize d + Lean2Js.Parse.fieldsSize rest + 1
Instances For
Used by
Lean2Js.Parse.parseDesc
sourceEquations
- One or more equations did not get rendered due to their size.
- Lean2Js.Parse.parseDesc 0 x✝ = none
Instances For
Used by
Lean2Js.Parse.parseAlts
sourceEquations
Instances For
Used by
Lean2Js.Parse.parseFields
sourceEquations
Instances For
Used by
Lean2Js.Parse.descSize_pos
sourceUsed by
Lean2Js.Parse.altsSize_pos
sourceUsed by
Lean2Js.Parse.fieldsSize_pos
sourceUsed by
Lean2Js.Parse.parseDesc_append
sourceUsed by
Lean2Js.Parse.parseAlts_append
sourceUsed by
Lean2Js.Parse.parseFields_append
sourceUsed by
Fold specs #
A spec carries the shape TyAlts does with a kind where a descriptor sits, so the reader is the
descriptor's with the descent taken out: a kind is one of three words and nothing below it nests. The
budget is still the spec's own size, because the recursion is on the text rather than on the tree.
The spec is printed as an object rather than as nested arrays, because __fold indexes it by the
constructor's name, so the end of an empty one is told from the start of an entry the way parseObjFields
tells them apart — by the space that opens }.
Lean2Js.Parse.foldFieldsSize
sourceEquations
- Lean2Js.Parse.foldFieldsSize [] = 1
- Lean2Js.Parse.foldFieldsSize (head :: rest) = Lean2Js.Parse.foldFieldsSize rest + 1
Instances For
Used by
Lean2Js.Parse.specSize
sourceEquations
- Lean2Js.Parse.specSize [] = 1
- Lean2Js.Parse.specSize ((fst, fs) :: rest) = Lean2Js.Parse.foldFieldsSize fs + Lean2Js.Parse.specSize rest + 1
Instances For
Used by
Lean2Js.Parse.foldFieldsSize_pos
sourceUsed by
Lean2Js.Parse.specSize_pos
sourceUsed by
Lean2Js.Parse.parseFoldKind
sourceThe three words FoldKind.render writes. A fourth is a text this printer does not write, so the
reader has nothing to give back for it.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Used by
Lean2Js.Parse.parseFoldKind_cons
sourceUsed by
Lean2Js.Parse.parseFoldFields
sourceEquations
Instances For
Used by
Lean2Js.Parse.parseFoldSpec
sourceEquations
Instances For
Used by
Lean2Js.Parse.parseFoldFields_append
sourceUsed by
Lean2Js.Parse.parseFoldSpec_append
sourceUsed by
Expressions #
The grammar is fully parenthesised and has no optional whitespace, so one character of lookahead picks
the form everywhere except after (, where arrowHead reads ahead for (names) => (. Nothing else the
printer writes has that shape: member closes with )., and binary and cond put a space where the
arrow wants ).
Lean2Js.Parse.isOpChar
sourceEquations
Instances For
Used by
Lean2Js.Parse.parseOpChars
sourceEquations
Instances For
Used by
Lean2Js.Parse.parseOp
sourceEquations
Instances For
Used by
Lean2Js.Parse.parseNumeral
sourceEquations
- One or more equations did not get rendered due to their size.
Instances For
Used by
Lean2Js.Parse.negateNumeral
sourceUndoes the sign a numeral reader takes with it, for the one place where (- opens a unary minus
rather than a negative literal.
Equations
Instances For
Used by
Lean2Js.Parse.parseIdentList
sourceEquations
- One or more equations did not get rendered due to their size.
- Lean2Js.Parse.parseIdentList 0 x✝ = none
Instances For
Used by
Lean2Js.Parse.parseArrowHead
sourceEquations
- One or more equations did not get rendered due to their size.
Instances For
Used by
Lean2Js.Parse.parseExpr
sourceEquations
- One or more equations did not get rendered due to their size.
- Lean2Js.Parse.parseExpr 0 x✝ = none
- Lean2Js.Parse.parseExpr f.succ [] = none
- Lean2Js.Parse.parseExpr f.succ ('\"' :: tail) = Option.map (fun (p : String × List Char) => (Lean2Js.Js.Expr.str p.fst, p.snd)) (Lean2Js.Parse.parseStr ('\"' :: tail))
- Lean2Js.Parse.parseExpr f.succ ('(' :: r) = Lean2Js.Parse.parseParen f r
Instances For
Used by
Lean2Js.Parse.parseNamed
sourceWhat follows a name: a keyword, a helper the printer has a constructor for, a call, or the name itself.
Equations
- One or more equations did not get rendered due to their size.
- Lean2Js.Parse.parseNamed 0 x✝¹ x✝ = none
Instances For
Used by
Lean2Js.Parse.parseLambdaCall
sourceEquations
- One or more equations did not get rendered due to their size.
- Lean2Js.Parse.parseLambdaCall 0 x✝ = none
Instances For
Used by
Lean2Js.Parse.parseParen
sourceEquations
- One or more equations did not get rendered due to their size.
- Lean2Js.Parse.parseParen 0 x✝ = none
Instances For
Used by
Lean2Js.Parse.parseAfterHead
sourceThe three forms that open with a subexpression: (e).f, (e op e) and (e ? e : e). A ) with no
field behind it is the unary minus a numeral reader has already swallowed the sign of.
Equations
- One or more equations did not get rendered due to their size.
- Lean2Js.Parse.parseAfterHead 0 x✝¹ x✝ = none
- Lean2Js.Parse.parseAfterHead f.succ x✝ (')' :: '.' :: r) = do let __x ← Lean2Js.Parse.parseIdent r match __x with | (field, r) => pure (x✝.member field, r)
- Lean2Js.Parse.parseAfterHead f.succ x✝ (')' :: r) = Option.map (fun (e : Lean2Js.Js.Expr) => (Lean2Js.Js.Expr.unary "-" e, r)) (Lean2Js.Parse.negateNumeral x✝)
- Lean2Js.Parse.parseAfterHead f.succ x✝¹ x✝ = none
Instances For
Used by
Lean2Js.Parse.parseExprList
sourceEquations
- One or more equations did not get rendered due to their size.
- Lean2Js.Parse.parseExprList 0 x✝¹ x✝ = none
- Lean2Js.Parse.parseExprList f.succ x✝ [] = none
Instances For
Used by
Lean2Js.Parse.parseObjFields
sourceEquations
Instances For
Used by
Lean2Js.Parse.parseEntries
sourceEquations
Instances For
Used by
Statements, functions and the module #
The runtime helpers are matched as the one literal block the printer writes them as. The block is what
Helper's own printer makes of the definitions the helper proofs are stated over, so it is an AST on
the way out; the reader does not take it back apart, and accepting it verbatim is what "reads back
exactly what this printer writes" means for that part.
Lean2Js.Parse.takeUntil
sourceEquations
- One or more equations did not get rendered due to their size.
- Lean2Js.Parse.takeUntil lit [] = none
Instances For
Used by
Lean2Js.Parse.parseStmt
sourceEquations
- One or more equations did not get rendered due to their size.
Instances For
Used by
Lean2Js.Parse.parseStmts
sourceEquations
Instances For
Used by
Lean2Js.Parse.parseFunc
sourceEquations
- One or more equations did not get rendered due to their size.
- Lean2Js.Parse.parseFunc 0 x✝ = none
Instances For
Used by
Lean2Js.Parse.parseFuncs
sourceEquations
Instances For
Used by
Lean2Js.Parse.parseModule
sourceEquations
- One or more equations did not get rendered due to their size.
Instances For
Used by
The grammar the reader accepts #
One case per printer branch, plus the places where two branches open with the same character. The theorem below covers these too; they are here because a reader that drifts from the printer stops building long before a proof about it does.