def spans

bolt@1.27.0.0 · src/rules/digest.bend:89

import bolt@1.27.0.0/src/rules/digest.bend as Digest
import Base
import bolt@1.27.0.0/src/syntax/lex.bend as Lex
import bolt@1.27.0.0/src/syntax/tree.bend as Tree
import bolt@1.27.0.0/src/rules/laws/closed.bend as Closed

89# the spans of every quantified law of a tree, in order. A closed law spans
90# nothing (it covers one input, not the def)
91def spans(root: Tree.Node) -> List<&2, Span>:
92  match root:
93    case Tree.NCons{Tree.Stmt{Tree.SLaw{}, kids, +body}, rest}:
94      +more = spans(rest)
95      Bool.pick(List<&2, Span>, Closed.binds(body),
96        Span{Tree.line(kids), Tree.line.of(List.head(&2, Lex.Tok, Tree.leaves.go(body, [])))} <> more, more)
97    case Tree.NCons{h, rest}:
98      spans(rest)
99    case other:
100      Nil{}

Uses (11)

Used by (1)