src/fmt/line.bend checks
raw source on the hub · import bolt@1.66.0.0/src/fmt/line.bend as Line
src/fmt/line: the pass of bolt's formatter for the spaces inside a line.
Two steps over a file's tokens:
commas a comma has a space after it: one is put after a comma the next
token touches, unless that token is a closing bracket ([a, b,]
stays);
runs one space between two tokens of a line: a run of spaces or tabs
that neither opens its line nor comes before a comment becomes
one space.
A line's indentation is kept as written, and so are the spaces before a
comment, which may be lined up with the comments around it. A space is
put nowhere but after a comma, and none is taken away: f(x) and f (x)
both stay, and so does 1n+p.
Pure.
2 imports
import Base import ../syntax/lex.bend as Lex
Definitions
def commas.far source · line 19 · raw
@k:0x243ea54885fbd6711eb0dc5731e3043f/src/syntax/lex.TokKind -> Bool
may a comma not touch a token of this kind: any but blank space and a closing bracket?
def commas.bare source · line 32 · raw
@rest:List<&2, 0x243ea54885fbd6711eb0dc5731e3043f/src/syntax/lex.Tok> -> Bool
does a comma right before these tokens want a space: there is a next token, and a comma may not touch it?
def space source · line 40 · raw
0x243ea54885fbd6711eb0dc5731e3043f/src/syntax/lex.Tok
one space
def commas.gap source · line 44 · raw
@bare:Bool -> @more:List<&2, 0x243ea54885fbd6711eb0dc5731e3043f/src/syntax/lex.Tok> -> List<&2, 0x243ea54885fbd6711eb0dc5731e3043f/src/syntax/lex.Tok>
the tokens after a comma, a space put first where the comma wants one
def commas source · line 52 · raw
@toks:List<&2, 0x243ea54885fbd6711eb0dc5731e3043f/src/syntax/lex.Tok> -> List<&2, 0x243ea54885fbd6711eb0dc5731e3043f/src/syntax/lex.Tok>
a space after every comma
def runs.note source · line 62 · raw
@k:0x243ea54885fbd6711eb0dc5731e3043f/src/syntax/lex.TokKind -> Bool
is the kind a comment's?
def runs.noted source · line 70 · raw
@rest:List<&2, 0x243ea54885fbd6711eb0dc5731e3043f/src/syntax/lex.Tok> -> Bool
is the first of these tokens a comment?
def runs.text source · line 78 · raw
@keep:Bool -> @t:String -> String
a space token's text: as written where it is kept, one space where not
def runs source · line 87 · raw
@toks:List<&2, 0x243ea54885fbd6711eb0dc5731e3043f/src/syntax/lex.Tok> -> @lead:Bool -> List<&2, 0x243ea54885fbd6711eb0dc5731e3043f/src/syntax/lex.Tok>
one space between two tokens of a line. lead: does the next token open its line?
def spaces source · line 99 · raw
@toks:List<&2, 0x243ea54885fbd6711eb0dc5731e3043f/src/syntax/lex.Tok> -> List<&2, 0x243ea54885fbd6711eb0dc5731e3043f/src/syntax/lex.Tok>
a file's tokens with the spaces inside each line written one way