PageRenderTime 57ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/env/Lib/site-packages/wx-2.8-msw-unicode/wx/tools/Editra/src/extern/pygments/lexers/other.py

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