aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/Pygments/py3/pygments/lexers/ecl.py
blob: e7484761c676d67af7de64afc1c69cacbb6aaf3a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
""" 
    pygments.lexers.ecl 
    ~~~~~~~~~~~~~~~~~~~ 
 
    Lexers for the ECL language. 
 
    :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details. 
""" 
 
import re 
 
from pygments.lexer import RegexLexer, include, bygroups, words 
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 
    Number, Punctuation, Whitespace
 
__all__ = ['ECLLexer'] 
 
 
class ECLLexer(RegexLexer): 
    """ 
    Lexer for the declarative big-data `ECL 
    <https://hpccsystems.com/training/documentation/ecl-language-reference/html>`_
    language. 
 
    .. versionadded:: 1.5 
    """ 
 
    name = 'ECL' 
    aliases = ['ecl'] 
    filenames = ['*.ecl'] 
    mimetypes = ['application/x-ecl'] 
 
    flags = re.IGNORECASE | re.MULTILINE 
 
    tokens = { 
        'root': [ 
            include('whitespace'), 
            include('statements'), 
        ], 
        'whitespace': [ 
            (r'\s+', Whitespace),
            (r'\/\/.*', Comment.Single), 
            (r'/(\\\n)?\*(.|\n)*?\*(\\\n)?/', Comment.Multiline), 
        ], 
        'statements': [ 
            include('types'), 
            include('keywords'), 
            include('functions'), 
            include('hash'), 
            (r'"', String, 'string'), 
            (r'\'', String, 'string'), 
            (r'(\d+\.\d*|\.\d+|\d+)e[+-]?\d+[lu]*', Number.Float), 
            (r'(\d+\.\d*|\.\d+|\d+f)f?', Number.Float), 
            (r'0x[0-9a-f]+[lu]*', Number.Hex), 
            (r'0[0-7]+[lu]*', Number.Oct), 
            (r'\d+[lu]*', Number.Integer), 
            (r'[~!%^&*+=|?:<>/-]+', Operator), 
            (r'[{}()\[\],.;]', Punctuation), 
            (r'[a-z_]\w*', Name), 
        ], 
        'hash': [ 
            (r'^#.*$', Comment.Preproc), 
        ], 
        'types': [ 
            (r'(RECORD|END)\D', Keyword.Declaration), 
            (r'((?:ASCII|BIG_ENDIAN|BOOLEAN|DATA|DECIMAL|EBCDIC|INTEGER|PATTERN|' 
             r'QSTRING|REAL|RECORD|RULE|SET OF|STRING|TOKEN|UDECIMAL|UNICODE|' 
             r'UNSIGNED|VARSTRING|VARUNICODE)\d*)(\s+)', 
             bygroups(Keyword.Type, Whitespace)),
        ], 
        'keywords': [ 
            (words(( 
                'APPLY', 'ASSERT', 'BUILD', 'BUILDINDEX', 'EVALUATE', 'FAIL', 
                'KEYDIFF', 'KEYPATCH', 'LOADXML', 'NOTHOR', 'NOTIFY', 'OUTPUT', 
                'PARALLEL', 'SEQUENTIAL', 'SOAPCALL', 'CHECKPOINT', 'DEPRECATED', 
                'FAILCODE', 'FAILMESSAGE', 'FAILURE', 'GLOBAL', 'INDEPENDENT', 
                'ONWARNING', 'PERSIST', 'PRIORITY', 'RECOVERY', 'STORED', 'SUCCESS', 
                'WAIT', 'WHEN'), suffix=r'\b'), 
             Keyword.Reserved), 
            # These are classed differently, check later 
            (words(( 
                'ALL', 'AND', 'ANY', 'AS', 'ATMOST', 'BEFORE', 'BEGINC++', 'BEST', 'BETWEEN', 'CASE', 
                'CONST', 'COUNTER', 'CSV', 'DESCEND', 'ENCRYPT', 'ENDC++', 'ENDMACRO', 'EXCEPT', 
                'EXCLUSIVE', 'EXPIRE', 'EXPORT', 'EXTEND', 'FALSE', 'FEW', 'FIRST', 'FLAT', 'FULL', 
                'FUNCTION', 'GROUP', 'HEADER', 'HEADING', 'HOLE', 'IFBLOCK', 'IMPORT', 'IN', 'JOINED', 
                'KEEP', 'KEYED', 'LAST', 'LEFT', 'LIMIT', 'LOAD', 'LOCAL', 'LOCALE', 'LOOKUP', 'MACRO', 
                'MANY', 'MAXCOUNT', 'MAXLENGTH', 'MIN SKEW', 'MODULE', 'INTERFACE', 'NAMED', 'NOCASE', 
                'NOROOT', 'NOSCAN', 'NOSORT', 'NOT', 'OF', 'ONLY', 'OPT', 'OR', 'OUTER', 'OVERWRITE', 
                'PACKED', 'PARTITION', 'PENALTY', 'PHYSICALLENGTH', 'PIPE', 'QUOTE', 'RELATIONSHIP', 
                'REPEAT', 'RETURN', 'RIGHT', 'SCAN', 'SELF', 'SEPARATOR', 'SERVICE', 'SHARED', 'SKEW', 
                'SKIP', 'SQL', 'STORE', 'TERMINATOR', 'THOR', 'THRESHOLD', 'TOKEN', 'TRANSFORM', 'TRIM', 
                'TRUE', 'TYPE', 'UNICODEORDER', 'UNSORTED', 'VALIDATE', 'VIRTUAL', 'WHOLE', 'WILD', 
                'WITHIN', 'XML', 'XPATH', '__COMPRESSED__'), suffix=r'\b'), 
             Keyword.Reserved), 
        ], 
        'functions': [ 
            (words(( 
                'ABS', 'ACOS', 'ALLNODES', 'ASCII', 'ASIN', 'ASSTRING', 'ATAN', 'ATAN2', 'AVE', 'CASE', 
                'CHOOSE', 'CHOOSEN', 'CHOOSESETS', 'CLUSTERSIZE', 'COMBINE', 'CORRELATION', 'COS', 
                'COSH', 'COUNT', 'COVARIANCE', 'CRON', 'DATASET', 'DEDUP', 'DEFINE', 'DENORMALIZE', 
                'DISTRIBUTE', 'DISTRIBUTED', 'DISTRIBUTION', 'EBCDIC', 'ENTH', 'ERROR', 'EVALUATE', 
                'EVENT', 'EVENTEXTRA', 'EVENTNAME', 'EXISTS', 'EXP', 'FAILCODE', 'FAILMESSAGE', 
                'FETCH', 'FROMUNICODE', 'GETISVALID', 'GLOBAL', 'GRAPH', 'GROUP', 'HASH', 'HASH32', 
                'HASH64', 'HASHCRC', 'HASHMD5', 'HAVING', 'IF', 'INDEX', 'INTFORMAT', 'ISVALID', 
                'ITERATE', 'JOIN', 'KEYUNICODE', 'LENGTH', 'LIBRARY', 'LIMIT', 'LN', 'LOCAL', 'LOG', 'LOOP', 
                'MAP', 'MATCHED', 'MATCHLENGTH', 'MATCHPOSITION', 'MATCHTEXT', 'MATCHUNICODE', 
                'MAX', 'MERGE', 'MERGEJOIN', 'MIN', 'NOLOCAL', 'NONEMPTY', 'NORMALIZE', 'PARSE', 'PIPE', 
                'POWER', 'PRELOAD', 'PROCESS', 'PROJECT', 'PULL', 'RANDOM', 'RANGE', 'RANK', 'RANKED', 
                'REALFORMAT', 'RECORDOF', 'REGEXFIND', 'REGEXREPLACE', 'REGROUP', 'REJECTED', 
                'ROLLUP', 'ROUND', 'ROUNDUP', 'ROW', 'ROWDIFF', 'SAMPLE', 'SET', 'SIN', 'SINH', 'SIZEOF', 
                'SOAPCALL', 'SORT', 'SORTED', 'SQRT', 'STEPPED', 'STORED', 'SUM', 'TABLE', 'TAN', 'TANH', 
                'THISNODE', 'TOPN', 'TOUNICODE', 'TRANSFER', 'TRIM', 'TRUNCATE', 'TYPEOF', 'UNGROUP', 
                'UNICODEORDER', 'VARIANCE', 'WHICH', 'WORKUNIT', 'XMLDECODE', 'XMLENCODE', 
                'XMLTEXT', 'XMLUNICODE'), suffix=r'\b'), 
             Name.Function), 
        ], 
        'string': [ 
            (r'"', String, '#pop'), 
            (r'\'', String, '#pop'), 
            (r'[^"\']+', String), 
        ], 
    } 

    def analyse_text(text):
        """This is very difficult to guess relative to other business languages.
        -> in conjuction with BEGIN/END seems relatively rare though."""
        result = 0

        if '->' in text:
            result += 0.01
        if 'BEGIN' in text:
            result += 0.01
        if 'END' in text:
            result += 0.01

        return result