def unimported

bolt@1.27.0.0 · src/rules/style/space.bend:62

import bolt@1.27.0.0/src/rules/style/space.bend as Space
import Base
import bolt@1.27.0.0/src/syntax/lex.bend as Lex
import bolt@1.27.0.0/src/lazy/lazy.bend as Lazy

62# the tokens with every import line cut to its newline, so the width counts
63# no import; start is whether the token opens its line, and cutting whether
64# it is on an import line
65def unimported(toks: List<&2, Lex.Tok>, start: Bool, cutting: Bool) -> List<&2, Lex.Tok>:
66  match toks:
67    case Nil{}:
68      Nil{}
69    case Con{Lex.Tok{Lex.TNewline{}, t, l, c}, rest}:
70      Lex.Tok{Lex.TNewline{}, t, l, c} <> unimported(rest, True{}, False{})
71    case Con{Lex.Tok{k, +t, l, c}, +rest}:
72      +cuts = Bool.or(cutting, Bool.and(start, String.eq(t, "import")))
73      Lazy.either(List<&2, Lex.Tok>, cuts, _u => unimported(rest, False{}, True{}),
74        _v => Lex.Tok{k, t, l, c} <> unimported(rest, False{}, False{}))

Uses (8)

Used by (1)