~/bend-docscommunity

layout/format.bend checks

raw source on the hub · import bend-lint-rules@0.2.0.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.

3 imports
import Base
import bend-lint-api@0.2.0.0/linter/lint.bend as Lint
import bend-lint-api@0.2.0.0/shared/strings.bend as Strings

Types

type Lex source · line 21 · raw

Data

Types =====

type Sym source · line 28 · raw

Data

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

type Token source · line 87 · 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 102 · 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 118 · raw

Data

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

type Quote source · line 122 · raw

Data

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

type Class source · line 127 · raw

Data

type Tree source · line 133 · raw

Data

type Open source · line 139 · 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 142 · raw

Data

type Flat source · line 147 · 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 154 · 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 161 · raw

Data

type Mode source · line 168 · 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 177 · 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 188 · 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 193 · 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 196 · raw

Data

type Act source · line 200 · raw

Data

What a child of a group does to its parts.

type Job source · line 206 · 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 215 · raw

Data

type Recs source · line 220 · raw

Data

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

type Cut source · line 224 · raw

Data

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

type Hash source · line 227 · raw

Data

type Rows source · line 231 · raw

Data

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

type Settings source · line 235 · raw

Data

width: None{} for "never".

Definitions

def fuel_per_point source · line 242 · raw

U32

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

def is_blank source · line 252 · raw

@+c:Char -> Bool

Whitespace, as Bend's parser reads it.

def is_head source · line 265 · raw

@+c:Char -> Bool

def is_word source · line 268 · raw

@+c:Char -> Bool

def char source · line 278 · raw

@c:Char -> String

def drop_blank.go source · line 281 · raw

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

def drop_blank source · line 290 · raw

@+s:String -> String

def trim_end source · line 293 · raw

@s:String -> String

def pad source · line 296 · raw

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

def is_same.go source · line 305 · 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 314 · raw

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

def is_not_line_end source · line 324 · 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 335 · raw

@s:String -> Bool

def is_ident_at.of source · line 342 · raw

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

def is_ident_at source · line 350 · raw

@s:String -> Bool

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

def tok source · line 386 · raw

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

def fixed source · line 391 · raw

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

def keyword.is source · line 394 · raw

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

def keyword source · line 397 · raw

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

def ident source · line 420 · raw

@r:Run -> Scan

def number.tok source · line 425 · raw

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

def exponent.digits source · line 428 · 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 449 · raw

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

def exponent.of source · line 466 · raw

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

def exponent source · line 476 · raw

@r:Run -> Scan

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

def fraction source · line 481 · raw

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

def number.inc source · line 489 · raw

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

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

def number.of source · line 496 · raw

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

def number source · line 506 · raw

@r:Run -> Scan

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

def tail_after source · line 511 · raw

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

def quote_after source · line 520 · raw

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

def literal.go source · line 529 · 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 556 · 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 568 · raw

@+c:Char -> Class

def single source · line 576 · raw

@c:Char -> Sym

def lex.other source · line 615 · raw

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

def lex.char source · line 626 · raw

@s:String -> Scan

def lex.dash source · line 633 · raw

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

def lex.lt source · line 640 · raw

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

def lex.shr source · line 655 · raw

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

def lex.gt source · line 662 · raw

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

def lex.dot source · line 671 · raw

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

def lex.minus source · line 682 · raw

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

def lex.eq source · line 689 · raw

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

def lex.bang source · line 698 · raw

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

def lex.amp source · line 705 · raw

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

def lex.bar source · line 718 · raw

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

def lex.plus source · line 725 · raw

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

def comment source · line 732 · raw

@r:Run -> Scan

def blanks source · line 738 · raw

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

A run of whitespace on one line.

def lex.token source · line 752 · 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 787 · raw

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

def lex.go source · line 797 · 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 820 · raw

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

def Token.text source · line 825 · raw

@t:Token -> String

Tokens ------

def Token.beg source · line 830 · raw

@t:Token -> U32

def Token.end source · line 835 · raw

@t:Token -> U32

def Token.col source · line 840 · raw

@t:Token -> U32

def Token.sym source · line 845 · raw

@t:Token -> Sym

def Token.is_name source · line 850 · raw

@t:Token -> Bool

def Token.from source · line 855 · raw

@t:Token -> String

def is_comment source · line 860 · raw

@t:Token -> Bool

def is_operator source · line 867 · raw

@s:Sym -> Bool

def is_prefix source · line 921 · raw

@s:Sym -> Bool

A sign or quantity glued to what follows it.

def is_tight source · line 934 · raw

@s:Sym -> Bool

def is_punct source · line 951 · raw

@s:Sym -> Bool

def is_sigil source · line 962 · raw

@s:Sym -> Bool

def is_opener source · line 977 · raw

@s:Sym -> Bool

def is_closer source · line 990 · raw

@s:Sym -> Bool

def is_keyword source · line 1001 · raw

@s:Sym -> Bool

def is_block_word source · line 1018 · raw

@s:Sym -> Bool

def is_continued source · line 1038 · raw

@s:Sym -> Bool

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

def is_declaration source · line 1053 · raw

@s:Sym -> Bool

def is_import source · line 1066 · raw

@s:Sym -> Bool

def is_sym source · line 1073 · raw

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

def first source · line 1098 · raw

@n:Tree -> Token

Trees -----

def last source · line 1105 · raw

@n:Tree -> Token

def is_newline source · line 1112 · raw

@n:Tree -> Bool

def is_leaf source · line 1119 · raw

@n:Tree -> Bool

def is_leaf_of source · line 1126 · raw

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

def last_of source · line 1140 · raw

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

def upcoming source · line 1148 · raw

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

The first tree after a run of newlines.

def closer source · line 1158 · raw

@s:Sym -> Sym

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

def is_angled source · line 1171 · raw

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

def opens.of source · line 1179 · raw

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

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

def opens source · line 1192 · raw

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

def is_block_leaf source · line 1195 · raw

@n:Tree -> Bool

def add source · line 1202 · raw

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

def waits source · line 1209 · raw

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

def pop source · line 1216 · raw

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

def tree.close source · line 1223 · raw

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

def tree.step source · line 1230 · raw

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

def tree.go source · line 1237 · raw

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

def measure source · line 1248 · raw

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

Docs ----

def str.split source · line 1260 · raw

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

def str.of source · line 1267 · raw

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

def str source · line 1272 · raw

@+s:String -> Doc

def text source · line 1276 · raw

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

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

def space source · line 1279 · raw

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

def nothing source · line 1282 · raw

Doc

def soft source · line 1285 · raw

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

def hard source · line 1288 · raw

@offset:U32 -> Doc

def flat_of source · line 1291 · raw

@d:Doc -> Flat

def flat_then source · line 1309 · raw

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

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

def flat_rev source · line 1316 · raw

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

def grp source · line 1323 · raw

@+d:Doc -> Doc

def nest source · line 1326 · raw

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

def cat_rev source · line 1330 · raw

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

A Cat of docs last first.

def cat source · line 1334 · raw

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

A Cat of a few docs, in order.

def code source · line 1337 · raw

@t:Token -> Doc

def is_glued_prefix source · line 1342 · raw

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

def is_callee source · line 1350 · raw

@+x:Token -> Bool

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

def is_inc source · line 1356 · raw

@s:Sym -> Bool

def separator.of source · line 1367 · 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 1410 · raw

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

def comment_text.after source · line 1415 · 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 1427 · raw

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

def leaf_doc source · line 1434 · raw

@+t:Token -> Doc

def should_pop source · line 1447 · raw

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

Levels ------

def pop_levels source · line 1454 · raw

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

def deepen source · line 1463 · raw

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

def indented source · line 1471 · 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 1474 · raw

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

def depth source · line 1481 · raw

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

def fresh source · line 1486 · raw

@base:U32 -> Seq

Sequences ---------

def Seq.put source · line 1489 · raw

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

def Seq.chain source · line 1496 · raw

@s:Seq -> Seq

def Seq.doc source · line 1503 · raw

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

def is_prev_comment source · line 1510 · raw

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

def Seq.level source · line 1518 · 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 1526 · raw

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

def Seq.break source · line 1533 · raw

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

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

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

def Seq.newline source · line 1547 · raw

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

def Seq.joint source · line 1559 · raw

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

def Seq.tree source · line 1566 · raw

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

def Seq.step source · line 1586 · raw

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

def Seq.visit source · line 1601 · raw

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

def Split.fresh source · line 1606 · raw

Split

Parts -----

def Split.track source · line 1609 · raw

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

def Split.end source · line 1620 · raw

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

def Split.comments source · line 1634 · raw

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

def has_head_comment source · line 1639 · raw

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

def Split.act source · line 1646 · raw

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

def Split.apply source · line 1658 · raw

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

def Split.visit source · line 1681 · raw

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

def should_drop source · line 1686 · raw

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

def drop_parts source · line 1694 · 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 1703 · raw

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

def content.go source · line 1710 · raw

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

def content source · line 1718 · raw

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

The parts' docs with their separators, last first.

def opening source · line 1725 · raw

@comments:Bool -> Doc

def closing source · line 1734 · 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 1737 · raw

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

def mode_of source · line 1761 · raw

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

Build -----

def start source · line 1770 · raw

@base:U32 -> State

def visit source · line 1773 · raw

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

def finish source · line 1792 · raw

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

def build source · line 1805 · 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 1828 · raw

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

def push source · line 1834 · 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 1841 · raw

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

def fits.flat source · line 1851 · 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 1856 · raw

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

def fits.step source · line 1863 · raw

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

def fits.go source · line 1880 · raw

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

def fits.from source · line 1889 · raw

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

def fits source · line 1897 · 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 1900 · raw

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

def print.str source · line 1909 · 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 1924 · 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 1941 · raw

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

def is_unbounded source · line 1956 · raw

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

def print.step source · line 1963 · 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 2009 · 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 2039 · raw

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

Records -------

def joins source · line 2056 · 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 2063 · raw

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

def records.step source · line 2070 · raw

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

def records source · line 2083 · raw

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

def cut.step source · line 2090 · raw

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

def cut.go source · line 2097 · raw

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

def cut.is_inline source · line 2105 · raw

@c:Cut -> Bool

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

def is_not_hash source · line 2112 · raw

@s:String -> Bool

def split_hash.of source · line 2121 · raw

@r:Run -> Hash

def split_hash source · line 2128 · raw

@+s:String -> Hash

def import_space.of source · line 2131 · raw

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

def import_space source · line 2134 · raw

@+s:String -> String

def is_alias_at.as source · line 2137 · raw

@s:String -> Bool

def is_alias_at source · line 2144 · raw

@+s:String -> Bool

def alias.go source · line 2147 · raw

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

def alias source · line 2156 · raw

@+s:String -> String

def import_doc.of source · line 2159 · raw

@h:Hash -> Doc

def record_end source · line 2173 · raw

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

Where the record that head starts ends.

def import_doc source · line 2178 · 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 2190 · raw

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

def decl_doc.cut source · line 2197 · raw

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

def decl_doc source · line 2202 · 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 2205 · raw

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

def joined source · line 2220 · 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 2227 · raw

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

def gapped source · line 2234 · raw

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

def rows.line source · line 2241 · raw

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

def rows.step source · line 2266 · raw

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

def rows.go source · line 2273 · raw

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

def is_head_empty source · line 2280 · raw

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

def drop_empty source · line 2287 · raw

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

def join source · line 2294 · raw

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

def text_of.trimmed source · line 2303 · 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 2310 · raw

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

def format.text source · line 2313 · raw

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

def format.of source · line 2318 · raw

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

def format source · line 2335 · raw

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

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

def differ source · line 2342 · 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 2352 · 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 2361 · raw

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

def judge source · line 2381 · raw

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

def first_newline source · line 2395 · raw

@s:String -> String

def newline.preserve source · line 2406 · raw

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

def newline.crlf source · line 2413 · raw

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

def newline_of source · line 2420 · raw

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

def width_of source · line 2423 · raw

@value:Maybe<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Value> -> Maybe<&2, U32>

def settings source · line 2430 · raw

@+here:0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Here -> Settings

def run source · line 2437 · raw

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

def options source · line 2442 · raw

List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Declared>

def rule source · line 2453 · raw

0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Rule

Templates

template head_passes source · line 271 · raw

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

template scan.go source · line 358 · 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 375 · 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.