business.py 27 KB

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