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.

elm.go 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package e
  2. import (
  3. . "github.com/alecthomas/chroma" // nolint
  4. "github.com/alecthomas/chroma/lexers/internal"
  5. )
  6. // Elm lexer.
  7. var Elm = internal.Register(MustNewLexer(
  8. &Config{
  9. Name: "Elm",
  10. Aliases: []string{"elm"},
  11. Filenames: []string{"*.elm"},
  12. MimeTypes: []string{"text/x-elm"},
  13. },
  14. Rules{
  15. "root": {
  16. {`\{-`, CommentMultiline, Push("comment")},
  17. {`--.*`, CommentSingle, nil},
  18. {`\s+`, Text, nil},
  19. {`"`, LiteralString, Push("doublequote")},
  20. {`^\s*module\s*`, KeywordNamespace, Push("imports")},
  21. {`^\s*import\s*`, KeywordNamespace, Push("imports")},
  22. {`\[glsl\|.*`, NameEntity, Push("shader")},
  23. {Words(``, `\b`, `alias`, `as`, `case`, `else`, `if`, `import`, `in`, `let`, `module`, `of`, `port`, `then`, `type`, `where`), KeywordReserved, nil},
  24. {`[A-Z]\w*`, KeywordType, nil},
  25. {`^main `, KeywordReserved, nil},
  26. {Words(`\(`, `\)`, `~`, `||`, `|>`, `|`, "`", `^`, `\`, `'`, `>>`, `>=`, `>`, `==`, `=`, `<~`, `<|`, `<=`, `<<`, `<-`, `<`, `::`, `:`, `/=`, `//`, `/`, `..`, `.`, `->`, `-`, `++`, `+`, `*`, `&&`, `%`), NameFunction, nil},
  27. {Words(``, ``, `~`, `||`, `|>`, `|`, "`", `^`, `\`, `'`, `>>`, `>=`, `>`, `==`, `=`, `<~`, `<|`, `<=`, `<<`, `<-`, `<`, `::`, `:`, `/=`, `//`, `/`, `..`, `.`, `->`, `-`, `++`, `+`, `*`, `&&`, `%`), NameFunction, nil},
  28. Include("numbers"),
  29. {`[a-z_][a-zA-Z_\']*`, NameVariable, nil},
  30. {`[,()\[\]{}]`, Punctuation, nil},
  31. },
  32. "comment": {
  33. {`-(?!\})`, CommentMultiline, nil},
  34. {`\{-`, CommentMultiline, Push("comment")},
  35. {`[^-}]`, CommentMultiline, nil},
  36. {`-\}`, CommentMultiline, Pop(1)},
  37. },
  38. "doublequote": {
  39. {`\\u[0-9a-fA-F]{4}`, LiteralStringEscape, nil},
  40. {`\\[nrfvb\\"]`, LiteralStringEscape, nil},
  41. {`[^"]`, LiteralString, nil},
  42. {`"`, LiteralString, Pop(1)},
  43. },
  44. "imports": {
  45. {`\w+(\.\w+)*`, NameClass, Pop(1)},
  46. },
  47. "numbers": {
  48. {`_?\d+\.(?=\d+)`, LiteralNumberFloat, nil},
  49. {`_?\d+`, LiteralNumberInteger, nil},
  50. },
  51. "shader": {
  52. {`\|(?!\])`, NameEntity, nil},
  53. {`\|\]`, NameEntity, Pop(1)},
  54. {`.*\n`, NameEntity, nil},
  55. },
  56. },
  57. ))