1 # src/src: one file, read once and parsed once. A rule is handed this, not 2 # the text: a tree parse of a 156 KB file costs 1.5 s here (the lexer alone 3 # 54 ms, and `Bind.bound` parses again), so twenty rules that each parsed 4 # the text made the linter twenty times slower than it needs to be. 5 import Base 6 import ./syntax/lex.bend as Lex 7 import ./syntax/tree.bend as Tree 8 import ./syntax/bind.bend as Bind 9 import ./syntax/outline.bend as Outline 10 11 # the path, the text, and the three readings of it every rule shares 12 type Src is Data: 13 Src{path: String, text: String, toks: List<&2, Lex.Tok>, tree: Tree.Node, bound: Bind.Bound, 14 items: List<&2, Outline.Item>} 15 16 # read a file's text once 17 def of(+path: String, +text: String) -> Src: 18 +toks = Lex.tokens(text) 19 +tree = Tree.of_tokens(toks) 20 Src{path, text, toks, tree, Bind.of_tree(tree, String.lines(text)), Outline.of_tokens(text, toks)}