1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-11-04 08:17:24 -05:00
gitea/vendor/github.com/alecthomas/chroma/lexers/f/fish.go
6543 fae07cbc8f
Update Vendor (#16325)
* Add Dependencie Update Script

* update gitea.com/lunny/levelqueue

* update github.com/PuerkitoBio/goquery

* update github.com/alecthomas/chroma

* update github.com/blevesearch/bleve/v2

* update github.com/caddyserver/certmagic

* update github.com/go-enry/go-enry/v2

* update github.com/go-redis/redis/v8

* update github.com/hashicorp/golang-lru

* update github.com/klauspost/compress

* update github.com/markbates/goth

* update github.com/mholt/archiver/v3

* update github.com/microcosm-cc/bluemonday

* update github.com/minio/minio-go/v7

* update github.com/olivere/elastic/v7

* update github.com/xanzy/go-gitlab

* update github.com/yuin/goldmark
2021-07-04 04:06:10 +02:00

99 lines
3.5 KiB
Go
Vendored

package f
import (
. "github.com/alecthomas/chroma" // nolint
"github.com/alecthomas/chroma/lexers/internal"
)
// Fish lexer.
var Fish = internal.Register(MustNewLazyLexer(
&Config{
Name: "Fish",
Aliases: []string{"fish", "fishshell"},
Filenames: []string{"*.fish", "*.load"},
MimeTypes: []string{"application/x-fish"},
},
fishRules,
))
func fishRules() Rules {
keywords := []string{
`begin`, `end`, `if`, `else`, `while`, `break`, `for`, `return`, `function`, `block`,
`case`, `continue`, `switch`, `not`, `and`, `or`, `set`, `echo`, `exit`, `pwd`, `true`,
`false`, `cd`, `cdh`, `count`, `test`,
}
keywordsPattern := Words(`\b`, `\b`, keywords...)
builtins := []string{
`alias`, `bg`, `bind`, `breakpoint`, `builtin`, `argparse`, `abbr`, `string`, `command`,
`commandline`, `complete`, `contains`, `dirh`, `dirs`, `disown`, `emit`, `eval`, `exec`,
`fg`, `fish`, `fish_add_path`, `fish_breakpoint_prompt`, `fish_command_not_found`,
`fish_config`, `fish_git_prompt`, `fish_greeting`, `fish_hg_prompt`, `fish_indent`,
`fish_is_root_user`, `fish_key_reader`, `fish_mode_prompt`, `fish_opt`, `fish_pager`,
`fish_prompt`, `fish_right_prompt`, `fish_status_to_signal`, `fish_svn_prompt`,
`fish_title`, `fish_update_completions`, `fish_vcs_prompt`, `fishd`, `funced`,
`funcsave`, `functions`, `help`, `history`, `isatty`, `jobs`, `math`, `mimedb`, `nextd`,
`open`, `prompt_pwd`, `realpath`, `popd`, `prevd`, `psub`, `pushd`, `random`, `read`,
`set_color`, `source`, `status`, `suspend`, `trap`, `type`, `ulimit`, `umask`, `vared`,
`fc`, `getopts`, `hash`, `kill`, `printf`, `time`, `wait`,
}
return Rules{
"root": {
Include("basic"),
Include("interp"),
Include("data"),
},
"interp": {
{`\$\(\(`, Keyword, Push("math")},
{`\(`, Keyword, Push("paren")},
{`\$#?(\w+|.)`, NameVariable, nil},
},
"basic": {
{Words(`(?<=(?:^|\A|;|&&|\|\||\||`+keywordsPattern+`)\s*)`, `(?=;?\b)`, keywords...), Keyword, nil},
{`(?<=for\s+\S+\s+)in\b`, Keyword, nil},
{Words(`\b`, `\s*\b(?!\.)`, builtins...), NameBuiltin, nil},
{`#!.*\n`, CommentHashbang, nil},
{`#.*\n`, Comment, nil},
{`\\[\w\W]`, LiteralStringEscape, nil},
{`(\b\w+)(\s*)(=)`, ByGroups(NameVariable, Text, Operator), nil},
{`[\[\]()={}]`, Operator, nil},
{`(?<=\[[^\]]+)\.\.|-(?=[^\[]+\])`, Operator, nil},
{`<<-?\s*(\'?)\\?(\w+)[\w\W]+?\2`, LiteralString, nil},
{`(?<=set\s+(?:--?[^\d\W][\w-]*\s+)?)\w+`, NameVariable, nil},
{`(?<=for\s+)\w[\w-]*(?=\s+in)`, NameVariable, nil},
{`(?<=function\s+)\w(?:[^\n])*?(?= *[-\n])`, NameFunction, nil},
{`(?<=(?:^|\b(?:and|or|sudo)\b|;|\|\||&&|\||\(|(?:\b\w+\s*=\S+\s)) *)\w[\w-]*`, NameFunction, nil},
},
"data": {
{`(?s)\$?"(\\\\|\\[0-7]+|\\.|[^"\\$])*"`, LiteralStringDouble, nil},
{`"`, LiteralStringDouble, Push("string")},
{`(?s)\$'(\\\\|\\[0-7]+|\\.|[^'\\])*'`, LiteralStringSingle, nil},
{`(?s)'.*?'`, LiteralStringSingle, nil},
{`;`, Punctuation, nil},
{`&&|\|\||&|\||\^|<|>`, Operator, nil},
{`\s+`, Text, nil},
{`\b\d+\b`, LiteralNumber, nil},
{`--?[^\d][\w-]*`, NameAttribute, nil},
{".+?", Text, nil},
},
"string": {
{`"`, LiteralStringDouble, Pop(1)},
{`(?s)(\\\\|\\[0-7]+|\\.|[^"\\$])+`, LiteralStringDouble, nil},
Include("interp"),
},
"paren": {
{`\)`, Keyword, Pop(1)},
Include("root"),
},
"math": {
{`\)\)`, Keyword, Pop(1)},
{`[-+*/%^|&]|\*\*|\|\|`, Operator, nil},
{`\d+#\d+`, LiteralNumber, nil},
{`\d+#(?! )`, LiteralNumber, nil},
{`\d+`, LiteralNumber, nil},
Include("root"),
},
}
}