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.

fish.go 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package f
  2. import (
  3. . "github.com/alecthomas/chroma" // nolint
  4. "github.com/alecthomas/chroma/lexers/internal"
  5. )
  6. // Fish lexer.
  7. var Fish = internal.Register(MustNewLexer(
  8. &Config{
  9. Name: "Fish",
  10. Aliases: []string{"fish", "fishshell"},
  11. Filenames: []string{"*.fish", "*.load"},
  12. MimeTypes: []string{"application/x-fish"},
  13. },
  14. Rules{
  15. "root": {
  16. Include("basic"),
  17. Include("data"),
  18. Include("interp"),
  19. },
  20. "interp": {
  21. {`\$\(\(`, Keyword, Push("math")},
  22. {`\(`, Keyword, Push("paren")},
  23. {`\$#?(\w+|.)`, NameVariable, nil},
  24. },
  25. "basic": {
  26. {`\b(begin|end|if|else|while|break|for|in|return|function|block|case|continue|switch|not|and|or|set|echo|exit|pwd|true|false|cd|count|test)(\s*)\b`, ByGroups(Keyword, Text), nil},
  27. {`\b(alias|bg|bind|breakpoint|builtin|command|commandline|complete|contains|dirh|dirs|emit|eval|exec|fg|fish|fish_config|fish_indent|fish_pager|fish_prompt|fish_right_prompt|fish_update_completions|fishd|funced|funcsave|functions|help|history|isatty|jobs|math|mimedb|nextd|open|popd|prevd|psub|pushd|random|read|set_color|source|status|trap|type|ulimit|umask|vared|fc|getopts|hash|kill|printf|time|wait)\s*\b(?!\.)`, NameBuiltin, nil},
  28. {`#.*\n`, Comment, nil},
  29. {`\\[\w\W]`, LiteralStringEscape, nil},
  30. {`(\b\w+)(\s*)(=)`, ByGroups(NameVariable, Text, Operator), nil},
  31. {`[\[\]()=]`, Operator, nil},
  32. {`<<-?\s*(\'?)\\?(\w+)[\w\W]+?\2`, LiteralString, nil},
  33. },
  34. "data": {
  35. {`(?s)\$?"(\\\\|\\[0-7]+|\\.|[^"\\$])*"`, LiteralStringDouble, nil},
  36. {`"`, LiteralStringDouble, Push("string")},
  37. {`(?s)\$'(\\\\|\\[0-7]+|\\.|[^'\\])*'`, LiteralStringSingle, nil},
  38. {`(?s)'.*?'`, LiteralStringSingle, nil},
  39. {`;`, Punctuation, nil},
  40. {`&|\||\^|<|>`, Operator, nil},
  41. {`\s+`, Text, nil},
  42. {`\d+(?= |\Z)`, LiteralNumber, nil},
  43. {"[^=\\s\\[\\]{}()$\"\\'`\\\\<&|;]+", Text, nil},
  44. },
  45. "string": {
  46. {`"`, LiteralStringDouble, Pop(1)},
  47. {`(?s)(\\\\|\\[0-7]+|\\.|[^"\\$])+`, LiteralStringDouble, nil},
  48. Include("interp"),
  49. },
  50. "paren": {
  51. {`\)`, Keyword, Pop(1)},
  52. Include("root"),
  53. },
  54. "math": {
  55. {`\)\)`, Keyword, Pop(1)},
  56. {`[-+*/%^|&]|\*\*|\|\|`, Operator, nil},
  57. {`\d+#\d+`, LiteralNumber, nil},
  58. {`\d+#(?! )`, LiteralNumber, nil},
  59. {`\d+`, LiteralNumber, nil},
  60. Include("root"),
  61. },
  62. },
  63. ))