~/bend-docscommunity

src/fmt/head.bend checks

raw source on the hub · import bolt@1.58.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 or before a closing one or a comma). 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 36 · 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

type Prev source · line 48 · raw

Data

what the token before was: the list's (, a comma between parameters, a comment, another opening bracket, or anything else

type Gap source · line 57 · 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

type State source · line 69 · 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

Definitions

def space source · line 74 · raw

@text:String -> 0x513b777299af6ffc61682bebdb9f09e1/src/syntax/lex.Tok

a space token of this text

def newline source · line 78 · raw

0x513b777299af6ffc61682bebdb9f09e1/src/syntax/lex.Tok

a newline token

def gap.toks source · line 82 · raw

@gp:Gap -> List<&2, 0x513b777299af6ffc61682bebdb9f09e1/src/syntax/lex.Tok>

a gap as tokens

def role.kind source · line 98 · raw

@k:0x513b777299af6ffc61682bebdb9f09e1/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 110 · raw

@act:0x513b777299af6ffc61682bebdb9f09e1/src/rules/style/wrap.Act -> @k:0x513b777299af6ffc61682bebdb9f09e1/src/syntax/lex.TokKind -> Role

what a token is to the layout, given wrap's motion for it

def act_of source · line 122 · raw

@wk:0x513b777299af6ffc61682bebdb9f09e1/src/rules/style/wrap.Walk -> @tok:0x513b777299af6ffc61682bebdb9f09e1/src/syntax/lex.Tok -> @glued:Bool -> 0x513b777299af6ffc61682bebdb9f09e1/src/rules/style/wrap.Act

wrap's motion for a token, at its walk so far

def kind_of source · line 128 · raw

@tok:0x513b777299af6ffc61682bebdb9f09e1/src/syntax/lex.Tok -> 0x513b777299af6ffc61682bebdb9f09e1/src/syntax/lex.TokKind

a token's kind

def is_note source · line 133 · raw

@k:0x513b777299af6ffc61682bebdb9f09e1/src/syntax/lex.TokKind -> Bool

is the kind a comment's?

def role.pick source · line 142 · raw

@note:Bool -> @wk:0x513b777299af6ffc61682bebdb9f09e1/src/rules/style/wrap.Walk -> @+tok:0x513b777299af6ffc61682bebdb9f09e1/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 150 · raw

@wk:0x513b777299af6ffc61682bebdb9f09e1/src/rules/style/wrap.Walk -> @+tok:0x513b777299af6ffc61682bebdb9f09e1/src/syntax/lex.Tok -> @glued:Bool -> Role

what a token is to the layout

def after source · line 154 · raw

@rl:Role -> Prev

what a token leaves for the one after it

def listing source · line 168 · raw

@ph:0x513b777299af6ffc61682bebdb9f09e1/src/rules/style/wrap.Phase -> Bool

is the walk inside the parameter list?

def kept source · line 176 · raw

@brk:Bool -> @sp:String -> Gap

the spaces that were there, or nothing where a line broke

def joined source · line 184 · raw

@brk:Bool -> @sp:String -> Gap

the spaces that were there, or one where a line broke

def noted source · line 193 · 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 201 · raw

@inside:Bool -> Gap

a line of its own: indented inside the parameter list, not outside it

def gap.open source · line 209 · raw

@rl:Role -> @brk:Bool -> Gap

the gap before a token right after the list's (

def gap.comma source · line 219 · raw

@rl:Role -> @brk:Bool -> Gap

the gap before a token right after a comma between parameters

def gap.note source · line 229 · raw

@rl:Role -> @inside:Bool -> Gap

the gap before a token right after a comment

def gap.bracket source · line 237 · raw

@rl:Role -> @brk:Bool -> @sp:String -> Gap

the gap before a token right after another opening bracket

def gap.aside source · line 246 · 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 254 · raw

@rl:Role -> @brk:Bool -> @sp:String -> Gap

the gap before a token after anything else

def gap source · line 268 · 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 282 · raw

@k:0x513b777299af6ffc61682bebdb9f09e1/src/syntax/lex.TokKind -> @+depth:U32 -> U32

the bracket depth after a token

def ends source · line 292 · raw

@k:0x513b777299af6ffc61682bebdb9f09e1/src/syntax/lex.TokKind -> @depth:U32 -> Bool

is the token the : that ends a header: a colon outside every bracket?

def needs source · line 303 · raw

@toks:List<&2, 0x513b777299af6ffc61682bebdb9f09e1/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 315 · raw

@tok:0x513b777299af6ffc61682bebdb9f09e1/src/syntax/lex.Tok -> Bool

is the token a def at column 0?

def entered source · line 323 · raw

@+tok:0x513b777299af6ffc61682bebdb9f09e1/src/syntax/lex.Tok -> State

the state inside a header, its def just read

def enter source · line 328 · raw

@+tok:0x513b777299af6ffc61682bebdb9f09e1/src/syntax/lex.Tok -> @rest:List<&2, 0x513b777299af6ffc61682bebdb9f09e1/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 333 · raw

@done:Bool -> @+wk:0x513b777299af6ffc61682bebdb9f09e1/src/rules/style/wrap.Walk -> @+glued:Bool -> @+tok:0x513b777299af6ffc61682bebdb9f09e1/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 348 · raw

@st:State -> @+tok:0x513b777299af6ffc61682bebdb9f09e1/src/syntax/lex.Tok -> @rest:List<&2, 0x513b777299af6ffc61682bebdb9f09e1/src/syntax/lex.Tok> -> State

the state after a token that is no space and no newline

def on_space source · line 356 · raw

@st:State -> @text:String -> State

the state after a space: inside a header it is remembered, not written

def on_line source · line 364 · raw

@st:State -> State

the state after a newline: inside a header a line broke

def blank source · line 374 · raw

@st:State -> @tok:0x513b777299af6ffc61682bebdb9f09e1/src/syntax/lex.Tok -> @more:List<&2, 0x513b777299af6ffc61682bebdb9f09e1/src/syntax/lex.Tok> -> List<&2, 0x513b777299af6ffc61682bebdb9f09e1/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 383 · raw

@st:State -> @tok:0x513b777299af6ffc61682bebdb9f09e1/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 391 · raw

@toks:List<&2, 0x513b777299af6ffc61682bebdb9f09e1/src/syntax/lex.Tok> -> @+st:State -> List<&2, 0x513b777299af6ffc61682bebdb9f09e1/src/syntax/lex.Tok>

every header that needs it rewritten, the rest of the tokens as they were

def heads source · line 404 · raw

@toks:List<&2, 0x513b777299af6ffc61682bebdb9f09e1/src/syntax/lex.Tok> -> List<&2, 0x513b777299af6ffc61682bebdb9f09e1/src/syntax/lex.Tok>

a file's tokens with each def header that breaks, or is too wide, in the shape wrap asks for