src/fmt/head.bend checks
raw source on the hub · import bolt@1.59.0.0/src/fmt/head.bend as Head
src/fmt/head: the def-header pass of bolt's formatter. A header that
wrap (src/rules/style/wrap.bend) would judge, one that already breaks
across lines or is wider than 120 on one, is written in the shape that
rule asks for:
def name( first: A, second: B ) -> T:
( ends the first line, each parameter has a line of its own, indented
two, and ) opens the last line with the return type after it. A header
on one line that fits is left as it is, however many parameters it has. A
parameter list with no parameter in it is closed where it opens: ().
Only blank space changes: a space or a newline between two tokens of the
header is dropped or put back, and every other token is kept as it is, in
order. Inside a parameter the spacing is kept, and a line break there
becomes one space: none after an opening bracket, none before a closing
one or a comma, and none before an opening one unless a comma comes right
before it. A comment stays where it is on its line: after the ( or a
comma it keeps that line, two spaces off, and anywhere else it gets a line
of its own; the line after it starts as the shape says.
The header runs from a def at column 0 through the first : outside
every bracket; a def with no such : before the tokens end is left
alone. Which token is the list's (, its ) or a comma between two
parameters is wrap's reading (its check.act), so the two agree on what
a parameter is.
Pure.
4 imports
import Base import ../lazy/lazy.bend as Lazy import ../syntax/lex.bend as Lex import ../rules/style/wrap.bend as Wrap
Types
type Role source · line 37 · raw
Data
what a token of a header is to the layout: the parameter list's (, its
), a comma between two parameters, a comment, another opening bracket,
another closing bracket, a comma inside a parameter, or anything else
ROpenRole
REndRole
RCommaRole
RNoteRole
RBracketRole
RCloseRole
RSepRole
RWordRole
type Prev source · line 50 · raw
Data
what the token before was: the list's (, a comma between parameters, a
comment, another opening bracket, a comma inside a parameter, or anything
else
POpenPrev
PCommaPrev
PNotePrev
PBracketPrev
PSepPrev
PWordPrev
type Gap source · line 60 · raw
Data
the blank space before a token: none, one space, two, a line break, a line break and an indent of two, or the spaces that were there
GNoneGap
GOneGap
GTwoGap
GLineGap
GDentGap
GKeep@sp:String -> Gap
type State source · line 72 · raw
Data
where the pass is: outside a header, or inside one it is rewriting, with wrap's walk so far, whether the token before was a name, what it was to the layout, whether a line break came since, the spaces since, and how many brackets are open
OutState
In@wk:0xace24ae64a36369bd02380967fccdfd3/src/rules/style/wrap.Walk -> @glued:Bool -> @prev:Prev -> @brk:Bool -> @sp:String -> @depth:U32 -> State
Definitions
def space source · line 77 · raw
@text:String -> 0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok
a space token of this text
def newline source · line 81 · raw
0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok
a newline token
def gap.toks source · line 85 · raw
@gp:Gap -> List<&2, 0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok>
a gap as tokens
def role.kind source · line 101 · raw
@k:0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.TokKind -> Role
what a token that is no comment is to the layout by its kind alone
def role.act source · line 113 · raw
@act:0xace24ae64a36369bd02380967fccdfd3/src/rules/style/wrap.Act -> @k:0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.TokKind -> Role
what a token is to the layout, given wrap's motion for it
def act_of source · line 125 · raw
@wk:0xace24ae64a36369bd02380967fccdfd3/src/rules/style/wrap.Walk -> @tok:0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok -> @glued:Bool -> 0xace24ae64a36369bd02380967fccdfd3/src/rules/style/wrap.Act
wrap's motion for a token, at its walk so far
def kind_of source · line 131 · raw
@tok:0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok -> 0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.TokKind
a token's kind
def is_note source · line 136 · raw
@k:0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.TokKind -> Bool
is the kind a comment's?
def role.pick source · line 145 · raw
@note:Bool -> @wk:0xace24ae64a36369bd02380967fccdfd3/src/rules/style/wrap.Walk -> @+tok:0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok -> @glued:Bool -> Role
what a token is to the layout: a comment by its kind, any other by wrap's motion for it
def role source · line 153 · raw
@wk:0xace24ae64a36369bd02380967fccdfd3/src/rules/style/wrap.Walk -> @+tok:0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok -> @glued:Bool -> Role
what a token is to the layout
def after source · line 157 · raw
@rl:Role -> Prev
what a token leaves for the one after it
def listing source · line 173 · raw
@ph:0xace24ae64a36369bd02380967fccdfd3/src/rules/style/wrap.Phase -> Bool
is the walk inside the parameter list?
def kept source · line 181 · raw
@brk:Bool -> @sp:String -> Gap
the spaces that were there, or nothing where a line broke
def joined source · line 189 · raw
@brk:Bool -> @sp:String -> Gap
the spaces that were there, or one where a line broke
def noted source · line 198 · raw
@brk:Bool -> Gap
a comment after the list's ( or a comma: on that line, two spaces off,
or on its own when a line broke before it
def lined source · line 206 · raw
@inside:Bool -> Gap
a line of its own: indented inside the parameter list, not outside it
def gap.open source · line 214 · raw
@rl:Role -> @brk:Bool -> Gap
the gap before a token right after the list's (
def gap.comma source · line 224 · raw
@rl:Role -> @brk:Bool -> Gap
the gap before a token right after a comma between parameters
def gap.note source · line 234 · raw
@rl:Role -> @inside:Bool -> Gap
the gap before a token right after a comment
def gap.bracket source · line 242 · raw
@rl:Role -> @brk:Bool -> @sp:String -> Gap
the gap before a token right after another opening bracket
def gap.aside source · line 251 · raw
@brk:Bool -> @sp:String -> Gap
a comment in the middle of a parameter: where it was on its line, or on a line of its own when a line broke before it
def gap.word source · line 259 · raw
@rl:Role -> @brk:Bool -> @sp:String -> Gap
the gap before a token after anything else
def gap.sep source · line 273 · raw
@rl:Role -> @brk:Bool -> @sp:String -> Gap
the gap before a token right after a comma inside a parameter: where a
line broke, one space, so the comma keeps the space bolt fmt gives every
comma; none before a closing bracket or another comma
def gap source · line 289 · raw
@pv:Prev -> @rl:Role -> @brk:Bool -> @sp:String -> @inside:Bool -> Gap
the gap before a token: by what came before it, what it is, whether a line broke between them, the spaces between them, and whether the parameter list is open
def depth.after source · line 305 · raw
@k:0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.TokKind -> @+depth:U32 -> U32
the bracket depth after a token
def ends source · line 315 · raw
@k:0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.TokKind -> @depth:U32 -> Bool
is the token the : that ends a header: a colon outside every bracket?
def needs source · line 326 · raw
@toks:List<&2, 0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok> -> @+depth:U32 -> @+wide:U32 -> @+brk:Bool -> Bool
does the header these tokens go on with need rewriting: it reaches its
:, and before that it breaks across lines, or is wider than 120 with
the def before it (wide so far)? A def at column 0 before the :, or
the tokens ending, means there is no header to read
def starts source · line 338 · raw
@tok:0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok -> Bool
is the token a def at column 0?
def entered source · line 346 · raw
@+tok:0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok -> State
the state inside a header, its def just read
def enter source · line 351 · raw
@+tok:0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok -> @rest:List<&2, 0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok> -> State
the state after a token outside a header: inside one when the token is a
def whose header needs rewriting
def leave source · line 356 · raw
@done:Bool -> @+wk:0xace24ae64a36369bd02380967fccdfd3/src/rules/style/wrap.Walk -> @+glued:Bool -> @+tok:0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok -> @depth:U32 -> State
the state after a token inside a header: outside again once it was the
header's :
def on_mark source · line 371 · raw
@st:State -> @+tok:0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok -> @rest:List<&2, 0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok> -> State
the state after a token that is no space and no newline
def on_space source · line 379 · raw
@st:State -> @text:String -> State
the state after a space: inside a header it is remembered, not written
def on_line source · line 387 · raw
@st:State -> State
the state after a newline: inside a header a line broke
def blank source · line 397 · raw
@st:State -> @tok:0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok -> @more:List<&2, 0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok> -> List<&2, 0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok>
a space or a newline before the rest: written as it is outside a header, and dropped inside one, where the gap before the next token takes its place
def gap_at source · line 406 · raw
@st:State -> @tok:0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok -> Gap
the gap written before a token that is no space and no newline: none outside a header
def heads.go source · line 414 · raw
@toks:List<&2, 0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok> -> @+st:State -> List<&2, 0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok>
every header that needs it rewritten, the rest of the tokens as they were
def heads source · line 427 · raw
@toks:List<&2, 0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok> -> List<&2, 0xace24ae64a36369bd02380967fccdfd3/src/syntax/lex.Tok>
a file's tokens with each def header that breaks, or is too wide, in the
shape wrap asks for