Make cc.pretty internals more opaque

I wish I had an actual type system.
This commit is contained in:
Jonathan Coates 2021-05-28 21:28:56 +01:00
parent f9fb0619fa
commit b129ae627b
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
1 changed files with 6 additions and 4 deletions

View File

@ -45,17 +45,19 @@ end
-- @type Doc
local Doc = { }
local function mk_doc(tbl) return setmetatable(tbl, Doc) end
--- An empty document.
local empty = setmetatable({ tag = "nil" }, Doc)
local empty = mk_doc({ tag = "nil" })
--- A document with a single space in it.
local space = setmetatable({ tag = "text", text = " " }, Doc)
local space = mk_doc({ tag = "text", text = " " })
--- A line break. When collapsed with @{group}, this will be replaced with @{empty}.
local line = setmetatable({ tag = "line", flat = empty }, Doc)
local line = mk_doc({ tag = "line", flat = empty })
--- A line break. When collapsed with @{group}, this will be replaced with @{space}.
local space_line = setmetatable({ tag = "line", flat = space }, Doc)
local space_line = mk_doc({ tag = "line", flat = space })
local text_cache = { [""] = empty, [" "] = space, ["\n"] = space_line }