pig.go

 1package p
 2
 3import (
 4	. "github.com/alecthomas/chroma" // nolint
 5	"github.com/alecthomas/chroma/lexers/internal"
 6)
 7
 8// Pig lexer.
 9var Pig = internal.Register(MustNewLexer(
10	&Config{
11		Name:            "Pig",
12		Aliases:         []string{"pig"},
13		Filenames:       []string{"*.pig"},
14		MimeTypes:       []string{"text/x-pig"},
15		CaseInsensitive: true,
16	},
17	Rules{
18		"root": {
19			{`\s+`, Text, nil},
20			{`--.*`, Comment, nil},
21			{`/\*[\w\W]*?\*/`, CommentMultiline, nil},
22			{`\\\n`, Text, nil},
23			{`\\`, Text, nil},
24			{`\'(?:\\[ntbrf\\\']|\\u[0-9a-f]{4}|[^\'\\\n\r])*\'`, LiteralString, nil},
25			Include("keywords"),
26			Include("types"),
27			Include("builtins"),
28			Include("punct"),
29			Include("operators"),
30			{`[0-9]*\.[0-9]+(e[0-9]+)?[fd]?`, LiteralNumberFloat, nil},
31			{`0x[0-9a-f]+`, LiteralNumberHex, nil},
32			{`[0-9]+L?`, LiteralNumberInteger, nil},
33			{`\n`, Text, nil},
34			{`([a-z_]\w*)(\s*)(\()`, ByGroups(NameFunction, Text, Punctuation), nil},
35			{`[()#:]`, Text, nil},
36			{`[^(:#\'")\s]+`, Text, nil},
37			{`\S+\s+`, Text, nil},
38		},
39		"keywords": {
40			{`(assert|and|any|all|arrange|as|asc|bag|by|cache|CASE|cat|cd|cp|%declare|%default|define|dense|desc|describe|distinct|du|dump|eval|exex|explain|filter|flatten|foreach|full|generate|group|help|if|illustrate|import|inner|input|into|is|join|kill|left|limit|load|ls|map|matches|mkdir|mv|not|null|onschema|or|order|outer|output|parallel|pig|pwd|quit|register|returns|right|rm|rmf|rollup|run|sample|set|ship|split|stderr|stdin|stdout|store|stream|through|union|using|void)\b`, Keyword, nil},
41		},
42		"builtins": {
43			{`(AVG|BinStorage|cogroup|CONCAT|copyFromLocal|copyToLocal|COUNT|cross|DIFF|MAX|MIN|PigDump|PigStorage|SIZE|SUM|TextLoader|TOKENIZE)\b`, NameBuiltin, nil},
44		},
45		"types": {
46			{`(bytearray|BIGINTEGER|BIGDECIMAL|chararray|datetime|double|float|int|long|tuple)\b`, KeywordType, nil},
47		},
48		"punct": {
49			{`[;(){}\[\]]`, Punctuation, nil},
50		},
51		"operators": {
52			{`[#=,./%+\-?]`, Operator, nil},
53			{`(eq|gt|lt|gte|lte|neq|matches)\b`, Operator, nil},
54			{`(==|<=|<|>=|>|!=)`, Operator, nil},
55		},
56	},
57))