...
1 package b
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var Brainfuck = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "Brainfuck",
12 Aliases: []string{"brainfuck", "bf"},
13 Filenames: []string{"*.bf", "*.b"},
14 MimeTypes: []string{"application/x-brainfuck"},
15 },
16 brainfuckRules,
17 ))
18
19 func brainfuckRules() Rules {
20 return Rules{
21 "common": {
22 {`[.,]+`, NameTag, nil},
23 {`[+-]+`, NameBuiltin, nil},
24 {`[<>]+`, NameVariable, nil},
25 {`[^.,+\-<>\[\]]+`, Comment, nil},
26 },
27 "root": {
28 {`\[`, Keyword, Push("loop")},
29 {`\]`, Error, nil},
30 Include("common"),
31 },
32 "loop": {
33 {`\[`, Keyword, Push()},
34 {`\]`, Keyword, Pop(1)},
35 Include("common"),
36 },
37 }
38 }
39
View as plain text