~/bend-docscommunity

src/src.bend source

src/src.bend on the hub · documented module

# src/src: one file, read once and parsed once. A rule is handed this, not# the text: a tree parse of a 156 KB file costs 1.5 s here (the lexer alone# 54 ms, and `Bind.bound` parses again), so twenty rules that each parsed# the text made the linter twenty times slower than it needs to be.import Baseimport ./syntax/lex.bend as Leximport ./syntax/tree.bend as Treeimport ./syntax/bind.bend as Bindimport ./syntax/outline.bend as Outline# the path, the text, and the three readings of it every rule sharestype Src is Data:  Src{path: String, text: String, toks: List<&2, Lex.Tok>, tree: Tree.Node, bound: Bind.Bound,    items: List<&2, Outline.Item>}# read a file's text oncedef of(+path: String, +text: String) -> Src:  +toks = Lex.tokens(text)  +tree = Tree.of_tokens(toks)  Src{path, text, toks, tree, Bind.of_tree(tree, String.lines(text)), Outline.of_tokens(text, toks)}