ecl.py 6.1 KB

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