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