You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

brainfuck.go 709B

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