PageRenderTime 27ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/eric4-4.4.19/eric/ThirdParty/Pygments/pygments/lexers/other.py

#
Python | 2082 lines | 1817 code | 91 blank | 174 comment | 21 complexity | 2ac69b637c66ad499af64b11c35594ae MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, BSD-2-Clause

Large files files are truncated, but you can click here to view the full file

  1. # -*- coding: utf-8 -*-
  2. """
  3. pygments.lexers.other
  4. ~~~~~~~~~~~~~~~~~~~~~
  5. Lexers for other languages.
  6. :copyright: Copyright 2006-2009 by the Pygments team, see AUTHORS.
  7. :license: BSD, see LICENSE for details.
  8. """
  9. import re
  10. from pygments.lexer import Lexer, RegexLexer, include, bygroups, using, \
  11. this, do_insertions
  12. from pygments.token import Error, Punctuation, \
  13. Text, Comment, Operator, Keyword, Name, String, Number, Generic
  14. from pygments.util import shebang_matches
  15. from pygments.lexers.web import HtmlLexer
  16. __all__ = ['SqlLexer', 'MySqlLexer', 'SqliteConsoleLexer', 'BrainfuckLexer',
  17. 'BashLexer', 'BatchLexer', 'BefungeLexer', 'RedcodeLexer',
  18. 'MOOCodeLexer', 'SmalltalkLexer', 'TcshLexer', 'LogtalkLexer',
  19. 'GnuplotLexer', 'PovrayLexer', 'AppleScriptLexer',
  20. 'BashSessionLexer', 'ModelicaLexer', 'RebolLexer', 'ABAPLexer',
  21. 'NewspeakLexer']
  22. line_re = re.compile('.*?\n')
  23. class SqlLexer(RegexLexer):
  24. """
  25. Lexer for Structured Query Language. Currently, this lexer does
  26. not recognize any special syntax except ANSI SQL.
  27. """
  28. name = 'SQL'
  29. aliases = ['sql']
  30. filenames = ['*.sql']
  31. mimetypes = ['text/x-sql']
  32. flags = re.IGNORECASE
  33. tokens = {
  34. 'root': [
  35. (r'\s+', Text),
  36. (r'--.*?\n', Comment.Single),
  37. (r'/\*', Comment.Multiline, 'multiline-comments'),
  38. (r'(ABORT|ABS|ABSOLUTE|ACCESS|ADA|ADD|ADMIN|AFTER|AGGREGATE|'
  39. r'ALIAS|ALL|ALLOCATE|ALTER|ANALYSE|ANALYZE|AND|ANY|ARE|AS|'
  40. r'ASC|ASENSITIVE|ASSERTION|ASSIGNMENT|ASYMMETRIC|AT|ATOMIC|'
  41. r'AUTHORIZATION|AVG|BACKWARD|BEFORE|BEGIN|BETWEEN|BITVAR|'
  42. r'BIT_LENGTH|BOTH|BREADTH|BY|C|CACHE|CALL|CALLED|CARDINALITY|'
  43. r'CASCADE|CASCADED|CASE|CAST|CATALOG|CATALOG_NAME|CHAIN|'
  44. r'CHARACTERISTICS|CHARACTER_LENGTH|CHARACTER_SET_CATALOG|'
  45. r'CHARACTER_SET_NAME|CHARACTER_SET_SCHEMA|CHAR_LENGTH|CHECK|'
  46. r'CHECKED|CHECKPOINT|CLASS|CLASS_ORIGIN|CLOB|CLOSE|CLUSTER|'
  47. r'COALSECE|COBOL|COLLATE|COLLATION|COLLATION_CATALOG|'
  48. r'COLLATION_NAME|COLLATION_SCHEMA|COLUMN|COLUMN_NAME|'
  49. r'COMMAND_FUNCTION|COMMAND_FUNCTION_CODE|COMMENT|COMMIT|'
  50. r'COMMITTED|COMPLETION|CONDITION_NUMBER|CONNECT|CONNECTION|'
  51. r'CONNECTION_NAME|CONSTRAINT|CONSTRAINTS|CONSTRAINT_CATALOG|'
  52. r'CONSTRAINT_NAME|CONSTRAINT_SCHEMA|CONSTRUCTOR|CONTAINS|'
  53. r'CONTINUE|CONVERSION|CONVERT|COPY|CORRESPONTING|COUNT|'
  54. r'CREATE|CREATEDB|CREATEUSER|CROSS|CUBE|CURRENT|CURRENT_DATE|'
  55. r'CURRENT_PATH|CURRENT_ROLE|CURRENT_TIME|CURRENT_TIMESTAMP|'
  56. r'CURRENT_USER|CURSOR|CURSOR_NAME|CYCLE|DATA|DATABASE|'
  57. r'DATETIME_INTERVAL_CODE|DATETIME_INTERVAL_PRECISION|DAY|'
  58. r'DEALLOCATE|DECLARE|DEFAULT|DEFAULTS|DEFERRABLE|DEFERRED|'
  59. r'DEFINED|DEFINER|DELETE|DELIMITER|DELIMITERS|DEREF|DESC|'
  60. r'DESCRIBE|DESCRIPTOR|DESTROY|DESTRUCTOR|DETERMINISTIC|'
  61. r'DIAGNOSTICS|DICTIONARY|DISCONNECT|DISPATCH|DISTINCT|DO|'
  62. r'DOMAIN|DROP|DYNAMIC|DYNAMIC_FUNCTION|DYNAMIC_FUNCTION_CODE|'
  63. r'EACH|ELSE|ENCODING|ENCRYPTED|END|END-EXEC|EQUALS|ESCAPE|EVERY|'
  64. r'EXCEPT|ESCEPTION|EXCLUDING|EXCLUSIVE|EXEC|EXECUTE|EXISTING|'
  65. r'EXISTS|EXPLAIN|EXTERNAL|EXTRACT|FALSE|FETCH|FINAL|FIRST|FOR|'
  66. r'FORCE|FOREIGN|FORTRAN|FORWARD|FOUND|FREE|FREEZE|FROM|FULL|'
  67. r'FUNCTION|G|GENERAL|GENERATED|GET|GLOBAL|GO|GOTO|GRANT|GRANTED|'
  68. r'GROUP|GROUPING|HANDLER|HAVING|HIERARCHY|HOLD|HOST|IDENTITY|'
  69. r'IGNORE|ILIKE|IMMEDIATE|IMMUTABLE|IMPLEMENTATION|IMPLICIT|IN|'
  70. r'INCLUDING|INCREMENT|INDEX|INDITCATOR|INFIX|INHERITS|INITIALIZE|'
  71. r'INITIALLY|INNER|INOUT|INPUT|INSENSITIVE|INSERT|INSTANTIABLE|'
  72. r'INSTEAD|INTERSECT|INTO|INVOKER|IS|ISNULL|ISOLATION|ITERATE|JOIN|'
  73. r'KEY|KEY_MEMBER|KEY_TYPE|LANCOMPILER|LANGUAGE|LARGE|LAST|'
  74. r'LATERAL|LEADING|LEFT|LENGTH|LESS|LEVEL|LIKE|LIMIT|LISTEN|LOAD|'
  75. r'LOCAL|LOCALTIME|LOCALTIMESTAMP|LOCATION|LOCATOR|LOCK|LOWER|'
  76. r'MAP|MATCH|MAX|MAXVALUE|MESSAGE_LENGTH|MESSAGE_OCTET_LENGTH|'
  77. r'MESSAGE_TEXT|METHOD|MIN|MINUTE|MINVALUE|MOD|MODE|MODIFIES|'
  78. r'MODIFY|MONTH|MORE|MOVE|MUMPS|NAMES|NATIONAL|NATURAL|NCHAR|'
  79. r'NCLOB|NEW|NEXT|NO|NOCREATEDB|NOCREATEUSER|NONE|NOT|NOTHING|'
  80. r'NOTIFY|NOTNULL|NULL|NULLABLE|NULLIF|OBJECT|OCTET_LENGTH|OF|OFF|'
  81. r'OFFSET|OIDS|OLD|ON|ONLY|OPEN|OPERATION|OPERATOR|OPTION|OPTIONS|'
  82. r'OR|ORDER|ORDINALITY|OUT|OUTER|OUTPUT|OVERLAPS|OVERLAY|OVERRIDING|'
  83. r'OWNER|PAD|PARAMETER|PARAMETERS|PARAMETER_MODE|PARAMATER_NAME|'
  84. r'PARAMATER_ORDINAL_POSITION|PARAMETER_SPECIFIC_CATALOG|'
  85. r'PARAMETER_SPECIFIC_NAME|PARAMATER_SPECIFIC_SCHEMA|PARTIAL|'
  86. r'PASCAL|PENDANT|PLACING|PLI|POSITION|POSTFIX|PRECISION|PREFIX|'
  87. r'PREORDER|PREPARE|PRESERVE|PRIMARY|PRIOR|PRIVILEGES|PROCEDURAL|'
  88. r'PROCEDURE|PUBLIC|READ|READS|RECHECK|RECURSIVE|REF|REFERENCES|'
  89. r'REFERENCING|REINDEX|RELATIVE|RENAME|REPEATABLE|REPLACE|RESET|'
  90. r'RESTART|RESTRICT|RESULT|RETURN|RETURNED_LENGTH|'
  91. r'RETURNED_OCTET_LENGTH|RETURNED_SQLSTATE|RETURNS|REVOKE|RIGHT|'
  92. r'ROLE|ROLLBACK|ROLLUP|ROUTINE|ROUTINE_CATALOG|ROUTINE_NAME|'
  93. r'ROUTINE_SCHEMA|ROW|ROWS|ROW_COUNT|RULE|SAVE_POINT|SCALE|SCHEMA|'
  94. r'SCHEMA_NAME|SCOPE|SCROLL|SEARCH|SECOND|SECURITY|SELECT|SELF|'
  95. r'SENSITIVE|SERIALIZABLE|SERVER_NAME|SESSION|SESSION_USER|SET|'
  96. r'SETOF|SETS|SHARE|SHOW|SIMILAR|SIMPLE|SIZE|SOME|SOURCE|SPACE|'
  97. r'SPECIFIC|SPECIFICTYPE|SPECIFIC_NAME|SQL|SQLCODE|SQLERROR|'
  98. r'SQLEXCEPTION|SQLSTATE|SQLWARNINIG|STABLE|START|STATE|STATEMENT|'
  99. r'STATIC|STATISTICS|STDIN|STDOUT|STORAGE|STRICT|STRUCTURE|STYPE|'
  100. r'SUBCLASS_ORIGIN|SUBLIST|SUBSTRING|SUM|SYMMETRIC|SYSID|SYSTEM|'
  101. r'SYSTEM_USER|TABLE|TABLE_NAME| TEMP|TEMPLATE|TEMPORARY|TERMINATE|'
  102. r'THAN|THEN|TIMESTAMP|TIMEZONE_HOUR|TIMEZONE_MINUTE|TO|TOAST|'
  103. r'TRAILING|TRANSATION|TRANSACTIONS_COMMITTED|'
  104. r'TRANSACTIONS_ROLLED_BACK|TRANSATION_ACTIVE|TRANSFORM|'
  105. r'TRANSFORMS|TRANSLATE|TRANSLATION|TREAT|TRIGGER|TRIGGER_CATALOG|'
  106. r'TRIGGER_NAME|TRIGGER_SCHEMA|TRIM|TRUE|TRUNCATE|TRUSTED|TYPE|'
  107. r'UNCOMMITTED|UNDER|UNENCRYPTED|UNION|UNIQUE|UNKNOWN|UNLISTEN|'
  108. r'UNNAMED|UNNEST|UNTIL|UPDATE|UPPER|USAGE|USER|'
  109. r'USER_DEFINED_TYPE_CATALOG|USER_DEFINED_TYPE_NAME|'
  110. r'USER_DEFINED_TYPE_SCHEMA|USING|VACUUM|VALID|VALIDATOR|VALUES|'
  111. r'VARIABLE|VERBOSE|VERSION|VIEW|VOLATILE|WHEN|WHENEVER|WHERE|'
  112. r'WITH|WITHOUT|WORK|WRITE|YEAR|ZONE)\b', Keyword),
  113. (r'(ARRAY|BIGINT|BINARY|BIT|BLOB|BOOLEAN|CHAR|CHARACTER|DATE|'
  114. r'DEC|DECIMAL|FLOAT|INT|INTEGER|INTERVAL|NUMBER|NUMERIC|REAL|'
  115. r'SERIAL|SMALLINT|VARCHAR|VARYING|INT8|SERIAL8|TEXT)\b',
  116. Name.Builtin),
  117. (r'[+*/<>=~!@#%^&|`?^-]', Operator),
  118. (r'[0-9]+', Number.Integer),
  119. # TODO: Backslash escapes?
  120. (r"'(''|[^'])*'", String.Single),
  121. (r'"(""|[^"])*"', String.Symbol), # not a real string literal in ANSI SQL
  122. (r'[a-zA-Z_][a-zA-Z0-9_]*', Name),
  123. (r'[;:()\[\],\.]', Punctuation)
  124. ],
  125. 'multiline-comments': [
  126. (r'/\*', Comment.Multiline, 'multiline-comments'),
  127. (r'\*/', Comment.Multiline, '#pop'),
  128. (r'[^/\*]+', Comment.Multiline),
  129. (r'[/*]', Comment.Multiline)
  130. ]
  131. }
  132. class MySqlLexer(RegexLexer):
  133. """
  134. Special lexer for MySQL.
  135. """
  136. name = 'MySQL'
  137. aliases = ['mysql']
  138. mimetypes = ['text/x-mysql']
  139. flags = re.IGNORECASE
  140. tokens = {
  141. 'root': [
  142. (r'\s+', Text),
  143. (r'(#|--\s+).*?\n', Comment.Single),
  144. (r'/\*', Comment.Multiline, 'multiline-comments'),
  145. (r'[0-9]+', Number.Integer),
  146. (r'[0-9]*\.[0-9]+(e[+-][0-9]+)', Number.Float),
  147. # TODO: add backslash escapes
  148. (r"'(''|[^'])*'", String.Single),
  149. (r'"(""|[^"])*"', String.Double),
  150. (r"`(``|[^`])*`", String.Symbol),
  151. (r'[+*/<>=~!@#%^&|`?^-]', Operator),
  152. (r'\b(tinyint|smallint|mediumint|int|integer|bigint|date|'
  153. r'datetime|time|bit|bool|tinytext|mediumtext|longtext|text|'
  154. r'tinyblob|mediumblob|longblob|blob|float|double|double\s+'
  155. r'precision|real|numeric|dec|decimal|timestamp|year|char|'
  156. r'varchar|varbinary|varcharacter|enum|set)(\b\s*)(\()?',
  157. bygroups(Keyword.Type, Text, Punctuation)),
  158. (r'\b(add|all|alter|analyze|and|as|asc|asensitive|before|between|'
  159. r'bigint|binary|blob|both|by|call|cascade|case|change|char|'
  160. r'character|check|collate|column|condition|constraint|continue|'
  161. r'convert|create|cross|current_date|current_time|'
  162. r'current_timestamp|current_user|cursor|database|databases|'
  163. r'day_hour|day_microsecond|day_minute|day_second|dec|decimal|'
  164. r'declare|default|delayed|delete|desc|describe|deterministic|'
  165. r'distinct|distinctrow|div|double|drop|dual|each|else|elseif|'
  166. r'enclosed|escaped|exists|exit|explain|fetch|float|float4|float8'
  167. r'|for|force|foreign|from|fulltext|grant|group|having|'
  168. r'high_priority|hour_microsecond|hour_minute|hour_second|if|'
  169. r'ignore|in|index|infile|inner|inout|insensitive|insert|int|'
  170. r'int1|int2|int3|int4|int8|integer|interval|into|is|iterate|'
  171. r'join|key|keys|kill|leading|leave|left|like|limit|lines|load|'
  172. r'localtime|localtimestamp|lock|long|loop|low_priority|match|'
  173. r'minute_microsecond|minute_second|mod|modifies|natural|'
  174. r'no_write_to_binlog|not|numeric|on|optimize|option|optionally|'
  175. r'or|order|out|outer|outfile|precision|primary|procedure|purge|'
  176. r'raid0|read|reads|real|references|regexp|release|rename|repeat|'
  177. r'replace|require|restrict|return|revoke|right|rlike|schema|'
  178. r'schemas|second_microsecond|select|sensitive|separator|set|'
  179. r'show|smallint|soname|spatial|specific|sql|sql_big_result|'
  180. r'sql_calc_found_rows|sql_small_result|sqlexception|sqlstate|'
  181. r'sqlwarning|ssl|starting|straight_join|table|terminated|then|'
  182. r'to|trailing|trigger|undo|union|unique|unlock|unsigned|update|'
  183. r'usage|use|using|utc_date|utc_time|utc_timestamp|values|'
  184. r'varying|when|where|while|with|write|x509|xor|year_month|'
  185. r'zerofill)\b', Keyword),
  186. # TODO: this list is not complete
  187. (r'\b(auto_increment|engine|charset|tables)\b', Keyword.Pseudo),
  188. (r'(true|false|null)', Name.Constant),
  189. (r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*)(\()',
  190. bygroups(Name.Function, Text, Punctuation)),
  191. (r'[a-zA-Z_][a-zA-Z0-9_]*', Name),
  192. (r'@[A-Za-z0-9]*[._]*[A-Za-z0-9]*', Name.Variable),
  193. (r'[;:()\[\],\.]', Punctuation)
  194. ],
  195. 'multiline-comments': [
  196. (r'/\*', Comment.Multiline, 'multiline-comments'),
  197. (r'\*/', Comment.Multiline, '#pop'),
  198. (r'[^/\*]+', Comment.Multiline),
  199. (r'[/*]', Comment.Multiline)
  200. ]
  201. }
  202. class SqliteConsoleLexer(Lexer):
  203. """
  204. Lexer for example sessions using sqlite3.
  205. *New in Pygments 0.11.*
  206. """
  207. name = 'sqlite3con'
  208. aliases = ['sqlite3']
  209. filenames = ['*.sqlite3-console']
  210. mimetypes = ['text/x-sqlite3-console']
  211. def get_tokens_unprocessed(self, data):
  212. sql = SqlLexer(**self.options)
  213. curcode = ''
  214. insertions = []
  215. for match in line_re.finditer(data):
  216. line = match.group()
  217. if line.startswith('sqlite> ') or line.startswith(' ...> '):
  218. insertions.append((len(curcode),
  219. [(0, Generic.Prompt, line[:8])]))
  220. curcode += line[8:]
  221. else:
  222. if curcode:
  223. for item in do_insertions(insertions,
  224. sql.get_tokens_unprocessed(curcode)):
  225. yield item
  226. curcode = ''
  227. insertions = []
  228. if line.startswith('SQL error: '):
  229. yield (match.start(), Generic.Traceback, line)
  230. else:
  231. yield (match.start(), Generic.Output, line)
  232. if curcode:
  233. for item in do_insertions(insertions,
  234. sql.get_tokens_unprocessed(curcode)):
  235. yield item
  236. class BrainfuckLexer(RegexLexer):
  237. """
  238. Lexer for the esoteric `BrainFuck <http://www.muppetlabs.com/~breadbox/bf/>`_
  239. language.
  240. """
  241. name = 'Brainfuck'
  242. aliases = ['brainfuck', 'bf']
  243. filenames = ['*.bf', '*.b']
  244. mimetypes = ['application/x-brainfuck']
  245. tokens = {
  246. 'common': [
  247. # use different colors for different instruction types
  248. (r'[.,]+', Name.Tag),
  249. (r'[+-]+', Name.Builtin),
  250. (r'[<>]+', Name.Variable),
  251. (r'[^.,+\-<>\[\]]+', Comment),
  252. ],
  253. 'root': [
  254. (r'\[', Keyword, 'loop'),
  255. (r'\]', Error),
  256. include('common'),
  257. ],
  258. 'loop': [
  259. (r'\[', Keyword, '#push'),
  260. (r'\]', Keyword, '#pop'),
  261. include('common'),
  262. ]
  263. }
  264. class BefungeLexer(RegexLexer):
  265. """
  266. Lexer for the esoteric `Befunge <http://en.wikipedia.org/wiki/Befunge>`_
  267. language.
  268. *New in Pygments 0.7.*
  269. """
  270. name = 'Befunge'
  271. aliases = ['befunge']
  272. filenames = ['*.befunge']
  273. mimetypes = ['application/x-befunge']
  274. tokens = {
  275. 'root': [
  276. (r'[0-9a-f]', Number),
  277. (r'[\+\*/%!`-]', Operator), # Traditional math
  278. (r'[<>^v?\[\]rxjk]', Name.Variable), # Move, imperatives
  279. (r'[:\\$.,n]', Name.Builtin), # Stack ops, imperatives
  280. (r'[|_mw]', Keyword),
  281. (r'[{}]', Name.Tag), # Befunge-98 stack ops
  282. (r'".*?"', String.Double), # Strings don't appear to allow escapes
  283. (r'\'.', String.Single), # Single character
  284. (r'[#;]', Comment), # Trampoline... depends on direction hit
  285. (r'[pg&~=@iotsy]', Keyword), # Misc
  286. (r'[()A-Z]', Comment), # Fingerprints
  287. (r'\s+', Text), # Whitespace doesn't matter
  288. ],
  289. }
  290. class BashLexer(RegexLexer):
  291. """
  292. Lexer for (ba)sh shell scripts.
  293. *New in Pygments 0.6.*
  294. """
  295. name = 'Bash'
  296. aliases = ['bash', 'sh']
  297. filenames = ['*.sh']
  298. mimetypes = ['application/x-sh', 'application/x-shellscript']
  299. tokens = {
  300. 'root': [
  301. include('basic'),
  302. (r'\$\(\(', Keyword, 'math'),
  303. (r'\$\(', Keyword, 'paren'),
  304. (r'\${#?', Keyword, 'curly'),
  305. (r'`', String.Backtick, 'backticks'),
  306. include('data'),
  307. ],
  308. 'basic': [
  309. (r'\b(if|fi|else|while|do|done|for|then|return|function|case|'
  310. r'select|continue|until|esac|elif)\s*\b',
  311. Keyword),
  312. (r'\b(alias|bg|bind|break|builtin|caller|cd|command|compgen|'
  313. r'complete|declare|dirs|disown|echo|enable|eval|exec|exit|'
  314. r'export|false|fc|fg|getopts|hash|help|history|jobs|kill|let|'
  315. r'local|logout|popd|printf|pushd|pwd|read|readonly|set|shift|'
  316. r'shopt|source|suspend|test|time|times|trap|true|type|typeset|'
  317. r'ulimit|umask|unalias|unset|wait)\s*\b(?!\.)',
  318. Name.Builtin),
  319. (r'#.*\n', Comment),
  320. (r'\\[\w\W]', String.Escape),
  321. (r'(\b\w+)(\s*)(=)', bygroups(Name.Variable, Text, Operator)),
  322. (r'[\[\]{}()=]', Operator),
  323. (r'<<\s*(\'?)\\?(\w+)[\w\W]+?\2', String),
  324. (r'&&|\|\|', Operator),
  325. ],
  326. 'data': [
  327. (r'\$?"(\\\\|\\[0-7]+|\\.|[^"])*"', String.Double),
  328. (r"\$?'(\\\\|\\[0-7]+|\\.|[^'])*'", String.Single),
  329. (r';', Text),
  330. (r'\s+', Text),
  331. (r'[^=\s\n\[\]{}()$"\'`\\<]+', Text),
  332. (r'\d+(?= |\Z)', Number),
  333. (r'\$#?(\w+|.)', Name.Variable),
  334. (r'<', Text),
  335. ],
  336. 'curly': [
  337. (r'}', Keyword, '#pop'),
  338. (r':-', Keyword),
  339. (r'[a-zA-Z0-9_]+', Name.Variable),
  340. (r'[^}:"\'`$]+', Punctuation),
  341. (r':', Punctuation),
  342. include('root'),
  343. ],
  344. 'paren': [
  345. (r'\)', Keyword, '#pop'),
  346. include('root'),
  347. ],
  348. 'math': [
  349. (r'\)\)', Keyword, '#pop'),
  350. (r'[-+*/%^|&]|\*\*|\|\|', Operator),
  351. (r'\d+', Number),
  352. include('root'),
  353. ],
  354. 'backticks': [
  355. (r'`', String.Backtick, '#pop'),
  356. include('root'),
  357. ],
  358. }
  359. def analyse_text(text):
  360. return shebang_matches(text, r'(ba|z|)sh')
  361. class BashSessionLexer(Lexer):
  362. """
  363. Lexer for simplistic shell sessions.
  364. *New in Pygments 1.1.*
  365. """
  366. name = 'Bash Session'
  367. aliases = ['console']
  368. filenames = ['*.sh-session']
  369. mimetypes = ['application/x-shell-session']
  370. def get_tokens_unprocessed(self, text):
  371. bashlexer = BashLexer(**self.options)
  372. pos = 0
  373. curcode = ''
  374. insertions = []
  375. for match in line_re.finditer(text):
  376. line = match.group()
  377. m = re.match(r'^((?:|sh\S*?|\w+\S+[@:]\S+(?:\s+\S+)?|\[\S+[@:]'
  378. r'[^\n]+\].+)[$#%])(.*\n?)', line)
  379. if m:
  380. # To support output lexers (say diff output), the output
  381. # needs to be broken by prompts whenever the output lexer
  382. # changes.
  383. if not insertions:
  384. pos = match.start()
  385. insertions.append((len(curcode),
  386. [(0, Generic.Prompt, m.group(1))]))
  387. curcode += m.group(2)
  388. elif line.startswith('>'):
  389. insertions.append((len(curcode),
  390. [(0, Generic.Prompt, line[:1])]))
  391. curcode += line[1:]
  392. else:
  393. if insertions:
  394. toks = bashlexer.get_tokens_unprocessed(curcode)
  395. for i, t, v in do_insertions(insertions, toks):
  396. yield pos+i, t, v
  397. yield match.start(), Generic.Output, line
  398. insertions = []
  399. curcode = ''
  400. if insertions:
  401. for i, t, v in do_insertions(insertions,
  402. bashlexer.get_tokens_unprocessed(curcode)):
  403. yield pos+i, t, v
  404. class BatchLexer(RegexLexer):
  405. """
  406. Lexer for the DOS/Windows Batch file format.
  407. *New in Pygments 0.7.*
  408. """
  409. name = 'Batchfile'
  410. aliases = ['bat']
  411. filenames = ['*.bat', '*.cmd']
  412. mimetypes = ['application/x-dos-batch']
  413. flags = re.MULTILINE | re.IGNORECASE
  414. tokens = {
  415. 'root': [
  416. # Lines can start with @ to prevent echo
  417. (r'^\s*@', Punctuation),
  418. (r'^(\s*)(rem\s.*)$', bygroups(Text, Comment)),
  419. (r'".*?"', String.Double),
  420. (r"'.*?'", String.Single),
  421. # If made more specific, make sure you still allow expansions
  422. # like %~$VAR:zlt
  423. (r'%%?[~$:\w]+%?', Name.Variable),
  424. (r'::.*', Comment), # Technically :: only works at BOL
  425. (r'(set)(\s+)(\w+)', bygroups(Keyword, Text, Name.Variable)),
  426. (r'(call)(\s+)(:\w+)', bygroups(Keyword, Text, Name.Label)),
  427. (r'(goto)(\s+)(\w+)', bygroups(Keyword, Text, Name.Label)),
  428. (r'\b(set|call|echo|on|off|endlocal|for|do|goto|if|pause|'
  429. r'setlocal|shift|errorlevel|exist|defined|cmdextversion|'
  430. r'errorlevel|else|cd|md|del|deltree|cls|choice)\b', Keyword),
  431. (r'\b(equ|neq|lss|leq|gtr|geq)\b', Operator),
  432. include('basic'),
  433. (r'.', Text),
  434. ],
  435. 'echo': [
  436. # Escapes only valid within echo args?
  437. (r'\^\^|\^<|\^>|\^\|', String.Escape),
  438. (r'\n', Text, '#pop'),
  439. include('basic'),
  440. (r'[^\'"^]+', Text),
  441. ],
  442. 'basic': [
  443. (r'".*?"', String.Double),
  444. (r"'.*?'", String.Single),
  445. (r'`.*?`', String.Backtick),
  446. (r'-?\d+', Number),
  447. (r',', Punctuation),
  448. (r'=', Operator),
  449. (r'/\S+', Name),
  450. (r':\w+', Name.Label),
  451. (r'\w:\w+', Text),
  452. (r'([<>|])(\s*)(\w+)', bygroups(Punctuation, Text, Name)),
  453. ],
  454. }
  455. class RedcodeLexer(RegexLexer):
  456. """
  457. A simple Redcode lexer based on ICWS'94.
  458. Contributed by Adam Blinkinsop <blinks@acm.org>.
  459. *New in Pygments 0.8.*
  460. """
  461. name = 'Redcode'
  462. aliases = ['redcode']
  463. filenames = ['*.cw']
  464. opcodes = ['DAT','MOV','ADD','SUB','MUL','DIV','MOD',
  465. 'JMP','JMZ','JMN','DJN','CMP','SLT','SPL',
  466. 'ORG','EQU','END']
  467. modifiers = ['A','B','AB','BA','F','X','I']
  468. tokens = {
  469. 'root': [
  470. # Whitespace:
  471. (r'\s+', Text),
  472. (r';.*$', Comment.Single),
  473. # Lexemes:
  474. # Identifiers
  475. (r'\b(%s)\b' % '|'.join(opcodes), Name.Function),
  476. (r'\b(%s)\b' % '|'.join(modifiers), Name.Decorator),
  477. (r'[A-Za-z_][A-Za-z_0-9]+', Name),
  478. # Operators
  479. (r'[-+*/%]', Operator),
  480. (r'[#$@<>]', Operator), # mode
  481. (r'[.,]', Punctuation), # mode
  482. # Numbers
  483. (r'[-+]?\d+', Number.Integer),
  484. ],
  485. }
  486. class MOOCodeLexer(RegexLexer):
  487. """
  488. For `MOOCode <http://www.moo.mud.org/>`_ (the MOO scripting
  489. language).
  490. *New in Pygments 0.9.*
  491. """
  492. name = 'MOOCode'
  493. filenames = ['*.moo']
  494. aliases = ['moocode']
  495. mimetypes = ['text/x-moocode']
  496. tokens = {
  497. 'root' : [
  498. # Numbers
  499. (r'(0|[1-9][0-9_]*)', Number.Integer),
  500. # Strings
  501. (r'"(\\\\|\\"|[^"])*"', String),
  502. # exceptions
  503. (r'(E_PERM|E_DIV)', Name.Exception),
  504. # db-refs
  505. (r'((#[-0-9]+)|(\$[a-z_A-Z0-9]+))', Name.Entity),
  506. # Keywords
  507. (r'\b(if|else|elseif|endif|for|endfor|fork|endfork|while'
  508. r'|endwhile|break|continue|return|try'
  509. r'|except|endtry|finally|in)\b', Keyword),
  510. # builtins
  511. (r'(random|length)', Name.Builtin),
  512. # special variables
  513. (r'(player|caller|this|args)', Name.Variable.Instance),
  514. # skip whitespace
  515. (r'\s+', Text),
  516. (r'\n', Text),
  517. # other operators
  518. (r'([!;=,{}&\|:\.\[\]@\(\)\<\>\?]+)', Operator),
  519. # function call
  520. (r'([a-z_A-Z0-9]+)(\()', bygroups(Name.Function, Operator)),
  521. # variables
  522. (r'([a-zA-Z_0-9]+)', Text),
  523. ]
  524. }
  525. class SmalltalkLexer(RegexLexer):
  526. """
  527. For `Smalltalk <http://www.smalltalk.org/>`_ syntax.
  528. Contributed by Stefan Matthias Aust.
  529. Rewritten by Nils Winter.
  530. *New in Pygments 0.10.*
  531. """
  532. name = 'Smalltalk'
  533. filenames = ['*.st']
  534. aliases = ['smalltalk', 'squeak']
  535. mimetypes = ['text/x-smalltalk']
  536. tokens = {
  537. 'root' : [
  538. (r'(<)(\w+:)(.*?)(>)', bygroups(Text, Keyword, Text, Text)),
  539. include('squeak fileout'),
  540. include('whitespaces'),
  541. include('method definition'),
  542. (r'(\|)([\w\s]*)(\|)', bygroups(Operator, Name.Variable, Operator)),
  543. include('objects'),
  544. (r'\^|\:=|\_', Operator),
  545. # temporaries
  546. (r'[\]({}.;!]', Text),
  547. ],
  548. 'method definition' : [
  549. # Not perfect can't allow whitespaces at the beginning and the
  550. # without breaking everything
  551. (r'([a-zA-Z]+\w*:)(\s*)(\w+)',
  552. bygroups(Name.Function, Text, Name.Variable)),
  553. (r'^(\b[a-zA-Z]+\w*\b)(\s*)$', bygroups(Name.Function, Text)),
  554. (r'^([-+*/\\~<>=|&!?,@%]+)(\s*)(\w+)(\s*)$',
  555. bygroups(Name.Function, Text, Name.Variable, Text)),
  556. ],
  557. 'blockvariables' : [
  558. include('whitespaces'),
  559. (r'(:)(\s*)([A-Za-z\w]+)',
  560. bygroups(Operator, Text, Name.Variable)),
  561. (r'\|', Operator, '#pop'),
  562. (r'', Text, '#pop'), # else pop
  563. ],
  564. 'literals' : [
  565. (r'\'[^\']*\'', String, 'afterobject'),
  566. (r'\$.', String.Char, 'afterobject'),
  567. (r'#\(', String.Symbol, 'parenth'),
  568. (r'\)', Text, 'afterobject'),
  569. (r'(\d+r)?-?\d+(\.\d+)?(e-?\d+)?', Number, 'afterobject'),
  570. ],
  571. '_parenth_helper' : [
  572. include('whitespaces'),
  573. (r'[-+*/\\~<>=|&#!?,@%\w+:]+', String.Symbol),
  574. # literals
  575. (r'\'[^\']*\'', String),
  576. (r'\$.', String.Char),
  577. (r'(\d+r)?-?\d+(\.\d+)?(e-?\d+)?', Number),
  578. (r'#*\(', String.Symbol, 'inner_parenth'),
  579. ],
  580. 'parenth' : [
  581. # This state is a bit tricky since
  582. # we can't just pop this state
  583. (r'\)', String.Symbol, ('root','afterobject')),
  584. include('_parenth_helper'),
  585. ],
  586. 'inner_parenth': [
  587. (r'\)', String.Symbol, '#pop'),
  588. include('_parenth_helper'),
  589. ],
  590. 'whitespaces' : [
  591. # skip whitespace and comments
  592. (r'\s+', Text),
  593. (r'"[^"]*"', Comment),
  594. ],
  595. 'objects' : [
  596. (r'\[', Text, 'blockvariables'),
  597. (r'\]', Text, 'afterobject'),
  598. (r'\b(self|super|true|false|nil|thisContext)\b',
  599. Name.Builtin.Pseudo, 'afterobject'),
  600. (r'\b[A-Z]\w*(?!:)\b', Name.Class, 'afterobject'),
  601. (r'\b[a-z]\w*(?!:)\b', Name.Variable, 'afterobject'),
  602. (r'#("[^"]*"|[-+*/\\~<>=|&!?,@%]+|[\w:]+)',
  603. String.Symbol, 'afterobject'),
  604. include('literals'),
  605. ],
  606. 'afterobject' : [
  607. (r'! !$', Keyword , '#pop'), # squeak chunk delimeter
  608. include('whitespaces'),
  609. (r'\b(ifTrue:|ifFalse:|whileTrue:|whileFalse:|timesRepeat:)',
  610. Name.Builtin, '#pop'),
  611. (r'\b(new\b(?!:))', Name.Builtin),
  612. (r'\:=|\_', Operator, '#pop'),
  613. (r'\b[a-zA-Z]+\w*:', Name.Function, '#pop'),
  614. (r'\b[a-zA-Z]+\w*', Name.Function),
  615. (r'\w+:?|[-+*/\\~<>=|&!?,@%]+', Name.Function, '#pop'),
  616. (r'\.', Punctuation, '#pop'),
  617. (r';', Punctuation),
  618. (r'[\])}]', Text),
  619. (r'[\[({]', Text, '#pop'),
  620. ],
  621. 'squeak fileout' : [
  622. # Squeak fileout format (optional)
  623. (r'^"[^"]*"!', Keyword),
  624. (r"^'[^']*'!", Keyword),
  625. (r'^(!)(\w+)( commentStamp: )(.*?)( prior: .*?!\n)(.*?)(!)',
  626. bygroups(Keyword, Name.Class, Keyword, String, Keyword, Text, Keyword)),
  627. (r'^(!)(\w+(?: class)?)( methodsFor: )(\'[^\']*\')(.*?!)',
  628. bygroups(Keyword, Name.Class, Keyword, String, Keyword)),
  629. (r'^(\w+)( subclass: )(#\w+)'
  630. r'(\s+instanceVariableNames: )(.*?)'
  631. r'(\s+classVariableNames: )(.*?)'
  632. r'(\s+poolDictionaries: )(.*?)'
  633. r'(\s+category: )(.*?)(!)',
  634. bygroups(Name.Class, Keyword, String.Symbol, Keyword, String, Keyword,
  635. String, Keyword, String, Keyword, String, Keyword)),
  636. (r'^(\w+(?: class)?)(\s+instanceVariableNames: )(.*?)(!)',
  637. bygroups(Name.Class, Keyword, String, Keyword)),
  638. (r'(!\n)(\].*)(! !)$', bygroups(Keyword, Text, Keyword)),
  639. (r'! !$', Keyword),
  640. ],
  641. }
  642. class TcshLexer(RegexLexer):
  643. """
  644. Lexer for tcsh scripts.
  645. *New in Pygments 0.10.*
  646. """
  647. name = 'Tcsh'
  648. aliases = ['tcsh', 'csh']
  649. filenames = ['*.tcsh', '*.csh']
  650. mimetypes = ['application/x-csh']
  651. tokens = {
  652. 'root': [
  653. include('basic'),
  654. (r'\$\(', Keyword, 'paren'),
  655. (r'\${#?', Keyword, 'curly'),
  656. (r'`', String.Backtick, 'backticks'),
  657. include('data'),
  658. ],
  659. 'basic': [
  660. (r'\b(if|endif|else|while|then|foreach|case|default|'
  661. r'continue|goto|breaksw|end|switch|endsw)\s*\b',
  662. Keyword),
  663. (r'\b(alias|alloc|bg|bindkey|break|builtins|bye|caller|cd|chdir|'
  664. r'complete|dirs|echo|echotc|eval|exec|exit|'
  665. r'fg|filetest|getxvers|glob|getspath|hashstat|history|hup|inlib|jobs|kill|'
  666. r'limit|log|login|logout|ls-F|migrate|newgrp|nice|nohup|notify|'
  667. r'onintr|popd|printenv|pushd|rehash|repeat|rootnode|popd|pushd|set|shift|'
  668. r'sched|setenv|setpath|settc|setty|setxvers|shift|source|stop|suspend|'
  669. r'source|suspend|telltc|time|'
  670. r'umask|unalias|uncomplete|unhash|universe|unlimit|unset|unsetenv|'
  671. r'ver|wait|warp|watchlog|where|which)\s*\b',
  672. Name.Builtin),
  673. (r'#.*\n', Comment),
  674. (r'\\[\w\W]', String.Escape),
  675. (r'(\b\w+)(\s*)(=)', bygroups(Name.Variable, Text, Operator)),
  676. (r'[\[\]{}()=]+', Operator),
  677. (r'<<\s*(\'?)\\?(\w+)[\w\W]+?\2', String),
  678. ],
  679. 'data': [
  680. (r'"(\\\\|\\[0-7]+|\\.|[^"])*"', String.Double),
  681. (r"'(\\\\|\\[0-7]+|\\.|[^'])*'", String.Single),
  682. (r'\s+', Text),
  683. (r'[^=\s\n\[\]{}()$"\'`\\]+', Text),
  684. (r'\d+(?= |\Z)', Number),
  685. (r'\$#?(\w+|.)', Name.Variable),
  686. ],
  687. 'curly': [
  688. (r'}', Keyword, '#pop'),
  689. (r':-', Keyword),
  690. (r'[a-zA-Z0-9_]+', Name.Variable),
  691. (r'[^}:"\'`$]+', Punctuation),
  692. (r':', Punctuation),
  693. include('root'),
  694. ],
  695. 'paren': [
  696. (r'\)', Keyword, '#pop'),
  697. include('root'),
  698. ],
  699. 'backticks': [
  700. (r'`', String.Backtick, '#pop'),
  701. include('root'),
  702. ],
  703. }
  704. class LogtalkLexer(RegexLexer):
  705. """
  706. For `Logtalk <http://logtalk.org/>`_ source code.
  707. *New in Pygments 0.10.*
  708. """
  709. name = 'Logtalk'
  710. aliases = ['logtalk']
  711. filenames = ['*.lgt']
  712. mimetypes = ['text/x-logtalk']
  713. tokens = {
  714. 'root': [
  715. # Directives
  716. (r'^\s*:-\s',Punctuation,'directive'),
  717. # Comments
  718. (r'%.*?\n', Comment),
  719. (r'/\*(.|\n)*?\*/',Comment),
  720. # Whitespace
  721. (r'\n', Text),
  722. (r'\s+', Text),
  723. # Numbers
  724. (r"0'.", Number),
  725. (r'0b[01]+', Number),
  726. (r'0o[0-7]+', Number),
  727. (r'0x[0-9a-fA-F]+', Number),
  728. (r'\d+\.?\d*((e|E)(\+|-)?\d+)?', Number),
  729. # Variables
  730. (r'([A-Z_][a-zA-Z0-9_]*)', Name.Variable),
  731. # Event handlers
  732. (r'(after|before)(?=[(])', Keyword),
  733. # Execution-context methods
  734. (r'(parameter|this|se(lf|nder))(?=[(])', Keyword),
  735. # Reflection
  736. (r'(current_predicate|predicate_property)(?=[(])', Keyword),
  737. # DCGs and term expansion
  738. (r'(expand_term|(goal|term)_expansion|phrase)(?=[(])', Keyword),
  739. # Entity
  740. (r'(abolish|c(reate|urrent))_(object|protocol|category)(?=[(])',
  741. Keyword),
  742. (r'(object|protocol|category)_property(?=[(])', Keyword),
  743. # Entity relations
  744. (r'complements_object(?=[(])', Keyword),
  745. (r'extends_(object|protocol|category)(?=[(])', Keyword),
  746. (r'imp(lements_protocol|orts_category)(?=[(])', Keyword),
  747. (r'(instantiat|specializ)es_class(?=[(])', Keyword),
  748. # Events
  749. (r'(current_event|(abolish|define)_events)(?=[(])', Keyword),
  750. # Flags
  751. (r'(current|set)_logtalk_flag(?=[(])', Keyword),
  752. # Compiling, loading, and library paths
  753. (r'logtalk_(compile|l(ibrary_path|oad))(?=[(])', Keyword),
  754. # Database
  755. (r'(clause|retract(all)?)(?=[(])', Keyword),
  756. (r'a(bolish|ssert(a|z))(?=[(])', Keyword),
  757. # Control
  758. (r'(ca(ll|tch)|throw)(?=[(])', Keyword),
  759. (r'(fail|true)\b', Keyword),
  760. # All solutions
  761. (r'((bag|set)of|f(ind|or)all)(?=[(])', Keyword),
  762. # Multi-threading meta-predicates
  763. (r'threaded(_(call|once|ignore|exit|peek|wait|notify))?(?=[(])',
  764. Keyword),
  765. # Term unification
  766. (r'unify_with_occurs_check(?=[(])', Keyword),
  767. # Term creation and decomposition
  768. (r'(functor|arg|copy_term)(?=[(])', Keyword),
  769. # Evaluable functors
  770. (r'(rem|mod|abs|sign)(?=[(])', Keyword),
  771. (r'float(_(integer|fractional)_part)?(?=[(])', Keyword),
  772. (r'(floor|truncate|round|ceiling)(?=[(])', Keyword),
  773. # Other arithmetic functors
  774. (r'(cos|atan|exp|log|s(in|qrt))(?=[(])', Keyword),
  775. # Term testing
  776. (r'(var|atom(ic)?|integer|float|compound|n(onvar|umber))(?=[(])',
  777. Keyword),
  778. # Stream selection and control
  779. (r'(curren|se)t_(in|out)put(?=[(])', Keyword),
  780. (r'(open|close)(?=[(])', Keyword),
  781. (r'flush_output(?=[(])', Keyword),
  782. (r'(at_end_of_stream|flush_output)\b', Keyword),
  783. (r'(stream_property|at_end_of_stream|set_stream_position)(?=[(])',
  784. Keyword),
  785. # Character and byte input/output
  786. (r'(nl|(get|peek|put)_(byte|c(har|ode)))(?=[(])', Keyword),
  787. (r'\bnl\b', Keyword),
  788. # Term input/output
  789. (r'read(_term)?(?=[(])', Keyword),
  790. (r'write(q|_(canonical|term))?(?=[(])', Keyword),
  791. (r'(current_)?op(?=[(])', Keyword),
  792. (r'(current_)?char_conversion(?=[(])', Keyword),
  793. # Atomic term processing
  794. (r'atom_(length|c(hars|o(ncat|des)))(?=[(])', Keyword),
  795. (r'(char_code|sub_atom)(?=[(])', Keyword),
  796. (r'number_c(har|ode)s(?=[(])', Keyword),
  797. # Implementation defined hooks functions
  798. (r'(se|curren)t_prolog_flag(?=[(])', Keyword),
  799. (r'\bhalt\b', Keyword),
  800. (r'halt(?=[(])', Keyword),
  801. # Message sending operators
  802. (r'(::|:|\^\^)', Operator),
  803. # External call
  804. (r'[{}]', Keyword),
  805. # Logic and control
  806. (r'\bonce(?=[(])', Keyword),
  807. (r'\brepeat\b', Keyword),
  808. # Bitwise functors
  809. (r'(>>|<<|/\\|\\\\|\\)', Operator),
  810. # Arithemtic evaluation
  811. (r'\bis\b', Keyword),
  812. # Arithemtic comparison
  813. (r'(=:=|=\\=|<|=<|>=|>)', Operator),
  814. # Term creation and decomposition
  815. (r'=\.\.', Operator),
  816. # Term unification
  817. (r'(=|\\=)', Operator),
  818. # Term comparison
  819. (r'(==|\\==|@=<|@<|@>=|@>)', Operator),
  820. # Evaluable functors
  821. (r'(//|[-+*/])', Operator),
  822. (r'\b(mod|rem)\b', Operator),
  823. # Other arithemtic functors
  824. (r'\b\*\*\b', Operator),
  825. # DCG rules
  826. (r'-->', Operator),
  827. # Control constructs
  828. (r'([!;]|->)', Operator),
  829. # Logic and control
  830. (r'\\+', Operator),
  831. # Mode operators
  832. (r'[?@]', Operator),
  833. # Strings
  834. (r'"(\\\\|\\"|[^"])*"', String),
  835. # Ponctuation
  836. (r'[()\[\],.|]', Text),
  837. # Atoms
  838. (r"[a-z][a-zA-Z0-9_]*", Text),
  839. (r"[']", String, 'quoted_atom'),
  840. ],
  841. 'quoted_atom': [
  842. (r"['][']", String),
  843. (r"[']", String, '#pop'),
  844. (r'\\([\\abfnrtv"\']|(x[a-fA-F0-9]+|[0-7]+)\\)', String.Escape),
  845. (r"[^\\'\n]+", String),
  846. (r'\\', String),
  847. ],
  848. 'directive': [
  849. # Entity directives
  850. (r'(category|object|protocol)(?=[(])', Keyword, 'entityrelations'),
  851. (r'(end_(category|object|protocol))[.]',Keyword, 'root'),
  852. # Predicate scope directives
  853. (r'(public|protected|private)(?=[(])', Keyword, 'root'),
  854. # Other directives
  855. (r'e(ncoding|xport)(?=[(])', Keyword, 'root'),
  856. (r'in(fo|itialization)(?=[(])', Keyword, 'root'),
  857. (r'(dynamic|synchronized|threaded)[.]', Keyword, 'root'),
  858. (r'(alias|d(ynamic|iscontiguous)|m(eta_predicate|ode|ultifile)'
  859. r'|synchronized)(?=[(])', Keyword, 'root'),
  860. (r'op(?=[(])', Keyword, 'root'),
  861. (r'(calls|use(s|_module))(?=[(])', Keyword, 'root'),
  862. (r'[a-z][a-zA-Z0-9_]*(?=[(])', Text, 'root'),
  863. (r'[a-z][a-zA-Z0-9_]*[.]', Text, 'root'),
  864. ],
  865. 'entityrelations': [
  866. (r'(extends|i(nstantiates|mp(lements|orts))|specializes)(?=[(])',
  867. Keyword),
  868. # Numbers
  869. (r"0'.", Number),
  870. (r'0b[01]+', Number),
  871. (r'0o[0-7]+', Number),
  872. (r'0x[0-9a-fA-F]+', Number),
  873. (r'\d+\.?\d*((e|E)(\+|-)?\d+)?', Number),
  874. # Variables
  875. (r'([A-Z_][a-zA-Z0-9_]*)', Name.Variable),
  876. # Atoms
  877. (r"[a-z][a-zA-Z0-9_]*", Text),
  878. (r"[']", String, 'quoted_atom'),
  879. # Strings
  880. (r'"(\\\\|\\"|[^"])*"', String),
  881. # End of entity-opening directive
  882. (r'([)]\.)', Text, 'root'),
  883. # Scope operator
  884. (r'(::)', Operator),
  885. # Ponctuation
  886. (r'[()\[\],.|]', Text),
  887. # Comments
  888. (r'%.*?\n', Comment),
  889. (r'/\*(.|\n)*?\*/',Comment),
  890. # Whitespace
  891. (r'\n', Text),
  892. (r'\s+', Text),
  893. ]
  894. }
  895. def _shortened(word):
  896. dpos = word.find('$')
  897. return '|'.join([word[:dpos] + word[dpos+1:i] + r'\b'
  898. for i in range(len(word), dpos, -1)])
  899. def _shortened_many(*words):
  900. return '|'.join(map(_shortened, words))
  901. class GnuplotLexer(RegexLexer):
  902. """
  903. For `Gnuplot <http://gnuplot.info/>`_ plotting scripts.
  904. *New in Pygments 0.11.*
  905. """
  906. name = 'Gnuplot'
  907. aliases = ['gnuplot']
  908. filenames = ['*.plot', '*.plt']
  909. mimetypes = ['text/x-gnuplot']
  910. tokens = {
  911. 'root': [
  912. include('whitespace'),
  913. (_shortened('bi$nd'), Keyword, 'bind'),
  914. (_shortened_many('ex$it', 'q$uit'), Keyword, 'quit'),
  915. (_shortened('f$it'), Keyword, 'fit'),
  916. (r'(if)(\s*)(\()', bygroups(Keyword, Text, Punctuation), 'if'),
  917. (r'else\b', Keyword),
  918. (_shortened('pa$use'), Keyword, 'pause'),
  919. (_shortened_many('p$lot', 'rep$lot', 'sp$lot'), Keyword, 'plot'),
  920. (_shortened('sa$ve'), Keyword, 'save'),
  921. (_shortened('se$t'), Keyword, ('genericargs', 'optionarg')),
  922. (_shortened_many('sh$ow', 'uns$et'),
  923. Keyword, ('noargs', 'optionarg')),
  924. (_shortened_many('low$er', 'ra$ise', 'ca$ll', 'cd$', 'cl$ear',
  925. 'h$elp', '\\?$', 'hi$story', 'l$oad', 'pr$int',
  926. 'pwd$', 're$read', 'res$et', 'scr$eendump',
  927. 'she$ll', 'sy$stem', 'up$date'),
  928. Keyword, 'genericargs'),
  929. (_shortened_many('pwd$', 're$read', 'res$et', 'scr$eendump',
  930. 'she$ll', 'test$'),
  931. Keyword, 'noargs'),
  932. ('([a-zA-Z_][a-zA-Z0-9_]*)(\s*)(=)',
  933. bygroups(Name.Variable, Text, Operator), 'genericargs'),
  934. ('([a-zA-Z_][a-zA-Z0-9_]*)(\s*\(.*?\)\s*)(=)',
  935. bygroups(Name.Function, Text, Operator), 'genericargs'),
  936. (r'@[a-zA-Z_][a-zA-Z0-9_]*', Name.Constant), # macros
  937. (r';', Keyword),
  938. ],
  939. 'comment': [
  940. (r'[^\\\n]', Comment),
  941. (r'\\\n', Comment),
  942. (r'\\', Comment),
  943. # don't add the newline to the Comment token
  944. ('', Comment, '#pop'),
  945. ],
  946. 'whitespace': [
  947. ('#', Comment, 'comment'),
  948. (r'[ \t\v\f]+', Text),
  949. ],
  950. 'noargs': [
  951. include('whitespace'),
  952. # semicolon and newline end the argument list
  953. (r';', Punctuation, '#pop'),
  954. (r'\n', Text, '#pop'),
  955. ],
  956. 'dqstring': [
  957. (r'"', String, '#pop'),
  958. (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
  959. (r'[^\\"\n]+', String), # all other characters
  960. (r'\\\n', String), # line continuation
  961. (r'\\', String), # stray backslash
  962. (r'\n', String, '#pop'), # newline ends the string too
  963. ],
  964. 'sqstring': [
  965. (r"''", String), # escaped single quote
  966. (r"'", String, '#pop'),
  967. (r"[^\\'\n]+", String), # all other characters
  968. (r'\\\n', String), # line continuation
  969. (r'\\', String), # normal backslash
  970. (r'\n', String, '#pop'), # newline ends the string too
  971. ],
  972. 'genericargs': [
  973. include('noargs'),
  974. (r'"', String, 'dqstring'),
  975. (r"'", String, 'sqstring'),
  976. (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+', Number.Float),
  977. (r'(\d+\.\d*|\.\d+)', Number.Float),
  978. (r'-?\d+', Number.Integer),
  979. ('[,.~!%^&*+=|?:<>/-]', Operator),
  980. ('[{}()\[\]]', Punctuation),
  981. (r'(eq|ne)\b', Operator.Word),
  982. (r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*)(\()',
  983. bygroups(Name.Function, Text, Punctuation)),
  984. (r'[a-zA-Z_][a-zA-Z0-9_]*', Name),
  985. (r'@[a-zA-Z_][a-zA-Z0-9_]*', Name.Constant), # macros
  986. (r'\\\n', Text),
  987. ],
  988. 'optionarg': [
  989. include('whitespace'),
  990. (_shortened_many(
  991. "a$ll","an$gles","ar$row","au$toscale","b$ars","bor$der",
  992. "box$width","cl$abel","c$lip","cn$trparam","co$ntour","da$ta",
  993. "data$file","dg$rid3d","du$mmy","enc$oding","dec$imalsign",
  994. "fit$","font$path","fo$rmat","fu$nction","fu$nctions","g$rid",
  995. "hid$den3d","his$torysize","is$osamples","k$ey","keyt$itle",
  996. "la$bel","li$nestyle","ls$","loa$dpath","loc$ale","log$scale",
  997. "mac$ros","map$ping","map$ping3d","mar$gin","lmar$gin",
  998. "rmar$gin","tmar$gin","bmar$gin","mo$use","multi$plot",
  999. "mxt$ics","nomxt$ics","mx2t$ics","nomx2t$ics","myt$ics",
  1000. "nomyt$ics","my2t$ics","nomy2t$ics","mzt$ics","nomzt$ics",
  1001. "mcbt$ics","nomcbt$ics","of$fsets","or$igin","o$utput",
  1002. "pa$rametric","pm$3d","pal$ette","colorb$ox","p$lot",
  1003. "poi$ntsize","pol$ar","pr$int","obj$ect","sa$mples","si$ze",
  1004. "st$yle","su$rface","table$","t$erminal","termo$ptions","ti$cs",
  1005. "ticsc$ale","ticsl$evel","timef$mt","tim$estamp","tit$le",
  1006. "v$ariables","ve$rsion","vi$ew","xyp$lane","xda$ta","x2da$ta",
  1007. "yda$ta","y2da$ta","zda$ta","cbda$ta","xl$abel","x2l$abel",
  1008. "yl$abel","y2l$abel","zl$abel","cbl$abel","xti$cs","noxti$cs",
  1009. "x2ti$cs","nox2ti$cs","yti$cs","noyti$cs","y2ti$cs","noy2ti$cs",
  1010. "zti$cs","nozti$cs","cbti$cs","nocbti$cs","xdti$cs","noxdti$cs",
  1011. "x2dti$cs","nox2dti$cs","ydti$cs","noydti$cs","y2dti$cs",
  1012. "noy2dti$cs","zdti$cs","nozdti$cs","cbdti$cs","nocbdti$cs",
  1013. "xmti$cs","noxmti$cs","x2mti$cs","nox2mti$cs","ymti$cs",
  1014. "noymti$cs","y2mti$cs","noy2mti$cs","zmti$cs","nozmti$cs",
  1015. "cbmti$cs","nocbmti$cs","xr$ange","x2r$ange","yr$ange",
  1016. "y2r$ange","zr$ange","cbr$ange","rr$ange","tr$ange","ur$ange",
  1017. "vr$ange","xzeroa$xis","x2zeroa$xis","yzeroa$xis","y2zeroa$xis",
  1018. "zzeroa$xis","zeroa$xis","z$ero"), Name.Builtin, '#pop'),
  1019. ],
  1020. 'bind': [
  1021. ('!', Keyword, '#pop'),
  1022. (_shortened('all$windows'), Name.Builtin),
  1023. include('genericargs'),
  1024. ],
  1025. 'quit': [
  1026. (r'gnuplot\b', Keyword),
  1027. include('noargs'),
  1028. ],
  1029. 'fit': [
  1030. (r'via\b', Name.Builtin),
  1031. include('plot'),
  1032. ],
  1033. 'if': [
  1034. (r'\)', Punctuation, '#pop'),
  1035. include('genericargs'),
  1036. ],
  1037. 'pause': [
  1038. (r'(mouse|any|button1|button2|button3)\b', Name.Builtin),
  1039. (_shortened('key$press'), Name.Builtin),
  1040. include('genericargs'),
  1041. ],
  1042. 'plot': [
  1043. (_shortened_many('ax$es', 'axi$s', 'bin$ary', 'ev$ery', 'i$ndex',
  1044. 'mat$rix', 's$mooth', 'thru$', 't$itle',
  1045. 'not$itle', 'u$sing', 'w$ith'),
  1046. Name.Builtin),
  1047. include('genericargs'),
  1048. ],
  1049. 'save': [
  1050. (_shortened_many('f$unctions', 's$et', 't$erminal', 'v$ariables'),
  1051. Name.Builtin),
  1052. include('genericargs'),
  1053. ],
  1054. }
  1055. class PovrayLexer(RegexLexer):
  1056. """
  1057. For `Persistence of Vision Raytracer <http://www.povray.org/>`_ files.
  1058. *New in Pygments 0.11.*
  1059. """
  1060. name = 'POVRay'
  1061. aliases = ['pov']
  1062. filenames = ['*.pov', '*.inc']
  1063. mimetypes = ['text/x-povray']
  1064. tokens = {
  1065. 'root': [
  1066. (r'/\*[\w\W]*?\*/', Comment.Multiline),
  1067. (r'//.*\n', Comment.Single),
  1068. (r'"(?:\\.|[^"])+"', String.Double),
  1069. (r'#(debug|default|else|end|error|fclose|fopen|if|ifdef|ifndef|'
  1070. r'include|range|read|render|statistics|switch|undef|version|'
  1071. r'warning|while|write|define|macro|local|declare)',
  1072. Comment.Preproc),
  1073. (r'\b(aa_level|aa_threshold|abs|acos|acosh|adaptive|adc_bailout|'
  1074. r'agate|agate_turb|all|alpha|ambient|ambient_light|angle|'
  1075. r'aperture|arc_angle|area_light|asc|asin|asinh|assumed_gamma|'
  1076. r'atan|atan2|atanh|atmosphere|atmospheric_attenuation|'
  1077. r'attenuating|average|background|black_hole|blue|blur_samples|'
  1078. r'bounded_by|box_mapping|bozo|break|brick|brick_size|'
  1079. r'brightness|brilliance|bumps|bumpy1|bumpy2|bumpy3|bump_map|'
  1080. r'bump_size|case|caustics|ceil|checker|chr|clipped_by|clock|'
  1081. r'color|color_map|colour|colour_map|component|composite|concat|'
  1082. r'confidence|conic_sweep|constant|control0|control1|cos|cosh|'
  1083. r'count|crackle|crand|cube|cubic_spline|cylindrical_mapping|'
  1084. r'debug|declare|default|degrees|dents|diffuse|direction|'
  1085. r'distance|distance_maximum|div|dust|dust_type|eccentricity|'
  1086. r'else|emitting|end|error|error_bound|exp|exponent|'
  1087. r'fade_distance|fade_power|falloff|falloff_angle|false|'
  1088. r'file_exists|filter|finish|fisheye|flatness|flip|floor|'
  1089. r'focal_point|fog|fog_alt|fog_offset|fog_type|frequency|gif|'
  1090. r'global_settings|glowing|gradient|granite|gray_threshold|'
  1091. r'green|halo|hexagon|hf_gray_16|hierarchy|hollow|hypercomplex|'
  1092. r'if|ifdef|iff|image_map|incidence|include|int|interpolate|'
  1093. r'inverse|ior|irid|irid_wavelength|jitter|lambda|leopard|'
  1094. r'linear|linear_spline|linear_sweep|location|log|looks_like|'
  1095. r'look_at|low_error_factor|mandel|map_type|marble|material_map|'
  1096. r'matrix|max|max_intersections|max_iteration|max_trace_level|'
  1097. r'max_value|metallic|min|minimum_reuse|mod|mortar|'
  1098. r'nearest_count|no|normal|normal_map|no_shadow|number_of_waves|'
  1099. r'octaves|off|offset|omega|omnimax|on|once|onion|open|'
  1100. r'orthographic|panoramic|pattern1|pattern2|pattern3|'
  1101. r'perspective|pgm|phase|phong|phong_size|pi|pigment|'
  1102. r'pigment_map|planar_mapping|png|point_at|pot|pow|ppm|'
  1103. r'precision|pwr|quadratic_spline|quaternion|quick_color|'
  1104. r'quick_colour|quilted|radial|radians|radiosity|radius|rainbow|'
  1105. r'ramp_wave|rand|range|reciprocal|recursion_limit|red|'
  1106. r'reflection|refraction|render|repeat|rgb|rgbf|rgbft|rgbt|'
  1107. r'right|ripples|rotate|roughness|samples|scale|scallop_wave|'
  1108. r'scattering|seed|shadowless|sin|sine_wave|sinh|sky|sky_sphere|'
  1109. r'slice|slope_map|smooth|specular|spherical_mapping|spiral|'
  1110. r'spiral1|spiral2|spotlight|spotted|sqr|sqrt|statistics|str|'
  1111. r'strcmp|strength|strlen|strlwr|strupr|sturm|substr|switch|sys|'
  1112. r't|tan|tanh|test_camera_1|test_camera_2|test_camera_3|'
  1113. r'test_camera_4|texture|texture_map|tga|thickness|threshold|'
  1114. r'tightness|tile2|tiles|track|transform|translate|transmit|'
  1115. r'triangle_wave|true|ttf|turbulence|turb_depth|type|'
  1116. r'ultra_wide_angle|up|use_color|use_colour|use_index|u_steps|'
  1117. r'val|variance|vaxis_rotate|vcross|vdot|version|vlength|'
  1118. r

Large files files are truncated, but you can click here to view the full file