1package f
2
3import (
4 . "github.com/alecthomas/chroma" // nolint
5 "github.com/alecthomas/chroma/lexers/internal"
6)
7
8// Fish lexer.
9var Fish = internal.Register(MustNewLexer(
10 &Config{
11 Name: "Fish",
12 Aliases: []string{"fish", "fishshell"},
13 Filenames: []string{"*.fish", "*.load"},
14 MimeTypes: []string{"application/x-fish"},
15 },
16 Rules{
17 "root": {
18 Include("basic"),
19 Include("data"),
20 Include("interp"),
21 },
22 "interp": {
23 {`\$\(\(`, Keyword, Push("math")},
24 {`\(`, Keyword, Push("paren")},
25 {`\$#?(\w+|.)`, NameVariable, nil},
26 },
27 "basic": {
28 {`\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},
29 {`\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},
30 {`#.*\n`, Comment, nil},
31 {`\\[\w\W]`, LiteralStringEscape, nil},
32 {`(\b\w+)(\s*)(=)`, ByGroups(NameVariable, Text, Operator), nil},
33 {`[\[\]()=]`, Operator, nil},
34 {`<<-?\s*(\'?)\\?(\w+)[\w\W]+?\2`, LiteralString, nil},
35 },
36 "data": {
37 {`(?s)\$?"(\\\\|\\[0-7]+|\\.|[^"\\$])*"`, LiteralStringDouble, nil},
38 {`"`, LiteralStringDouble, Push("string")},
39 {`(?s)\$'(\\\\|\\[0-7]+|\\.|[^'\\])*'`, LiteralStringSingle, nil},
40 {`(?s)'.*?'`, LiteralStringSingle, nil},
41 {`;`, Punctuation, nil},
42 {`&|\||\^|<|>`, Operator, nil},
43 {`\s+`, Text, nil},
44 {`\d+(?= |\Z)`, LiteralNumber, nil},
45 {"[^=\\s\\[\\]{}()$\"\\'`\\\\<&|;]+", Text, nil},
46 },
47 "string": {
48 {`"`, LiteralStringDouble, Pop(1)},
49 {`(?s)(\\\\|\\[0-7]+|\\.|[^"\\$])+`, LiteralStringDouble, nil},
50 Include("interp"),
51 },
52 "paren": {
53 {`\)`, Keyword, Pop(1)},
54 Include("root"),
55 },
56 "math": {
57 {`\)\)`, Keyword, Pop(1)},
58 {`[-+*/%^|&]|\*\*|\|\|`, Operator, nil},
59 {`\d+#\d+`, LiteralNumber, nil},
60 {`\d+#(?! )`, LiteralNumber, nil},
61 {`\d+`, LiteralNumber, nil},
62 Include("root"),
63 },
64 },
65))