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.

ebnf.go 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package e
  2. import (
  3. . "github.com/alecthomas/chroma" // nolint
  4. "github.com/alecthomas/chroma/lexers/internal"
  5. )
  6. // Ebnf lexer.
  7. var Ebnf = internal.Register(MustNewLexer(
  8. &Config{
  9. Name: "EBNF",
  10. Aliases: []string{"ebnf"},
  11. Filenames: []string{"*.ebnf"},
  12. MimeTypes: []string{"text/x-ebnf"},
  13. },
  14. Rules{
  15. "root": {
  16. Include("whitespace"),
  17. Include("comment_start"),
  18. Include("identifier"),
  19. {`=`, Operator, Push("production")},
  20. },
  21. "production": {
  22. Include("whitespace"),
  23. Include("comment_start"),
  24. Include("identifier"),
  25. {`"[^"]*"`, LiteralStringDouble, nil},
  26. {`'[^']*'`, LiteralStringSingle, nil},
  27. {`(\?[^?]*\?)`, NameEntity, nil},
  28. {`[\[\]{}(),|]`, Punctuation, nil},
  29. {`-`, Operator, nil},
  30. {`;`, Punctuation, Pop(1)},
  31. {`\.`, Punctuation, Pop(1)},
  32. },
  33. "whitespace": {
  34. {`\s+`, Text, nil},
  35. },
  36. "comment_start": {
  37. {`\(\*`, CommentMultiline, Push("comment")},
  38. },
  39. "comment": {
  40. {`[^*)]`, CommentMultiline, nil},
  41. Include("comment_start"),
  42. {`\*\)`, CommentMultiline, Pop(1)},
  43. {`[*)]`, CommentMultiline, nil},
  44. },
  45. "identifier": {
  46. {`([a-zA-Z][\w \-]*)`, Keyword, nil},
  47. },
  48. },
  49. ))