business.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. # -*- coding: utf-8 -*-
  2. """
  3. pygments.lexers.business
  4. ~~~~~~~~~~~~~~~~~~~~~~~~
  5. Lexers for "business-oriented" languages.
  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, words, bygroups
  11. from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
  12. Number, Punctuation, Error
  13. from pygments.lexers._openedge_builtins import OPENEDGEKEYWORDS
  14. __all__ = ['CobolLexer', 'CobolFreeformatLexer', 'ABAPLexer', 'OpenEdgeLexer',
  15. 'GoodDataCLLexer', 'MaqlLexer']
  16. class CobolLexer(RegexLexer):
  17. """
  18. Lexer for OpenCOBOL code.
  19. .. versionadded:: 1.6
  20. """
  21. name = 'COBOL'
  22. aliases = ['cobol']
  23. filenames = ['*.cob', '*.COB', '*.cpy', '*.CPY']
  24. mimetypes = ['text/x-cobol']
  25. flags = re.IGNORECASE | re.MULTILINE
  26. # Data Types: by PICTURE and USAGE
  27. # Operators: **, *, +, -, /, <, >, <=, >=, =, <>
  28. # Logical (?): NOT, AND, OR
  29. # Reserved words:
  30. # http://opencobol.add1tocobol.com/#reserved-words
  31. # Intrinsics:
  32. # http://opencobol.add1tocobol.com/#does-opencobol-implement-any-intrinsic-functions
  33. tokens = {
  34. 'root': [
  35. include('comment'),
  36. include('strings'),
  37. include('core'),
  38. include('nums'),
  39. (r'[a-z0-9]([\w\-]*[a-z0-9]+)?', Name.Variable),
  40. # (r'[\s]+', Text),
  41. (r'[ \t]+', Text),
  42. ],
  43. 'comment': [
  44. (r'(^.{6}[*/].*\n|^.{6}|\*>.*\n)', Comment),
  45. ],
  46. 'core': [
  47. # Figurative constants
  48. (r'(^|(?<=[^\w\-]))(ALL\s+)?'
  49. r'((ZEROES)|(HIGH-VALUE|LOW-VALUE|QUOTE|SPACE|ZERO)(S)?)'
  50. r'\s*($|(?=[^\w\-]))',
  51. Name.Constant),
  52. # Reserved words STATEMENTS and other bolds
  53. (words((
  54. 'ACCEPT', 'ADD', 'ALLOCATE', 'CALL', 'CANCEL', 'CLOSE', 'COMPUTE',
  55. 'CONFIGURATION', 'CONTINUE', 'DATA', 'DELETE', 'DISPLAY', 'DIVIDE',
  56. 'DIVISION', 'ELSE', 'END', 'END-ACCEPT',
  57. 'END-ADD', 'END-CALL', 'END-COMPUTE', 'END-DELETE', 'END-DISPLAY',
  58. 'END-DIVIDE', 'END-EVALUATE', 'END-IF', 'END-MULTIPLY', 'END-OF-PAGE',
  59. 'END-PERFORM', 'END-READ', 'END-RETURN', 'END-REWRITE', 'END-SEARCH',
  60. 'END-START', 'END-STRING', 'END-SUBTRACT', 'END-UNSTRING', 'END-WRITE',
  61. 'ENVIRONMENT', 'EVALUATE', 'EXIT', 'FD', 'FILE', 'FILE-CONTROL', 'FOREVER',
  62. 'FREE', 'GENERATE', 'GO', 'GOBACK', 'IDENTIFICATION', 'IF', 'INITIALIZE',
  63. 'INITIATE', 'INPUT-OUTPUT', 'INSPECT', 'INVOKE', 'I-O-CONTROL', 'LINKAGE',
  64. 'LOCAL-STORAGE', 'MERGE', 'MOVE', 'MULTIPLY', 'OPEN', 'PERFORM',
  65. 'PROCEDURE', 'PROGRAM-ID', 'RAISE', 'READ', 'RELEASE', 'RESUME',
  66. 'RETURN', 'REWRITE', 'SCREEN', 'SD', 'SEARCH', 'SECTION', 'SET',
  67. 'SORT', 'START', 'STOP', 'STRING', 'SUBTRACT', 'SUPPRESS',
  68. 'TERMINATE', 'THEN', 'UNLOCK', 'UNSTRING', 'USE', 'VALIDATE',
  69. 'WORKING-STORAGE', 'WRITE'), prefix=r'(^|(?<=[^\w\-]))',
  70. suffix=r'\s*($|(?=[^\w\-]))'),
  71. Keyword.Reserved),
  72. # Reserved words
  73. (words((
  74. 'ACCESS', 'ADDRESS', 'ADVANCING', 'AFTER', 'ALL',
  75. 'ALPHABET', 'ALPHABETIC', 'ALPHABETIC-LOWER', 'ALPHABETIC-UPPER',
  76. 'ALPHANUMERIC', 'ALPHANUMERIC-EDITED', 'ALSO', 'ALTER', 'ALTERNATE'
  77. 'ANY', 'ARE', 'AREA', 'AREAS', 'ARGUMENT-NUMBER', 'ARGUMENT-VALUE', 'AS',
  78. 'ASCENDING', 'ASSIGN', 'AT', 'AUTO', 'AUTO-SKIP', 'AUTOMATIC',
  79. 'AUTOTERMINATE', 'BACKGROUND-COLOR', 'BASED', 'BEEP', 'BEFORE', 'BELL',
  80. 'BLANK', 'BLINK', 'BLOCK', 'BOTTOM', 'BY', 'BYTE-LENGTH', 'CHAINING',
  81. 'CHARACTER', 'CHARACTERS', 'CLASS', 'CODE', 'CODE-SET', 'COL',
  82. 'COLLATING', 'COLS', 'COLUMN', 'COLUMNS', 'COMMA', 'COMMAND-LINE',
  83. 'COMMIT', 'COMMON', 'CONSTANT', 'CONTAINS', 'CONTENT', 'CONTROL',
  84. 'CONTROLS', 'CONVERTING', 'COPY', 'CORR', 'CORRESPONDING', 'COUNT', 'CRT',
  85. 'CURRENCY', 'CURSOR', 'CYCLE', 'DATE', 'DAY', 'DAY-OF-WEEK', 'DE',
  86. 'DEBUGGING', 'DECIMAL-POINT', 'DECLARATIVES', 'DEFAULT', 'DELIMITED',
  87. 'DELIMITER', 'DEPENDING', 'DESCENDING', 'DETAIL', 'DISK',
  88. 'DOWN', 'DUPLICATES', 'DYNAMIC', 'EBCDIC',
  89. 'ENTRY', 'ENVIRONMENT-NAME', 'ENVIRONMENT-VALUE', 'EOL', 'EOP',
  90. 'EOS', 'ERASE', 'ERROR', 'ESCAPE', 'EXCEPTION',
  91. 'EXCLUSIVE', 'EXTEND', 'EXTERNAL', 'FILE-ID', 'FILLER', 'FINAL',
  92. 'FIRST', 'FIXED', 'FLOAT-LONG', 'FLOAT-SHORT',
  93. 'FOOTING', 'FOR', 'FOREGROUND-COLOR', 'FORMAT', 'FROM', 'FULL',
  94. 'FUNCTION', 'FUNCTION-ID', 'GIVING', 'GLOBAL', 'GROUP',
  95. 'HEADING', 'HIGHLIGHT', 'I-O', 'ID',
  96. 'IGNORE', 'IGNORING', 'IN', 'INDEX', 'INDEXED', 'INDICATE',
  97. 'INITIAL', 'INITIALIZED', 'INPUT', 'INTO', 'INTRINSIC', 'INVALID',
  98. 'IS', 'JUST', 'JUSTIFIED', 'KEY', 'LABEL',
  99. 'LAST', 'LEADING', 'LEFT', 'LENGTH', 'LIMIT', 'LIMITS', 'LINAGE',
  100. 'LINAGE-COUNTER', 'LINE', 'LINES', 'LOCALE', 'LOCK',
  101. 'LOWLIGHT', 'MANUAL', 'MEMORY', 'MINUS', 'MODE', 'MULTIPLE',
  102. 'NATIONAL', 'NATIONAL-EDITED', 'NATIVE', 'NEGATIVE', 'NEXT', 'NO',
  103. 'NULL', 'NULLS', 'NUMBER', 'NUMBERS', 'NUMERIC', 'NUMERIC-EDITED',
  104. 'OBJECT-COMPUTER', 'OCCURS', 'OF', 'OFF', 'OMITTED', 'ON', 'ONLY',
  105. 'OPTIONAL', 'ORDER', 'ORGANIZATION', 'OTHER', 'OUTPUT', 'OVERFLOW',
  106. 'OVERLINE', 'PACKED-DECIMAL', 'PADDING', 'PAGE', 'PARAGRAPH',
  107. 'PLUS', 'POINTER', 'POSITION', 'POSITIVE', 'PRESENT', 'PREVIOUS',
  108. 'PRINTER', 'PRINTING', 'PROCEDURE-POINTER', 'PROCEDURES',
  109. 'PROCEED', 'PROGRAM', 'PROGRAM-POINTER', 'PROMPT', 'QUOTE',
  110. 'QUOTES', 'RANDOM', 'RD', 'RECORD', 'RECORDING', 'RECORDS', 'RECURSIVE',
  111. 'REDEFINES', 'REEL', 'REFERENCE', 'RELATIVE', 'REMAINDER', 'REMOVAL',
  112. 'RENAMES', 'REPLACING', 'REPORT', 'REPORTING', 'REPORTS', 'REPOSITORY',
  113. 'REQUIRED', 'RESERVE', 'RETURNING', 'REVERSE-VIDEO', 'REWIND',
  114. 'RIGHT', 'ROLLBACK', 'ROUNDED', 'RUN', 'SAME', 'SCROLL',
  115. 'SECURE', 'SEGMENT-LIMIT', 'SELECT', 'SENTENCE', 'SEPARATE',
  116. 'SEQUENCE', 'SEQUENTIAL', 'SHARING', 'SIGN', 'SIGNED', 'SIGNED-INT',
  117. 'SIGNED-LONG', 'SIGNED-SHORT', 'SIZE', 'SORT-MERGE', 'SOURCE',
  118. 'SOURCE-COMPUTER', 'SPECIAL-NAMES', 'STANDARD',
  119. 'STANDARD-1', 'STANDARD-2', 'STATUS', 'SUM',
  120. 'SYMBOLIC', 'SYNC', 'SYNCHRONIZED', 'TALLYING', 'TAPE',
  121. 'TEST', 'THROUGH', 'THRU', 'TIME', 'TIMES', 'TO', 'TOP', 'TRAILING',
  122. 'TRANSFORM', 'TYPE', 'UNDERLINE', 'UNIT', 'UNSIGNED',
  123. 'UNSIGNED-INT', 'UNSIGNED-LONG', 'UNSIGNED-SHORT', 'UNTIL', 'UP',
  124. 'UPDATE', 'UPON', 'USAGE', 'USING', 'VALUE', 'VALUES', 'VARYING',
  125. 'WAIT', 'WHEN', 'WITH', 'WORDS', 'YYYYDDD', 'YYYYMMDD'),
  126. prefix=r'(^|(?<=[^\w\-]))', suffix=r'\s*($|(?=[^\w\-]))'),
  127. Keyword.Pseudo),
  128. # inactive reserved words
  129. (words((
  130. 'ACTIVE-CLASS', 'ALIGNED', 'ANYCASE', 'ARITHMETIC', 'ATTRIBUTE',
  131. 'B-AND', 'B-NOT', 'B-OR', 'B-XOR', 'BIT', 'BOOLEAN', 'CD', 'CENTER',
  132. 'CF', 'CH', 'CHAIN', 'CLASS-ID', 'CLASSIFICATION', 'COMMUNICATION',
  133. 'CONDITION', 'DATA-POINTER', 'DESTINATION', 'DISABLE', 'EC', 'EGI',
  134. 'EMI', 'ENABLE', 'END-RECEIVE', 'ENTRY-CONVENTION', 'EO', 'ESI',
  135. 'EXCEPTION-OBJECT', 'EXPANDS', 'FACTORY', 'FLOAT-BINARY-16',
  136. 'FLOAT-BINARY-34', 'FLOAT-BINARY-7', 'FLOAT-DECIMAL-16',
  137. 'FLOAT-DECIMAL-34', 'FLOAT-EXTENDED', 'FORMAT', 'FUNCTION-POINTER',
  138. 'GET', 'GROUP-USAGE', 'IMPLEMENTS', 'INFINITY', 'INHERITS',
  139. 'INTERFACE', 'INTERFACE-ID', 'INVOKE', 'LC_ALL', 'LC_COLLATE',
  140. 'LC_CTYPE', 'LC_MESSAGES', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME',
  141. 'LINE-COUNTER', 'MESSAGE', 'METHOD', 'METHOD-ID', 'NESTED', 'NONE',
  142. 'NORMAL', 'OBJECT', 'OBJECT-REFERENCE', 'OPTIONS', 'OVERRIDE',
  143. 'PAGE-COUNTER', 'PF', 'PH', 'PROPERTY', 'PROTOTYPE', 'PURGE',
  144. 'QUEUE', 'RAISE', 'RAISING', 'RECEIVE', 'RELATION', 'REPLACE',
  145. 'REPRESENTS-NOT-A-NUMBER', 'RESET', 'RESUME', 'RETRY', 'RF', 'RH',
  146. 'SECONDS', 'SEGMENT', 'SELF', 'SEND', 'SOURCES', 'STATEMENT',
  147. 'STEP', 'STRONG', 'SUB-QUEUE-1', 'SUB-QUEUE-2', 'SUB-QUEUE-3',
  148. 'SUPER', 'SYMBOL', 'SYSTEM-DEFAULT', 'TABLE', 'TERMINAL', 'TEXT',
  149. 'TYPEDEF', 'UCS-4', 'UNIVERSAL', 'USER-DEFAULT', 'UTF-16', 'UTF-8',
  150. 'VAL-STATUS', 'VALID', 'VALIDATE', 'VALIDATE-STATUS'),
  151. prefix=r'(^|(?<=[^\w\-]))', suffix=r'\s*($|(?=[^\w\-]))'),
  152. Error),
  153. # Data Types
  154. (r'(^|(?<=[^\w\-]))'
  155. r'(PIC\s+.+?(?=(\s|\.\s))|PICTURE\s+.+?(?=(\s|\.\s))|'
  156. r'(COMPUTATIONAL)(-[1-5X])?|(COMP)(-[1-5X])?|'
  157. r'BINARY-C-LONG|'
  158. r'BINARY-CHAR|BINARY-DOUBLE|BINARY-LONG|BINARY-SHORT|'
  159. r'BINARY)\s*($|(?=[^\w\-]))', Keyword.Type),
  160. # Operators
  161. (r'(\*\*|\*|\+|-|/|<=|>=|<|>|==|/=|=)', Operator),
  162. # (r'(::)', Keyword.Declaration),
  163. (r'([(),;:&%.])', Punctuation),
  164. # Intrinsics
  165. (r'(^|(?<=[^\w\-]))(ABS|ACOS|ANNUITY|ASIN|ATAN|BYTE-LENGTH|'
  166. r'CHAR|COMBINED-DATETIME|CONCATENATE|COS|CURRENT-DATE|'
  167. r'DATE-OF-INTEGER|DATE-TO-YYYYMMDD|DAY-OF-INTEGER|DAY-TO-YYYYDDD|'
  168. r'EXCEPTION-(?:FILE|LOCATION|STATEMENT|STATUS)|EXP10|EXP|E|'
  169. r'FACTORIAL|FRACTION-PART|INTEGER-OF-(?:DATE|DAY|PART)|INTEGER|'
  170. r'LENGTH|LOCALE-(?:DATE|TIME(?:-FROM-SECONDS)?)|LOG(?:10)?|'
  171. r'LOWER-CASE|MAX|MEAN|MEDIAN|MIDRANGE|MIN|MOD|NUMVAL(?:-C)?|'
  172. r'ORD(?:-MAX|-MIN)?|PI|PRESENT-VALUE|RANDOM|RANGE|REM|REVERSE|'
  173. r'SECONDS-FROM-FORMATTED-TIME|SECONDS-PAST-MIDNIGHT|SIGN|SIN|SQRT|'
  174. r'STANDARD-DEVIATION|STORED-CHAR-LENGTH|SUBSTITUTE(?:-CASE)?|'
  175. r'SUM|TAN|TEST-DATE-YYYYMMDD|TEST-DAY-YYYYDDD|TRIM|'
  176. r'UPPER-CASE|VARIANCE|WHEN-COMPILED|YEAR-TO-YYYY)\s*'
  177. r'($|(?=[^\w\-]))', Name.Function),
  178. # Booleans
  179. (r'(^|(?<=[^\w\-]))(true|false)\s*($|(?=[^\w\-]))', Name.Builtin),
  180. # Comparing Operators
  181. (r'(^|(?<=[^\w\-]))(equal|equals|ne|lt|le|gt|ge|'
  182. r'greater|less|than|not|and|or)\s*($|(?=[^\w\-]))', Operator.Word),
  183. ],
  184. # \"[^\"\n]*\"|\'[^\'\n]*\'
  185. 'strings': [
  186. # apparently strings can be delimited by EOL if they are continued
  187. # in the next line
  188. (r'"[^"\n]*("|\n)', String.Double),
  189. (r"'[^'\n]*('|\n)", String.Single),
  190. ],
  191. 'nums': [
  192. (r'\d+(\s*|\.$|$)', Number.Integer),
  193. (r'[+-]?\d*\.\d+(E[-+]?\d+)?', Number.Float),
  194. (r'[+-]?\d+\.\d*(E[-+]?\d+)?', Number.Float),
  195. ],
  196. }
  197. class CobolFreeformatLexer(CobolLexer):
  198. """
  199. Lexer for Free format OpenCOBOL code.
  200. .. versionadded:: 1.6
  201. """
  202. name = 'COBOLFree'
  203. aliases = ['cobolfree']
  204. filenames = ['*.cbl', '*.CBL']
  205. mimetypes = []
  206. flags = re.IGNORECASE | re.MULTILINE
  207. tokens = {
  208. 'comment': [
  209. (r'(\*>.*\n|^\w*\*.*$)', Comment),
  210. ],
  211. }
  212. class ABAPLexer(RegexLexer):
  213. """
  214. Lexer for ABAP, SAP's integrated language.
  215. .. versionadded:: 1.1
  216. """
  217. name = 'ABAP'
  218. aliases = ['abap']
  219. filenames = ['*.abap', '*.ABAP']
  220. mimetypes = ['text/x-abap']
  221. flags = re.IGNORECASE | re.MULTILINE
  222. tokens = {
  223. 'common': [
  224. (r'\s+', Text),
  225. (r'^\*.*$', Comment.Single),
  226. (r'\".*?\n', Comment.Single),
  227. (r'##\w+', Comment.Special),
  228. ],
  229. 'variable-names': [
  230. (r'<\S+>', Name.Variable),
  231. (r'\w[\w~]*(?:(\[\])|->\*)?', Name.Variable),
  232. ],
  233. 'root': [
  234. include('common'),
  235. # function calls
  236. (r'CALL\s+(?:BADI|CUSTOMER-FUNCTION|FUNCTION)',
  237. Keyword),
  238. (r'(CALL\s+(?:DIALOG|SCREEN|SUBSCREEN|SELECTION-SCREEN|'
  239. r'TRANSACTION|TRANSFORMATION))\b',
  240. Keyword),
  241. (r'(FORM|PERFORM)(\s+)(\w+)',
  242. bygroups(Keyword, Text, Name.Function)),
  243. (r'(PERFORM)(\s+)(\()(\w+)(\))',
  244. bygroups(Keyword, Text, Punctuation, Name.Variable, Punctuation)),
  245. (r'(MODULE)(\s+)(\S+)(\s+)(INPUT|OUTPUT)',
  246. bygroups(Keyword, Text, Name.Function, Text, Keyword)),
  247. # method implementation
  248. (r'(METHOD)(\s+)([\w~]+)',
  249. bygroups(Keyword, Text, Name.Function)),
  250. # method calls
  251. (r'(\s+)([\w\-]+)([=\-]>)([\w\-~]+)',
  252. bygroups(Text, Name.Variable, Operator, Name.Function)),
  253. # call methodnames returning style
  254. (r'(?<=(=|-)>)([\w\-~]+)(?=\()', Name.Function),
  255. # text elements
  256. (r'(TEXT)(-)(\d{3})',
  257. bygroups(Keyword, Punctuation, Number.Integer)),
  258. (r'(TEXT)(-)(\w{3})',
  259. bygroups(Keyword, Punctuation, Name.Variable)),
  260. # keywords with dashes in them.
  261. # these need to be first, because for instance the -ID part
  262. # of MESSAGE-ID wouldn't get highlighted if MESSAGE was
  263. # first in the list of keywords.
  264. (r'(ADD-CORRESPONDING|AUTHORITY-CHECK|'
  265. r'CLASS-DATA|CLASS-EVENTS|CLASS-METHODS|CLASS-POOL|'
  266. r'DELETE-ADJACENT|DIVIDE-CORRESPONDING|'
  267. r'EDITOR-CALL|ENHANCEMENT-POINT|ENHANCEMENT-SECTION|EXIT-COMMAND|'
  268. r'FIELD-GROUPS|FIELD-SYMBOLS|FUNCTION-POOL|'
  269. r'INTERFACE-POOL|INVERTED-DATE|'
  270. r'LOAD-OF-PROGRAM|LOG-POINT|'
  271. r'MESSAGE-ID|MOVE-CORRESPONDING|MULTIPLY-CORRESPONDING|'
  272. r'NEW-LINE|NEW-PAGE|NEW-SECTION|NO-EXTENSION|'
  273. r'OUTPUT-LENGTH|PRINT-CONTROL|'
  274. r'SELECT-OPTIONS|START-OF-SELECTION|SUBTRACT-CORRESPONDING|'
  275. r'SYNTAX-CHECK|SYSTEM-EXCEPTIONS|'
  276. r'TYPE-POOL|TYPE-POOLS|NO-DISPLAY'
  277. r')\b', Keyword),
  278. # keyword kombinations
  279. (r'(?<![-\>])(CREATE\s+(PUBLIC|PRIVATE|DATA|OBJECT)|'
  280. r'(PUBLIC|PRIVATE|PROTECTED)\s+SECTION|'
  281. r'(TYPE|LIKE)\s+((LINE\s+OF|REF\s+TO|'
  282. r'(SORTED|STANDARD|HASHED)\s+TABLE\s+OF))?|'
  283. r'FROM\s+(DATABASE|MEMORY)|CALL\s+METHOD|'
  284. r'(GROUP|ORDER) BY|HAVING|SEPARATED BY|'
  285. r'GET\s+(BADI|BIT|CURSOR|DATASET|LOCALE|PARAMETER|'
  286. r'PF-STATUS|(PROPERTY|REFERENCE)\s+OF|'
  287. r'RUN\s+TIME|TIME\s+(STAMP)?)?|'
  288. r'SET\s+(BIT|BLANK\s+LINES|COUNTRY|CURSOR|DATASET|EXTENDED\s+CHECK|'
  289. r'HANDLER|HOLD\s+DATA|LANGUAGE|LEFT\s+SCROLL-BOUNDARY|'
  290. r'LOCALE|MARGIN|PARAMETER|PF-STATUS|PROPERTY\s+OF|'
  291. r'RUN\s+TIME\s+(ANALYZER|CLOCK\s+RESOLUTION)|SCREEN|'
  292. r'TITLEBAR|UPADTE\s+TASK\s+LOCAL|USER-COMMAND)|'
  293. r'CONVERT\s+((INVERTED-)?DATE|TIME|TIME\s+STAMP|TEXT)|'
  294. r'(CLOSE|OPEN)\s+(DATASET|CURSOR)|'
  295. r'(TO|FROM)\s+(DATA BUFFER|INTERNAL TABLE|MEMORY ID|'
  296. r'DATABASE|SHARED\s+(MEMORY|BUFFER))|'
  297. r'DESCRIBE\s+(DISTANCE\s+BETWEEN|FIELD|LIST|TABLE)|'
  298. r'FREE\s(MEMORY|OBJECT)?|'
  299. r'PROCESS\s+(BEFORE\s+OUTPUT|AFTER\s+INPUT|'
  300. r'ON\s+(VALUE-REQUEST|HELP-REQUEST))|'
  301. r'AT\s+(LINE-SELECTION|USER-COMMAND|END\s+OF|NEW)|'
  302. r'AT\s+SELECTION-SCREEN(\s+(ON(\s+(BLOCK|(HELP|VALUE)-REQUEST\s+FOR|'
  303. r'END\s+OF|RADIOBUTTON\s+GROUP))?|OUTPUT))?|'
  304. r'SELECTION-SCREEN:?\s+((BEGIN|END)\s+OF\s+((TABBED\s+)?BLOCK|LINE|'
  305. r'SCREEN)|COMMENT|FUNCTION\s+KEY|'
  306. r'INCLUDE\s+BLOCKS|POSITION|PUSHBUTTON|'
  307. r'SKIP|ULINE)|'
  308. r'LEAVE\s+(LIST-PROCESSING|PROGRAM|SCREEN|'
  309. r'TO LIST-PROCESSING|TO TRANSACTION)'
  310. r'(ENDING|STARTING)\s+AT|'
  311. r'FORMAT\s+(COLOR|INTENSIFIED|INVERSE|HOTSPOT|INPUT|FRAMES|RESET)|'
  312. r'AS\s+(CHECKBOX|SUBSCREEN|WINDOW)|'
  313. r'WITH\s+(((NON-)?UNIQUE)?\s+KEY|FRAME)|'
  314. r'(BEGIN|END)\s+OF|'
  315. r'DELETE(\s+ADJACENT\s+DUPLICATES\sFROM)?|'
  316. r'COMPARING(\s+ALL\s+FIELDS)?|'
  317. r'(INSERT|APPEND)(\s+INITIAL\s+LINE\s+(IN)?TO|\s+LINES\s+OF)?|'
  318. r'IN\s+((BYTE|CHARACTER)\s+MODE|PROGRAM)|'
  319. r'END-OF-(DEFINITION|PAGE|SELECTION)|'
  320. r'WITH\s+FRAME(\s+TITLE)|'
  321. r'(REPLACE|FIND)\s+((FIRST|ALL)\s+OCCURRENCES?\s+OF\s+)?(SUBSTRING|REGEX)?|'
  322. r'MATCH\s+(LENGTH|COUNT|LINE|OFFSET)|'
  323. r'(RESPECTING|IGNORING)\s+CASE|'
  324. r'IN\s+UPDATE\s+TASK|'
  325. r'(SOURCE|RESULT)\s+(XML)?|'
  326. r'REFERENCE\s+INTO|'
  327. # simple kombinations
  328. r'AND\s+(MARK|RETURN)|CLIENT\s+SPECIFIED|CORRESPONDING\s+FIELDS\s+OF|'
  329. r'IF\s+FOUND|FOR\s+EVENT|INHERITING\s+FROM|LEAVE\s+TO\s+SCREEN|'
  330. r'LOOP\s+AT\s+(SCREEN)?|LOWER\s+CASE|MATCHCODE\s+OBJECT|MODIF\s+ID|'
  331. r'MODIFY\s+SCREEN|NESTING\s+LEVEL|NO\s+INTERVALS|OF\s+STRUCTURE|'
  332. r'RADIOBUTTON\s+GROUP|RANGE\s+OF|REF\s+TO|SUPPRESS DIALOG|'
  333. r'TABLE\s+OF|UPPER\s+CASE|TRANSPORTING\s+NO\s+FIELDS|'
  334. r'VALUE\s+CHECK|VISIBLE\s+LENGTH|HEADER\s+LINE|COMMON\s+PART)\b', Keyword),
  335. # single word keywords.
  336. (r'(^|(?<=(\s|\.)))(ABBREVIATED|ABSTRACT|ADD|ALIASES|ALIGN|ALPHA|'
  337. r'ASSERT|AS|ASSIGN(ING)?|AT(\s+FIRST)?|'
  338. r'BACK|BLOCK|BREAK-POINT|'
  339. r'CASE|CATCH|CHANGING|CHECK|CLASS|CLEAR|COLLECT|COLOR|COMMIT|'
  340. r'CREATE|COMMUNICATION|COMPONENTS?|COMPUTE|CONCATENATE|CONDENSE|'
  341. r'CONSTANTS|CONTEXTS|CONTINUE|CONTROLS|COUNTRY|CURRENCY|'
  342. r'DATA|DATE|DECIMALS|DEFAULT|DEFINE|DEFINITION|DEFERRED|DEMAND|'
  343. r'DETAIL|DIRECTORY|DIVIDE|DO|DUMMY|'
  344. r'ELSE(IF)?|ENDAT|ENDCASE|ENDCATCH|ENDCLASS|ENDDO|ENDFORM|ENDFUNCTION|'
  345. r'ENDIF|ENDINTERFACE|ENDLOOP|ENDMETHOD|ENDMODULE|ENDSELECT|ENDTRY|ENDWHILE|'
  346. r'ENHANCEMENT|EVENTS|EXACT|EXCEPTIONS?|EXIT|EXPONENT|EXPORT|EXPORTING|EXTRACT|'
  347. r'FETCH|FIELDS?|FOR|FORM|FORMAT|FREE|FROM|FUNCTION|'
  348. r'HIDE|'
  349. r'ID|IF|IMPORT|IMPLEMENTATION|IMPORTING|IN|INCLUDE|INCLUDING|'
  350. r'INDEX|INFOTYPES|INITIALIZATION|INTERFACE|INTERFACES|INTO|'
  351. r'LANGUAGE|LEAVE|LENGTH|LINES|LOAD|LOCAL|'
  352. r'JOIN|'
  353. r'KEY|'
  354. r'NEXT|'
  355. r'MAXIMUM|MESSAGE|METHOD[S]?|MINIMUM|MODULE|MODIFIER|MODIFY|MOVE|MULTIPLY|'
  356. r'NODES|NUMBER|'
  357. r'OBLIGATORY|OBJECT|OF|OFF|ON|OTHERS|OVERLAY|'
  358. r'PACK|PAD|PARAMETERS|PERCENTAGE|POSITION|PROGRAM|PROVIDE|PUBLIC|PUT|PF\d\d|'
  359. r'RAISE|RAISING|RANGES?|READ|RECEIVE|REDEFINITION|REFRESH|REJECT|REPORT|RESERVE|'
  360. r'RESUME|RETRY|RETURN|RETURNING|RIGHT|ROLLBACK|REPLACE|'
  361. r'SCROLL|SEARCH|SELECT|SHIFT|SIGN|SINGLE|SIZE|SKIP|SORT|SPLIT|STATICS|STOP|'
  362. r'STYLE|SUBMATCHES|SUBMIT|SUBTRACT|SUM(?!\()|SUMMARY|SUMMING|SUPPLY|'
  363. r'TABLE|TABLES|TIMESTAMP|TIMES?|TIMEZONE|TITLE|\??TO|'
  364. r'TOP-OF-PAGE|TRANSFER|TRANSLATE|TRY|TYPES|'
  365. r'ULINE|UNDER|UNPACK|UPDATE|USING|'
  366. r'VALUE|VALUES|VIA|VARYING|VARY|'
  367. r'WAIT|WHEN|WHERE|WIDTH|WHILE|WITH|WINDOW|WRITE|XSD|ZERO)\b', Keyword),
  368. # builtins
  369. (r'(abs|acos|asin|atan|'
  370. r'boolc|boolx|bit_set|'
  371. r'char_off|charlen|ceil|cmax|cmin|condense|contains|'
  372. r'contains_any_of|contains_any_not_of|concat_lines_of|cos|cosh|'
  373. r'count|count_any_of|count_any_not_of|'
  374. r'dbmaxlen|distance|'
  375. r'escape|exp|'
  376. r'find|find_end|find_any_of|find_any_not_of|floor|frac|from_mixed|'
  377. r'insert|'
  378. r'lines|log|log10|'
  379. r'match|matches|'
  380. r'nmax|nmin|numofchar|'
  381. r'repeat|replace|rescale|reverse|round|'
  382. r'segment|shift_left|shift_right|sign|sin|sinh|sqrt|strlen|'
  383. r'substring|substring_after|substring_from|substring_before|substring_to|'
  384. r'tan|tanh|to_upper|to_lower|to_mixed|translate|trunc|'
  385. r'xstrlen)(\()\b', bygroups(Name.Builtin, Punctuation)),
  386. (r'&[0-9]', Name),
  387. (r'[0-9]+', Number.Integer),
  388. # operators which look like variable names before
  389. # parsing variable names.
  390. (r'(?<=(\s|.))(AND|OR|EQ|NE|GT|LT|GE|LE|CO|CN|CA|NA|CS|NOT|NS|CP|NP|'
  391. r'BYTE-CO|BYTE-CN|BYTE-CA|BYTE-NA|BYTE-CS|BYTE-NS|'
  392. r'IS\s+(NOT\s+)?(INITIAL|ASSIGNED|REQUESTED|BOUND))\b', Operator.Word),
  393. include('variable-names'),
  394. # standard operators after variable names,
  395. # because < and > are part of field symbols.
  396. (r'[?*<>=\-+&]', Operator),
  397. (r"'(''|[^'])*'", String.Single),
  398. (r"`([^`])*`", String.Single),
  399. (r"([|}])([^{}|]*?)([|{])",
  400. bygroups(Punctuation, String.Single, Punctuation)),
  401. (r'[/;:()\[\],.]', Punctuation),
  402. (r'(!)(\w+)', bygroups(Operator, Name)),
  403. ],
  404. }
  405. class OpenEdgeLexer(RegexLexer):
  406. """
  407. Lexer for `OpenEdge ABL (formerly Progress)
  408. <http://web.progress.com/en/openedge/abl.html>`_ source code.
  409. .. versionadded:: 1.5
  410. """
  411. name = 'OpenEdge ABL'
  412. aliases = ['openedge', 'abl', 'progress']
  413. filenames = ['*.p', '*.cls']
  414. mimetypes = ['text/x-openedge', 'application/x-openedge']
  415. types = (r'(?i)(^|(?<=[^\w\-]))(CHARACTER|CHAR|CHARA|CHARAC|CHARACT|CHARACTE|'
  416. r'COM-HANDLE|DATE|DATETIME|DATETIME-TZ|'
  417. r'DECIMAL|DEC|DECI|DECIM|DECIMA|HANDLE|'
  418. r'INT64|INTEGER|INT|INTE|INTEG|INTEGE|'
  419. r'LOGICAL|LONGCHAR|MEMPTR|RAW|RECID|ROWID)\s*($|(?=[^\w\-]))')
  420. keywords = words(OPENEDGEKEYWORDS,
  421. prefix=r'(?i)(^|(?<=[^\w\-]))',
  422. suffix=r'\s*($|(?=[^\w\-]))')
  423. tokens = {
  424. 'root': [
  425. (r'/\*', Comment.Multiline, 'comment'),
  426. (r'\{', Comment.Preproc, 'preprocessor'),
  427. (r'\s*&.*', Comment.Preproc),
  428. (r'0[xX][0-9a-fA-F]+[LlUu]*', Number.Hex),
  429. (r'(?i)(DEFINE|DEF|DEFI|DEFIN)\b', Keyword.Declaration),
  430. (types, Keyword.Type),
  431. (keywords, Name.Builtin),
  432. (r'"(\\\\|\\"|[^"])*"', String.Double),
  433. (r"'(\\\\|\\'|[^'])*'", String.Single),
  434. (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
  435. (r'[0-9]+', Number.Integer),
  436. (r'\s+', Text),
  437. (r'[+*/=-]', Operator),
  438. (r'[.:()]', Punctuation),
  439. (r'.', Name.Variable), # Lazy catch-all
  440. ],
  441. 'comment': [
  442. (r'[^*/]', Comment.Multiline),
  443. (r'/\*', Comment.Multiline, '#push'),
  444. (r'\*/', Comment.Multiline, '#pop'),
  445. (r'[*/]', Comment.Multiline)
  446. ],
  447. 'preprocessor': [
  448. (r'[^{}]', Comment.Preproc),
  449. (r'\{', Comment.Preproc, '#push'),
  450. (r'\}', Comment.Preproc, '#pop'),
  451. ],
  452. }
  453. class GoodDataCLLexer(RegexLexer):
  454. """
  455. Lexer for `GoodData-CL
  456. <http://github.com/gooddata/GoodData-CL/raw/master/cli/src/main/resources/\
  457. com/gooddata/processor/COMMANDS.txt>`_
  458. script files.
  459. .. versionadded:: 1.4
  460. """
  461. name = 'GoodData-CL'
  462. aliases = ['gooddata-cl']
  463. filenames = ['*.gdc']
  464. mimetypes = ['text/x-gooddata-cl']
  465. flags = re.IGNORECASE
  466. tokens = {
  467. 'root': [
  468. # Comments
  469. (r'#.*', Comment.Single),
  470. # Function call
  471. (r'[a-z]\w*', Name.Function),
  472. # Argument list
  473. (r'\(', Punctuation, 'args-list'),
  474. # Punctuation
  475. (r';', Punctuation),
  476. # Space is not significant
  477. (r'\s+', Text)
  478. ],
  479. 'args-list': [
  480. (r'\)', Punctuation, '#pop'),
  481. (r',', Punctuation),
  482. (r'[a-z]\w*', Name.Variable),
  483. (r'=', Operator),
  484. (r'"', String, 'string-literal'),
  485. (r'[0-9]+(?:\.[0-9]+)?(?:e[+-]?[0-9]{1,3})?', Number),
  486. # Space is not significant
  487. (r'\s', Text)
  488. ],
  489. 'string-literal': [
  490. (r'\\[tnrfbae"\\]', String.Escape),
  491. (r'"', String, '#pop'),
  492. (r'[^\\"]+', String)
  493. ]
  494. }
  495. class MaqlLexer(RegexLexer):
  496. """
  497. Lexer for `GoodData MAQL
  498. <https://secure.gooddata.com/docs/html/advanced.metric.tutorial.html>`_
  499. scripts.
  500. .. versionadded:: 1.4
  501. """
  502. name = 'MAQL'
  503. aliases = ['maql']
  504. filenames = ['*.maql']
  505. mimetypes = ['text/x-gooddata-maql', 'application/x-gooddata-maql']
  506. flags = re.IGNORECASE
  507. tokens = {
  508. 'root': [
  509. # IDENTITY
  510. (r'IDENTIFIER\b', Name.Builtin),
  511. # IDENTIFIER
  512. (r'\{[^}]+\}', Name.Variable),
  513. # NUMBER
  514. (r'[0-9]+(?:\.[0-9]+)?(?:e[+-]?[0-9]{1,3})?', Number),
  515. # STRING
  516. (r'"', String, 'string-literal'),
  517. # RELATION
  518. (r'\<\>|\!\=', Operator),
  519. (r'\=|\>\=|\>|\<\=|\<', Operator),
  520. # :=
  521. (r'\:\=', Operator),
  522. # OBJECT
  523. (r'\[[^]]+\]', Name.Variable.Class),
  524. # keywords
  525. (words((
  526. 'DIMENSION', 'DIMENSIONS', 'BOTTOM', 'METRIC', 'COUNT', 'OTHER',
  527. 'FACT', 'WITH', 'TOP', 'OR', 'ATTRIBUTE', 'CREATE', 'PARENT',
  528. 'FALSE', 'ROW', 'ROWS', 'FROM', 'ALL', 'AS', 'PF', 'COLUMN',
  529. 'COLUMNS', 'DEFINE', 'REPORT', 'LIMIT', 'TABLE', 'LIKE', 'AND',
  530. 'BY', 'BETWEEN', 'EXCEPT', 'SELECT', 'MATCH', 'WHERE', 'TRUE',
  531. 'FOR', 'IN', 'WITHOUT', 'FILTER', 'ALIAS', 'WHEN', 'NOT', 'ON',
  532. 'KEYS', 'KEY', 'FULLSET', 'PRIMARY', 'LABELS', 'LABEL',
  533. 'VISUAL', 'TITLE', 'DESCRIPTION', 'FOLDER', 'ALTER', 'DROP',
  534. 'ADD', 'DATASET', 'DATATYPE', 'INT', 'BIGINT', 'DOUBLE', 'DATE',
  535. 'VARCHAR', 'DECIMAL', 'SYNCHRONIZE', 'TYPE', 'DEFAULT', 'ORDER',
  536. 'ASC', 'DESC', 'HYPERLINK', 'INCLUDE', 'TEMPLATE', 'MODIFY'),
  537. suffix=r'\b'),
  538. Keyword),
  539. # FUNCNAME
  540. (r'[a-z]\w*\b', Name.Function),
  541. # Comments
  542. (r'#.*', Comment.Single),
  543. # Punctuation
  544. (r'[,;()]', Punctuation),
  545. # Space is not significant
  546. (r'\s+', Text)
  547. ],
  548. 'string-literal': [
  549. (r'\\[tnrfbae"\\]', String.Escape),
  550. (r'"', String, '#pop'),
  551. (r'[^\\"]+', String)
  552. ],
  553. }