def annotate.go

bolt@1.27.0.0 · src/syntax/bind.bend:858

import bolt@1.27.0.0/src/syntax/bind.bend as Bind
import Base
import bolt@1.27.0.0/src/lazy/lazy.bend as Lazy

858# every binder with its note filled. Binders come in source order, so the
859# lines are read once, front to back, from where the last binder was (`cur`
860# holds the lines from line `at` on); a binder behind that point reads its
861# line from the start
862def annotate.go(binds: List<&2, Bind>, +lines: List<&2, String>, +at: U32, +cur: List<&2, String>) -> List<&2, Bind>:
863  match binds:
864    case Nil{}:
865      Nil{}
866    case Con{Bind{name, +line, col, +kind, note}, rest}:
867      +ahead = U32.is_ge(line, at)
868      +here = Lazy.either(List<&2, String>, ahead, _u => annotate.ahead(line, at, cur), _v => cur)
869      +text = Lazy.either(String, ahead, _u => annotate.head(here), _v => annotate.back(lines, line))
870      Bind{name, line, col, kind, note_for(kind, note, _w => stripped(text))}
871        <> annotate.go(rest, lines, Bool.pick(U32, ahead, line, at), here)

Uses (12)

Used by (1)