1 package p
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var Pig = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "Pig",
12 Aliases: []string{"pig"},
13 Filenames: []string{"*.pig"},
14 MimeTypes: []string{"text/x-pig"},
15 CaseInsensitive: true,
16 },
17 pigRules,
18 ))
19
20 func pigRules() Rules {
21 return Rules{
22 "root": {
23 {`\s+`, Text, nil},
24 {`--.*`, Comment, nil},
25 {`/\*[\w\W]*?\*/`, CommentMultiline, nil},
26 {`\\\n`, Text, nil},
27 {`\\`, Text, nil},
28 {`\'(?:\\[ntbrf\\\']|\\u[0-9a-f]{4}|[^\'\\\n\r])*\'`, LiteralString, nil},
29 Include("keywords"),
30 Include("types"),
31 Include("builtins"),
32 Include("punct"),
33 Include("operators"),
34 {`[0-9]*\.[0-9]+(e[0-9]+)?[fd]?`, LiteralNumberFloat, nil},
35 {`0x[0-9a-f]+`, LiteralNumberHex, nil},
36 {`[0-9]+L?`, LiteralNumberInteger, nil},
37 {`\n`, Text, nil},
38 {`([a-z_]\w*)(\s*)(\()`, ByGroups(NameFunction, Text, Punctuation), nil},
39 {`[()#:]`, Text, nil},
40 {`[^(:#\'")\s]+`, Text, nil},
41 {`\S+\s+`, Text, nil},
42 },
43 "keywords": {
44 {`(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},
45 },
46 "builtins": {
47 {`(AVG|BinStorage|cogroup|CONCAT|copyFromLocal|copyToLocal|COUNT|cross|DIFF|MAX|MIN|PigDump|PigStorage|SIZE|SUM|TextLoader|TOKENIZE)\b`, NameBuiltin, nil},
48 },
49 "types": {
50 {`(bytearray|BIGINTEGER|BIGDECIMAL|chararray|datetime|double|float|int|long|tuple)\b`, KeywordType, nil},
51 },
52 "punct": {
53 {`[;(){}\[\]]`, Punctuation, nil},
54 },
55 "operators": {
56 {`[#=,./%+\-?]`, Operator, nil},
57 {`(eq|gt|lt|gte|lte|neq|matches)\b`, Operator, nil},
58 {`(==|<=|<|>=|>|!=)`, Operator, nil},
59 },
60 }
61 }
62
View as plain text