ecl.py 5.7 KB

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