main.bend
bolt@1.20.0.0 · 47 lines · 0 definitions
1# bolt: a linter, checker and language server for Bend 2.
2#
3# The one binary. Shake parses the line: `lint`, or a word that is no
4# subcommand, or nothing, lints the files named after it (every `.bend` file
5# under the current directory when none are); `check` runs the checker on
6# them; `lsp` serves an editor over stdio; `help` (or `--help`) prints usage; `--version`
7# prints the release and the short commit when the build has one. Build it
8# native (`bend main.bend -o bin/bolt.bin`). `bolt lsp` runs on the cores:
9# with no runtime `--gpu` it is `+RTS --gpu off -RTS lsp`, and
10# `+RTS --gpu on -RTS` or `+RTS --gpu 4GB -RTS` asks for the device. Runtime
11# options go between `+RTS` and `-RTS` (bend 2.0.38); bolt declares no
12# `--gpu` of its own, so `bolt --gpu off` is an unknown option. What the line
13# does is Args.out's decision (src/LAWS.bend proves it); this file only does
14# it, and LAWS.bend states what src/stop.bend's say and leave do.
15# Everything under src/ is internal.
16import Base
17import bolt@1.20.0.0/src/args.bend as Args
18import bolt@1.20.0.0/src/lint.bend as Lint
19import bolt@1.20.0.0/src/check.bend as Check
20import bolt@1.20.0.0/src/lsp/run.bend as Lsp
21import bolt@1.20.0.0/src/lsp/checker/bend.bend as BendChecker
22import bolt@1.20.0.0/src/stop.bend as Stop
23
24# what a subcommand runs, over the files after it
25def dispatch(cmd: Args.Cmd, paths: List<&2, String>) -> IO(Unit): # noqa: L001 IO driver
26 match cmd:
27 case Args.CLint{}:
28 Lint.run(paths)
29 case Args.CCheck{}:
30 Check.run(~BendChecker.service(), paths)
31 case Args.CLsp{}:
32 Lsp.run()
33
34# what a parsed line does, done
35def perform(oo: Args.Out) -> IO(Unit): # noqa: L001 IO driver
36 match oo:
37 case Args.Stop{to, text, code}:
38 do IO<Unit>:
39 Stop.say(to, text)
40 Stop.leave(code)
41 case Args.Go{cmd, paths}:
42 dispatch(cmd, paths)
43
44def main() -> IO(Unit): # noqa: L001 IO entry point
45 do IO<Unit>:
46 +av : List<&2, String> <- Args.argv()
47 perform(Args.out(Args.parse(Args.line(av))))