awk.go

 1package a
 2
 3import (
 4	. "github.com/alecthomas/chroma" // nolint
 5	"github.com/alecthomas/chroma/lexers/internal"
 6)
 7
 8// Awk lexer.
 9var Awk = internal.Register(MustNewLexer(
10	&Config{
11		Name:      "Awk",
12		Aliases:   []string{"awk", "gawk", "mawk", "nawk"},
13		Filenames: []string{"*.awk"},
14		MimeTypes: []string{"application/x-awk"},
15	},
16	Rules{
17		"commentsandwhitespace": {
18			{`\s+`, Text, nil},
19			{`#.*$`, CommentSingle, nil},
20		},
21		"slashstartsregex": {
22			Include("commentsandwhitespace"),
23			{`/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/\B`, LiteralStringRegex, Pop(1)},
24			{`(?=/)`, Text, Push("#pop", "badregex")},
25			Default(Pop(1)),
26		},
27		"badregex": {
28			{`\n`, Text, Pop(1)},
29		},
30		"root": {
31			{`^(?=\s|/)`, Text, Push("slashstartsregex")},
32			Include("commentsandwhitespace"),
33			{`\+\+|--|\|\||&&|in\b|\$|!?~|(\*\*|[-<>+*%\^/!=|])=?`, Operator, Push("slashstartsregex")},
34			{`[{(\[;,]`, Punctuation, Push("slashstartsregex")},
35			{`[})\].]`, Punctuation, nil},
36			{`(break|continue|do|while|exit|for|if|else|return)\b`, Keyword, Push("slashstartsregex")},
37			{`function\b`, KeywordDeclaration, Push("slashstartsregex")},
38			{`(atan2|cos|exp|int|log|rand|sin|sqrt|srand|gensub|gsub|index|length|match|split|sprintf|sub|substr|tolower|toupper|close|fflush|getline|next|nextfile|print|printf|strftime|systime|delete|system)\b`, KeywordReserved, nil},
39			{`(ARGC|ARGIND|ARGV|BEGIN|CONVFMT|ENVIRON|END|ERRNO|FIELDWIDTHS|FILENAME|FNR|FS|IGNORECASE|NF|NR|OFMT|OFS|ORFS|RLENGTH|RS|RSTART|RT|SUBSEP)\b`, NameBuiltin, nil},
40			{`[$a-zA-Z_]\w*`, NameOther, nil},
41			{`[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?`, LiteralNumberFloat, nil},
42			{`0x[0-9a-fA-F]+`, LiteralNumberHex, nil},
43			{`[0-9]+`, LiteralNumberInteger, nil},
44			{`"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil},
45			{`'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil},
46		},
47	},
48))