Skip to content

Instantly share code, notes, and snippets.

@ohAitch
Created November 22, 2016 02:15
Show Gist options
  • Select an option

  • Save ohAitch/4188dee50ed825c99826b74b9bbeab40 to your computer and use it in GitHub Desktop.

Select an option

Save ohAitch/4188dee50ed825c99826b74b9bbeab40 to your computer and use it in GitHub Desktop.
usage: jq '.' -s -R oldzuse.hoon | lsc -je "(require './retag.ls') @" | jq -r '.' > newzuse.hoon
RANGE=[ '(2)', '++ zuse']
strip_tags = (.filter -> it isnt /^( |::)* \+\+[a-z0-9:]*$/)
retag = (untagged)->
stack = []
already_tagged = {}
res = []; emit = (-> res.push it)
started = no
for untagged
if ..includes RANGE[0]
started = yes
if ..includes RANGE[1]
started = no
if !started
emit ..
continue
[dent] = ..match /^[ ]*/
pad = -> (dent + "::" + " "*80).slice 0, 56
while stack[0]?.dent >= dent => stack.shift!
[,tag] = (..match /:: *\+\+([a-z0-9:]+)/) ? []
if tag
already_tagged[tag] = yes
[,arm] = (..match /[ ]*\+\+ ([a-z0-9]+)/) ? []
if arm
stack
stack.unshift {arm,dent}
cur = (stack.map (.arm)) * ':'
unless already_tagged[cur]
out = pad! + ":: ++" + cur
while out.length > 80
out -= /[a-z0-9]+:?$/
emit out
emit ..
res
module.exports = (input)->
(retag strip_tags (input / \\n)) * \\n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment