~/bend-docscommunity

layout/format.bend checks

raw source on the hub · import bend-lint-rules@0.3.7.0/layout/format.bend as Format

layout/format: a file that differs from its formatted text, where it first differs. One formatter owns indentation, spacing, declaration gaps and wrapping. Fix: writes the formatted text. Options: tabWidth (2); wrapAtWidth (100, or "never": no optional wrapping); endOfLine ("lf", "crlf", or "preserve": the file's first, or LF if it has none). Heuristics: it reads tokens, not Bend's syntax, and changes only blanks, line breaks and the space after a comment's #, so a fix keeps the program. A form its token rules do not know can come out laid out oddly.

A String is a JS string at run time: ++ is native, and a match on SCon reads one character and slices off the rest. So the lexer reads the text once, tokens carry what the layout asks of them, and docs carry widths.

Each loop is go(input, state): a step that does not recurse makes the next state, so every loop recurses on a smaller part of its input. The lexer and the printer recurse on fuel instead: more steps than they can need.

4 imports
import Base
import bend-lint-api@0.3.7.0/linter/api/impl.bend as LintImpl
import bend-lint-api@0.3.7.0/linter/api/spec.bend as Lint
import bend-lint-api@0.3.7.0/shared.bend as Shared

Types

type Lex source · line 22 · raw

Data

Types =====

type Sym source · line 29 · raw

Data

The spellings the layout tells apart; Word{} is any other, Inc{} ends in n+.

type Token source · line 88 · raw

Data

Offsets and columns count code points. name: whether the text matches /^[\w.]+$/. tail: for a literal across lines, how many characters follow its last newline. from: the text from the token on.

type Scan source · line 103 · raw

Data

What the lexer read: the end of the text, one whitespace character, or a token; with the text after it and its last character.

type Run source · line 119 · raw

Data

Characters read by run: their text and count, the text after them, and the last one.

type Quote source · line 123 · raw

Data

What the next character of a literal is: inside it, escaped, or past it.

type Class source · line 128 · raw

Data

type Tree source · line 134 · raw

Data

type Open source · line 140 · raw

Data

A group the tree has opened: the sym that closes it, children last first, and whether a child is a token that makes it a block.

type Built source · line 143 · raw

Data

type Flat source · line 148 · raw

Data

A doc printed flat: its width up to the first break it cannot lose (a hard line, or a newline in text), and whether it has one.

type Doc source · line 155 · raw

Data

Str: text without its trailing whitespace, that whitespace, the width, and how many characters follow the last newline, if any. Line: the text and width when flat. Grp, Nest and Cat keep their Flat; Cat its docs last first.

type Measure source · line 162 · raw

Data

type Mode source · line 169 · raw

Data

How build reads a list of trees: a record, a group's children as a raw block, as comma-separated parts, or a group with no children. A block is an embedded statement body: its line and column boundaries mean something, so it keeps them, while ordinary calls inside it still wrap.

type Seq source · line 178 · raw

Data

A sequence being built: its docs last first, the docs of an operator chain, the previous tree, the indentation levels deepest first, and whether the rest of a run of newlines is skipped.

type Part source · line 189 · raw

Data

A comma-separated part: whether it holds only newlines, and whether its last other tree ends in a comment.

type Split source · line 194 · raw

Data

A group's parts so far, last first; the current part's flags; whether the next tree ends the current part; whether a child starts with a comment.

type State source · line 197 · raw

Data

type Act source · line 201 · raw

Data

What a child of a group does to its parts.

type Job source · line 207 · raw

Data
Data

The printer: jobs left, the text so far as chunks last first, the whitespace not written yet (dropped at a break or at the end), and the column.

type Fit source · line 216 · raw

Data

type Recs source · line 221 · raw

Data

Records so far, last first, and the current record, last first.

type Cut source · line 225 · raw

Data

A declaration record cut after its first colon, if it has one.

type Hash source · line 228 · raw

Data

type Rows source · line 232 · raw

Data

The rows so far, last first, and what the next record needs from them.

type Settings source · line 236 · raw

Data

width: None{} for "never".

Definitions

def fuel_per_point source · line 243 · raw

U32

Fuel per code point of a record: more printer steps than any doc needs.

def is_blank source · line 253 · raw

@+c:Char -> Bool

Whitespace, as Bend's parser reads it.

def is_head source · line 266 · raw

@+c:Char -> Bool

def is_word source · line 269 · raw

@+c:Char -> Bool

def char source · line 279 · raw

@c:Char -> String

def drop_blank.go source · line 282 · raw

@s:String -> @blank:Bool -> String

def drop_blank source · line 291 · raw

@+s:String -> String

def trim_end source · line 294 · raw

@s:String -> String

def pad source · line 297 · raw

@n:Nat -> @out:String -> String

def is_same.go source · line 306 · raw

@a:String -> @b:String -> @ok:Bool -> Bool

Base's String.eq is not tail-recursive, so long text would overflow the stack; is_same is. ok: whether the characters so far were the same.

def is_same source · line 315 · raw

@a:String -> @b:String -> Bool

def is_not_line_end source · line 325 · raw

@s:String -> Bool

Lexer -----

A branch that uses a string or a character its match took apart gets it rebuilt: a string as character + rest, a rope that the next read copies whole, and a character bit by bit. So a def that needs the whole value in a branch takes it twice, as keep, and matches the other copy.

def is_digit_at source · line 336 · raw

@s:String -> Bool

def is_ident_at.of source · line 343 · raw

@dot:Bool -> @c:Char -> @rest:String -> Bool

def is_ident_at source · line 351 · raw

@s:String -> Bool

A word character, or a dot before the start of a word.

def tok source · line 387 · raw

@r:Run -> @sym:Sym -> @name:Bool -> Scan

def fixed source · line 392 · raw

@text:String -> @len:U32 -> @rest:String -> @last:Char -> @sym:Sym -> Scan

def keyword.is source · line 395 · raw

@text:String -> @word:String -> @sym:Sym -> Sym

def keyword source · line 398 · raw

@text:String -> @+keep:String -> Sym

def ident source · line 421 · raw

@r:Run -> Scan

def number.tok source · line 426 · raw

@r:Run -> @inc:Bool -> @name:Bool -> Scan

def exponent.digits source · line 429 · raw

@go:Bool -> @+rest:String -> @mark:String -> @k:U32 -> @keep:String -> @text:String -> @n:U32 -> @last:Char -> @signed:Bool -> Scan

def exponent.sign source · line 450 · raw

@rest:String -> @+again:String -> @mark:String -> @keep:String -> @text:String -> @n:U32 -> @last:Char -> Scan

def exponent.of source · line 467 · raw

@s:String -> @keep:String -> @text:String -> @n:U32 -> @last:Char -> Scan

def exponent source · line 477 · raw

@r:Run -> Scan

After a fraction: [eE][+-]?\d+, if it is there.

def fraction source · line 482 · raw

@go:Bool -> @+rest:String -> @keep:String -> @text:String -> @n:U32 -> @last:Char -> Scan

def number.inc source · line 490 · raw

@s:String -> @keep:String -> @text:String -> @n:U32 -> Scan

After "n": n+, or n alone.

def number.of source · line 497 · raw

@s:String -> @keep:String -> @text:String -> @n:U32 -> @last:Char -> Scan

def number source · line 507 · raw

@r:Run -> Scan

After a number's digits: n, n+, or a fraction and its exponent.

def tail_after source · line 512 · raw

@c:Char -> @tail:Maybe<&2, U32> -> Maybe<&2, U32>

def quote_after source · line 521 · raw

@+c:Char -> @quote:Char -> Quote

def literal.go source · line 530 · raw

@s:String -> @keep:String -> @+quote:Char -> @at:Quote -> @text:String -> @n:U32 -> @last:Char -> @tail:Maybe<&2, U32> -> Scan

literal, with the text so far last character first: on the C lane, ++ copies its left side.

def literal source · line 557 · raw

@s:String -> @keep:String -> @quote:Char -> @at:Quote -> @text:String -> @n:U32 -> @last:Char -> @tail:Maybe<&2, U32> -> Scan

def class_of source · line 569 · raw

@+c:Char -> Class

def single source · line 577 · raw

@c:Char -> Sym

def lex.other source · line 616 · raw

@class:Class -> @+c:Char -> @+rest:String -> Scan

def lex.char source · line 627 · raw

@s:String -> Scan

def lex.dash source · line 634 · raw

@word:Bool -> @keep:String -> @r:String -> Scan

def lex.lt source · line 641 · raw

@rest:String -> @keep:String -> @+prev:Char -> Scan

def lex.shr source · line 656 · raw

@blank:Bool -> @keep:String -> @r:String -> Scan

def lex.gt source · line 663 · raw

@rest:String -> @keep:String -> @prev:Char -> Scan

def lex.dot source · line 672 · raw

@rest:String -> @keep:String -> Scan

def lex.minus source · line 683 · raw

@rest:String -> @keep:String -> Scan

def lex.eq source · line 690 · raw

@rest:String -> @keep:String -> Scan

def lex.bang source · line 699 · raw

@rest:String -> @keep:String -> Scan

def lex.amp source · line 706 · raw

@rest:String -> @keep:String -> Scan

def lex.bar source · line 719 · raw

@rest:String -> @keep:String -> Scan

def lex.plus source · line 726 · raw

@rest:String -> @keep:String -> Scan

def comment source · line 733 · raw

@r:Run -> Scan

def blanks source · line 739 · raw

@s:String -> @keep:String -> @n:U32 -> @last:Char -> Scan

A run of whitespace on one line.

def lex.token source · line 753 · raw

@s:String -> @keep:String -> @prev:Char -> Scan

The token at the start of s; prev is the character before it. Literals and comment text are kept verbatim: a quote or # inside a string is not syntax. Successor notation (1n+) and quantities (&2) are single tokens.

def next_col source · line 788 · raw

@lex:Lex -> @tail:Maybe<&2, U32> -> @col:U32 -> @len:U32 -> U32

def lex.go source · line 798 · raw

@fuel:Nat -> @sc:Scan -> @from:String -> @+at:U32 -> @+col:U32 -> @acc:List<&2, Token> -> List<&2, Token>

Each step reads at least one character, so the text's length is fuel.

def tokens source · line 821 · raw

@+s:String -> List<&2, Token>

def Token.text source · line 826 · raw

@t:Token -> String

Tokens ------

def Token.beg source · line 831 · raw

@t:Token -> U32

def Token.end source · line 836 · raw

@t:Token -> U32

def Token.col source · line 841 · raw

@t:Token -> U32

def Token.sym source · line 846 · raw

@t:Token -> Sym

def Token.is_name source · line 851 · raw

@t:Token -> Bool

def Token.from source · line 856 · raw

@t:Token -> String

def is_comment source · line 861 · raw

@t:Token -> Bool

def is_operator source · line 868 · raw

@s:Sym -> Bool

def is_prefix source · line 922 · raw

@s:Sym -> Bool

A sign or quantity glued to what follows it.

def is_tight source · line 935 · raw

@s:Sym -> Bool

def is_punct source · line 952 · raw

@s:Sym -> Bool

def is_sigil source · line 963 · raw

@s:Sym -> Bool

def is_opener source · line 978 · raw

@s:Sym -> Bool

def is_closer source · line 991 · raw

@s:Sym -> Bool

def is_keyword source · line 1002 · raw

@s:Sym -> Bool

def is_block_word source · line 1019 · raw

@s:Sym -> Bool

def is_continued source · line 1039 · raw

@s:Sym -> Bool

A record that ends in one of these goes on at the next line.

def is_declaration source · line 1054 · raw

@s:Sym -> Bool

def is_import source · line 1067 · raw

@s:Sym -> Bool

def is_sym source · line 1074 · raw

@s:Sym -> @t:Sym -> Bool

def first source · line 1099 · raw

@n:Tree -> Token

Trees -----

def last source · line 1106 · raw

@n:Tree -> Token

def is_newline source · line 1113 · raw

@n:Tree -> Bool

def is_leaf source · line 1120 · raw

@n:Tree -> Bool

def is_leaf_of source · line 1127 · raw

@n:Tree -> @s:Sym -> Bool

def last_of source · line 1141 · raw

@xs:List<&2, Tree> -> @at:Maybe<&2, Tree> -> Maybe<&2, Tree>

def upcoming source · line 1149 · raw

@xs:List<&2, Tree> -> Maybe<&2, Tree>

The first tree after a run of newlines.

def closer source · line 1159 · raw

@s:Sym -> Sym

What closes the group s opens, or Word{}.

def is_angled source · line 1172 · raw

@prev:Maybe<&2, Token> -> @t:Token -> Bool

def opens.of source · line 1180 · raw

@s:Sym -> @t:Token -> @prev:Maybe<&2, Token> -> Bool

Whether t opens a group: a glued < opens type arguments.

def opens source · line 1193 · raw

@+t:Token -> @prev:Maybe<&2, Token> -> Bool

def is_block_leaf source · line 1196 · raw

@n:Tree -> Bool

def add source · line 1203 · raw

@+n:Tree -> @stack:List<&2, Open> -> @root:List<&2, Tree> -> Built

def waits source · line 1210 · raw

@stack:List<&2, Open> -> @s:Sym -> Bool

def pop source · line 1217 · raw

@t:Token -> @stack:List<&2, Open> -> @root:List<&2, Tree> -> Built

def tree.close source · line 1224 · raw

@closes:Bool -> @t:Token -> @stack:List<&2, Open> -> @root:List<&2, Tree> -> Built

def tree.step source · line 1231 · raw

@opens:Bool -> @+t:Token -> @+stack:List<&2, Open> -> @root:List<&2, Tree> -> Built

def tree.go source · line 1238 · raw

@ts:List<&2, Token> -> @prev:Maybe<&2, Token> -> @b:Built -> Maybe<&2, List<&2, Tree>>

def measure source · line 1249 · raw

@s:String -> @+n:U32 -> @tail:Maybe<&2, U32> -> @keep:U32 -> Measure

Docs ----

def str.split source · line 1261 · raw

@whole:Bool -> @+s:String -> @width:U32 -> @tail:Maybe<&2, U32> -> @+keep:U32 -> Doc

def str.of source · line 1268 · raw

@s:String -> @m:Measure -> Doc

def str source · line 1273 · raw

@+s:String -> Doc

def text source · line 1277 · raw

@s:String -> @width:U32 -> Doc

A doc for text of this width, with no newline and no trailing whitespace.

def space source · line 1280 · raw

@s:String -> @width:U32 -> Doc

def nothing source · line 1283 · raw

Doc

def soft source · line 1286 · raw

@flat:String -> @width:U32 -> Doc

def hard source · line 1289 · raw

@offset:U32 -> Doc

def flat_of source · line 1292 · raw

@d:Doc -> Flat

def flat_then source · line 1310 · raw

@a:Flat -> @rest:Flat -> Flat

The Flat of a doc a, then of what follows it.

def flat_rev source · line 1317 · raw

@docs:List<&2, Doc> -> @acc:Flat -> Flat

def grp source · line 1324 · raw

@+d:Doc -> Doc

def nest source · line 1327 · raw

@+d:Doc -> @amount:U32 -> Doc

def cat_rev source · line 1331 · raw

@+docs:List<&2, Doc> -> Doc

A Cat of docs last first.

def cat source · line 1335 · raw

@docs:List<&2, Doc> -> Doc

A Cat of a few docs, in order.

def code source · line 1338 · raw

@t:Token -> Doc

def is_glued_prefix source · line 1343 · raw

@+a:Token -> @b:Maybe<&2, Tree> -> Bool

def is_callee source · line 1351 · raw

@+x:Token -> Bool

Whether a group after x is its argument list or type arguments.

def is_inc source · line 1357 · raw

@s:Sym -> Bool

def separator.of source · line 1368 · raw

@+x:Token -> @+y:Token -> @+group:Bool -> @b:Tree -> Doc

What goes between x and the tree b that y starts. A constructor's brace is glued to its name; a brace after a space can instead be the next (annotated) argument of a call without commas, so the space stays. Other atoms need a space.

def separator source · line 1411 · raw

@a:Tree -> @+b:Tree -> Doc

def comment_text.after source · line 1416 · raw

@rest:String -> @+keep:String -> String

"#x" gets a space; empty comments, whitespace, test expectations (#|), directives (#!) and headings (##) stay as they are.

def comment_text source · line 1428 · raw

@text:String -> @keep:String -> String

def leaf_doc source · line 1435 · raw

@+t:Token -> Doc

def should_pop source · line 1448 · raw

@levels:List<&2, U32> -> @col:U32 -> Bool

Levels ------

def pop_levels source · line 1455 · raw

@levels:List<&2, U32> -> @+col:U32 -> @go:Bool -> List<&2, U32>

def deepen source · line 1464 · raw

@levels:List<&2, U32> -> @+col:U32 -> List<&2, U32>

def indented source · line 1472 · raw

@+levels:List<&2, U32> -> @+col:U32 -> List<&2, U32>

Closes the levels deeper than col, then opens col if it is deeper.

def depth.go source · line 1475 · raw

@levels:List<&2, U32> -> @n:U32 -> U32

def depth source · line 1482 · raw

@levels:List<&2, U32> -> U32

def fresh source · line 1487 · raw

@base:U32 -> Seq

Sequences ---------

def Seq.put source · line 1490 · raw

@s:Seq -> @d:Doc -> Seq

def Seq.chain source · line 1497 · raw

@s:Seq -> Seq

def Seq.doc source · line 1504 · raw

@s:Seq -> @tab:U32 -> Doc

def is_prev_comment source · line 1511 · raw

@prev:Maybe<&2, Tree> -> Bool

def Seq.level source · line 1519 · raw

@+levels:List<&2, U32> -> @tab:U32 -> @out:List<&2, Doc> -> @chain:Maybe<&2, List<&2, Doc>> -> Seq

A run of newlines breaks the line at the next tree's level.

def Seq.end source · line 1527 · raw

@comment:Bool -> @s:Seq -> Seq

def Seq.break source · line 1534 · raw

@up:Maybe<&2, Tree> -> @tab:U32 -> @s:Seq -> Seq

def Seq.newline.if source · line 1541 · raw

@trigger:Bool -> @rest:List<&2, Tree> -> @tab:U32 -> @s:Seq -> Seq

def Seq.newline source · line 1548 · raw

@rest:List<&2, Tree> -> @tab:U32 -> @raw:Bool -> @s:Seq -> Seq

def Seq.joint source · line 1560 · raw

@chain:Bool -> @p:Tree -> @n:Tree -> @s:Seq -> Seq

def Seq.tree source · line 1567 · raw

@+n:Tree -> @d:Doc -> @next:Maybe<&2, Tree> -> @raw:Bool -> @s:Seq -> Seq

def Seq.step source · line 1587 · raw

@newline:Bool -> @n:Tree -> @d:Doc -> @rest:List<&2, Tree> -> @tab:U32 -> @raw:Bool -> @s:Seq -> Seq

def Seq.visit source · line 1602 · raw

@+n:Tree -> @d:Doc -> @rest:List<&2, Tree> -> @tab:U32 -> @raw:Bool -> @s:Seq -> Seq

def Split.fresh source · line 1607 · raw

Split

Parts -----

def Split.track source · line 1610 · raw

@+n:Tree -> @attach:Bool -> @sp:Split -> Split

def Split.end source · line 1621 · raw

@tab:U32 -> @base:U32 -> @st:State -> State

def Split.comments source · line 1635 · raw

@n:Tree -> @sp:Split -> Split

def has_head_comment source · line 1640 · raw

@xs:List<&2, Tree> -> Bool

def Split.act source · line 1647 · raw

@n:Tree -> @rest:List<&2, Tree> -> @sp:Split -> Act

def Split.apply source · line 1659 · raw

@act:Act -> @+n:Tree -> @d:Doc -> @rest:List<&2, Tree> -> @+tab:U32 -> @base:U32 -> @st:State -> State

def Seq.anchor source · line 1684 · raw

@+n:Tree -> @s:Seq -> Seq

A part's lines start at the column of its first tree: a line after a comment in it (a directive before a parameter) keeps the part's indentation.

def Split.visit source · line 1697 · raw

@+n:Tree -> @d:Doc -> @+rest:List<&2, Tree> -> @tab:U32 -> @base:U32 -> @st:State -> State

def should_drop source · line 1710 · raw

@parts:List<&2, Part> -> Bool

def drop_parts source · line 1718 · raw

@parts:List<&2, Part> -> @go:Bool -> List<&2, Part>

Drops the trailing parts that hold only newlines, keeping one part.

def content.sep source · line 1729 · raw

@comment:Bool -> @comments:Bool -> @acc:List<&2, Doc> -> List<&2, Doc>

What goes before a part: a line break after a part that ends in a comment (its comma is before the comment); else a comma, then a line break if a part of the group has a comment (comments), so each part keeps its own line.

def content.go source · line 1738 · raw

@parts:List<&2, Part> -> @comment:Bool -> @+comments:Bool -> @acc:List<&2, Doc> -> List<&2, Doc>

def content source · line 1751 · raw

@parts:List<&2, Part> -> @comments:Bool -> List<&2, Doc>

The parts' docs with their separators, last first.

def opening source · line 1758 · raw

@comments:Bool -> Doc

def closing source · line 1767 · raw

@close:Token -> @comments:Bool -> Doc

A generic's closing > stays glued to the term before it: Bend parses a spaced > as a comparison, even across a newline.

def Split.doc source · line 1770 · raw

@open:Token -> @+close:Token -> @tab:U32 -> @st:State -> Doc

def mode_of source · line 1796 · raw

@open:Token -> @close:Token -> @children:List<&2, Tree> -> @block:Bool -> Mode

Build -----

def start source · line 1805 · raw

@base:U32 -> State

def visit source · line 1808 · raw

@+mode:Mode -> @n:Tree -> @d:Doc -> @rest:List<&2, Tree> -> @tab:U32 -> @base:U32 -> @st:State -> State

def finish source · line 1827 · raw

@mode:Mode -> @st:State -> @+tab:U32 -> @base:U32 -> Doc

def build source · line 1840 · raw

@nodes:List<&2, Tree> -> @+tab:U32 -> @+base:U32 -> @+mode:Mode -> @st:State -> Doc

The doc of a list of trees, read as mode says. A group's children are built first, by the same def, as a smaller part of the list.

def sequence source · line 1863 · raw

@nodes:List<&2, Tree> -> @tab:U32 -> @+base:U32 -> Doc

def push source · line 1869 · raw

@docs:List<&2, Doc> -> @+indent:U32 -> @+flat:Bool -> @jobs:List<&2, Job> -> List<&2, Job>

Printer ------- Jobs for a Cat's docs, last first, so its first doc ends on top.

def fits.flat.of source · line 1876 · raw

@over:Bool -> @brk:Bool -> @jobs:List<&2, Job> -> @left:U32 -> Fit

def fits.flat source · line 1886 · raw

@f:Flat -> @jobs:List<&2, Job> -> @+left:U32 -> Fit

A doc printed flat, whole: past the width, or up to a break within it.

def fits.width source · line 1891 · raw

@stop:Bool -> @+n:U32 -> @jobs:List<&2, Job> -> @+left:U32 -> Fit

def fits.step source · line 1898 · raw

@jobs:List<&2, Job> -> @left:U32 -> Fit

def fits.go source · line 1915 · raw

@fuel:Nat -> @f:Fit -> Bool

def fits.from source · line 1924 · raw

@over:Bool -> @fuel:Nat -> @left:U32 -> @jobs:List<&2, Job> -> Bool

def fits source · line 1932 · raw

@fuel:Nat -> @+width:U32 -> @+col:U32 -> @jobs:List<&2, Job> -> Bool

Whether the jobs fit before their first break, from col.

def col_of source · line 1935 · raw

@tail:Maybe<&2, U32> -> @col:U32 -> @width:U32 -> U32

def print.str source · line 1944 · raw

@body:String -> @keep:String -> @blank:String -> @jobs:List<&2, Job> -> @out:List<&2, String> -> @pending:String -> @col:U32 -> Print

Text goes out after the pending whitespace; its own trailing whitespace becomes pending.

def print.line source · line 1959 · raw

@flat:Bool -> @text:String -> @+at:U32 -> @jobs:List<&2, Job> -> @out:List<&2, String> -> @pending:String -> @col:U32 -> @width:U32 -> @newline:String -> Print

def print.is_flat source · line 1976 · raw

@flat:Bool -> @fuel:Nat -> @+width:Maybe<&2, U32> -> @col:U32 -> @jobs:List<&2, Job> -> Bool

def is_unbounded source · line 1991 · raw

@width:Maybe<&2, U32> -> Bool

def print.step source · line 1998 · raw

@jobs:List<&2, Job> -> @out:List<&2, String> -> @pending:String -> @+col:U32 -> @width:Maybe<&2, U32> -> @newline:String -> @fuel:Nat -> Print

def print.go source · line 2044 · raw

@fuel:Nat -> @p:Print -> @+width:Maybe<&2, U32> -> @+newline:String -> @+budget:Nat -> String

The text so far; pending whitespace is never written at the end.

@doc:Doc -> @width:Maybe<&2, U32> -> @+indent:U32 -> @newline:String -> @+fuel:Nat -> String

The doc at indent; fuel bounds the steps of the printer and of each fit. A group is all flat if it fits; else its separators break together. Nesting is relative, never aligned under a function name. The width is a target, not a license to split atoms.

def joins.of source · line 2074 · raw

@+p:Tree -> @+next:Tree -> @following:Maybe<&2, Tree> -> Bool

Records -------

def joins source · line 2091 · raw

@previous:Maybe<&2, Tree> -> @rest:List<&2, Tree> -> Bool

Whether a newline between previous and rest continues the record.

def records.newline source · line 2098 · raw

@join:Bool -> @done:List<&2, List<&2, Tree>> -> @current:List<&2, Tree> -> Recs

def records.step source · line 2105 · raw

@newline:Bool -> @n:Tree -> @rest:List<&2, Tree> -> @done:List<&2, List<&2, Tree>> -> @+current:List<&2, Tree> -> Recs

def records source · line 2118 · raw

@nodes:List<&2, Tree> -> @r:Recs -> List<&2, List<&2, Tree>>

def cut.step source · line 2125 · raw

@+n:Tree -> @c:Cut -> Cut

def cut.go source · line 2132 · raw

@xs:List<&2, Tree> -> @c:Cut -> Cut

def cut.is_inline source · line 2140 · raw

@c:Cut -> Bool

Whether the cut has a body after its colon that is not a comment.

def is_not_hash source · line 2147 · raw

@s:String -> Bool

def split_hash.of source · line 2156 · raw

@r:Run -> Hash

def split_hash source · line 2163 · raw

@+s:String -> Hash

def import_space.of source · line 2166 · raw

@+rest:String -> @s:String -> String

def import_space source · line 2169 · raw

@+s:String -> String

def is_alias_at.as source · line 2172 · raw

@s:String -> Bool

def is_alias_at source · line 2179 · raw

@+s:String -> Bool

def alias.go source · line 2182 · raw

@s:String -> @hit:Bool -> @acc:String -> String

def alias source · line 2191 · raw

@+s:String -> String

def import_doc.of source · line 2194 · raw

@h:Hash -> Doc

def record_end source · line 2208 · raw

@head:Token -> @record:List<&2, Tree> -> U32

Where the record that head starts ends.

def import_doc source · line 2213 · raw

@+head:Token -> @record:List<&2, Tree> -> Doc

Paths and aliases have their own grammar: / and - are not operators there, so an import keeps its text and only its spacing changes.

def decl_doc.of source · line 2225 · raw

@inline:Bool -> @c:Cut -> @record:List<&2, Tree> -> @+tab:U32 -> @+col:U32 -> Doc

def decl_doc.cut source · line 2232 · raw

@+c:Cut -> @record:List<&2, Tree> -> @declaration:Bool -> @tab:U32 -> @+col:U32 -> Doc

def decl_doc source · line 2237 · raw

@+record:List<&2, Tree> -> @declaration:Bool -> @tab:U32 -> @col:U32 -> Doc

A declaration's body on the line of its colon moves to the next line, indented.

def record_doc source · line 2240 · raw

@is_import:Bool -> @head:Token -> @record:List<&2, Tree> -> @declaration:Bool -> @tab:U32 -> @col:U32 -> Doc

def joined source · line 2255 · raw

@xs:List<&2, Tree> -> @acc:List<&2, String> -> String

The text of the first tokens of xs, after acc, the texts so far, last first.

def is_unsafe source · line 2262 · raw

@at:Bool -> @record:List<&2, Tree> -> Bool

def gapped source · line 2269 · raw

@gap:Bool -> @rows:List<&2, String> -> List<&2, String>

def rows.line source · line 2276 · raw

@+head:Token -> @+record:List<&2, Tree> -> @+set:Settings -> @r:Rows -> Rows

def rows.step source · line 2301 · raw

@record:List<&2, Tree> -> @set:Settings -> @r:Rows -> Rows

def rows.go source · line 2308 · raw

@records:List<&2, List<&2, Tree>> -> @+set:Settings -> @r:Rows -> Rows

def is_head_empty source · line 2315 · raw

@rows:List<&2, String> -> Bool

def drop_empty source · line 2322 · raw

@rows:List<&2, String> -> @go:Bool -> List<&2, String>

def join source · line 2329 · raw

@rows:List<&2, String> -> @+newline:String -> @acc:String -> String

def text_of.trimmed source · line 2338 · raw

@rows:List<&2, String> -> @+newline:String -> String

The rows, last first, joined, without the empty rows at the end, with a newline. Each row has no trailing whitespace already.

def text_of source · line 2345 · raw

@+rows:List<&2, String> -> @newline:String -> String

def format.text source · line 2348 · raw

@r:Rows -> @newline:String -> String

def format.of source · line 2353 · raw

@nodes:Maybe<&2, List<&2, Tree>> -> @+set:Settings -> Maybe<&2, String>

def format source · line 2370 · raw

@source:String -> @set:Settings -> Maybe<&2, String>

The formatted text, or None{} if its delimiters do not balance.

def differ source · line 2377 · raw

@a:String -> @b:String -> @at:U32 -> @same:Bool -> U32

Where a and b first differ: same is whether the characters before at were the same.

def line_end source · line 2387 · raw

@s:String -> @i:U32 -> U32

Where the line that s starts, at i, ends: before its newline, or at the end of the text.

def judged source · line 2396 · raw

@same:Bool -> @+out:String -> @+text:String -> @+path:String -> List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Finding>

def judge source · line 2416 · raw

@formatted:Maybe<&2, String> -> @+text:String -> @path:String -> List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Finding>

def first_newline source · line 2430 · raw

@s:String -> String

def newline.preserve source · line 2441 · raw

@preserve:Bool -> @source:String -> String

def newline.crlf source · line 2448 · raw

@crlf:Bool -> @eol:String -> @source:String -> String

def newline_of source · line 2455 · raw

@+eol:String -> @source:String -> String

def width_of source · line 2458 · raw

@value:Maybe<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Value> -> Maybe<&2, U32>

def settings source · line 2465 · raw

@+here:0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Here -> Settings

def run source · line 2472 · raw

@+here:0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Here -> 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Ask(List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Finding>)

def options source · line 2477 · raw

List<&2, 0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Declared>

def rule source · line 2488 · raw

0x534e77ab9e7d8d3c817c84cab8139f38/linter/api/spec.Rule

Templates

template head_passes source · line 272 · raw

@-test:(@+c:Char -> Bool) -> @s:String -> Bool

template scan.go source · line 359 · raw

@-test:(@_:String -> Bool) -> @s:String -> @keep:String -> @ok:Bool -> @text:String -> @n:U32 -> @last:Char -> Run

scan, with the text so far last character first: on the C lane, ++ copies its left side.

template scan source · line 376 · raw

@-test:(@_:String -> Bool) -> @s:String -> @keep:String -> @ok:Bool -> @text:String -> @n:U32 -> @last:Char -> Run

Reads characters while test holds, after text; test sees the text from each character on, so it can look ahead.