diff options
Diffstat (limited to 'pygments/lexers/compiled.py')
-rw-r--r-- | pygments/lexers/compiled.py | 319 |
1 files changed, 313 insertions, 6 deletions
diff --git a/pygments/lexers/compiled.py b/pygments/lexers/compiled.py index 5c10a785..6c9d7c87 100644 --- a/pygments/lexers/compiled.py +++ b/pygments/lexers/compiled.py @@ -22,11 +22,11 @@ from pygments.token import \ # backwards compatibility from pygments.lexers.functional import OcamlLexer -__all__ = ['CLexer', 'CppLexer', 'DLexer', 'DelphiLexer', 'JavaLexer', +__all__ = ['CLexer', 'CppLexer', 'DLexer', 'DelphiLexer', 'ECLexer', 'JavaLexer', 'ScalaLexer', 'DylanLexer', 'OcamlLexer', 'ObjectiveCLexer', 'FortranLexer', 'GLShaderLexer', 'PrologLexer', 'CythonLexer', 'ValaLexer', 'OocLexer', 'GoLexer', 'FelixLexer', 'AdaLexer', - 'Modula2Lexer', 'BlitzMaxLexer'] + 'Modula2Lexer', 'BlitzMaxLexer', 'NimrodLexer'] class CLexer(RegexLexer): @@ -35,7 +35,7 @@ class CLexer(RegexLexer): """ name = 'C' aliases = ['c'] - filenames = ['*.c', '*.h'] + filenames = ['*.c', '*.h', '*.idc'] mimetypes = ['text/x-chdr', 'text/x-csrc'] #: optional Comment or Whitespace @@ -250,6 +250,156 @@ class CppLexer(RegexLexer): } +class ECLexer(RegexLexer): + """ + For eC source code with preprocessor directives. + + *New in Pygments 1.5.* + """ + name = 'eC' + aliases = ['ec'] + filenames = ['*.ec', '*.eh'] + mimetypes = ['text/x-echdr', 'text/x-ecsrc'] + + #: optional Comment or Whitespace + _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+' + + tokens = { + 'whitespace': [ + # preprocessor directives: without whitespace + ('^#if\s+0', Comment.Preproc, 'if0'), + ('^#', Comment.Preproc, 'macro'), + # or with whitespace + ('^' + _ws + r'#if\s+0', Comment.Preproc, 'if0'), + ('^' + _ws + '#', Comment.Preproc, 'macro'), + (r'^(\s*)([a-zA-Z_][a-zA-Z0-9_]*:(?!:))', bygroups(Text, Name.Label)), + (r'\n', Text), + (r'\s+', Text), + (r'\\\n', Text), # line continuation + (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single), + (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), + ], + 'statements': [ + (r'L?"', String, 'string'), + (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char), + (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*', Number.Float), + (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float), + (r'0x[0-9a-fA-F]+[LlUu]*', Number.Hex), + (r'0[0-7]+[LlUu]*', Number.Oct), + (r'\d+[LlUu]*', Number.Integer), + (r'\*/', Error), + (r'[~!%^&*+=|?:<>/-]', Operator), + (r'[()\[\],.]', Punctuation), + (r'\b(case)(.+?)(:)', bygroups(Keyword, using(this), Text)), + (r'(auto|break|case|const|continue|default|do|else|enum|extern|' + r'for|goto|if|register|restricted|return|sizeof|static|struct|' + r'switch|typedef|union|volatile|virtual|while|class|private|public|' + r'property|import|delete|new|new0|renew|renew0|define|get|set|remote|dllexport|dllimport|stdcall|' + r'subclass|__on_register_module|namespace|using|typed_object|any_object|incref|register|watch|' + r'stopwatching|firewatchers|watchable|class_designer|class_fixed|class_no_expansion|isset|' + r'class_default_property|property_category|class_data|class_property|virtual|thisclass|' + r'dbtable|dbindex|database_open|dbfield)\b', Keyword), + (r'(int|long|float|short|double|char|unsigned|signed|void)\b', + Keyword.Type), + (r'(uint|uint16|uint32|uint64|bool|byte|unichar|int64)\b', + Keyword.Type), + (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'), + (r'(_{0,2}inline|naked|restrict|thread|typename)\b', Keyword.Reserved), + (r'__(asm|int8|based|except|int16|stdcall|cdecl|fastcall|int32|' + r'declspec|finally|int64|try|leave)\b', Keyword.Reserved), + (r'(true|false|null|value|this|NULL)\b', Name.Builtin), + ('[a-zA-Z_][a-zA-Z0-9_]*', Name), + ], + 'root': [ + include('whitespace'), + # functions + (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments + r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name + r'(\s*\([^;]*?\))' # signature + r'(' + _ws + r')({)', + bygroups(using(this), Name.Function, using(this), using(this), + Punctuation), + 'function'), + # function declarations + (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments + r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name + r'(\s*\([^;]*?\))' # signature + r'(' + _ws + r')(;)', + bygroups(using(this), Name.Function, using(this), using(this), + Punctuation)), + ('', Text, 'statement'), + ], + 'classname': [ + (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop'), + # template specification + (r'\s*(?=>)', Text, '#pop'), + ], + 'statement' : [ + include('whitespace'), + include('statements'), + ('[{}]', Punctuation), + (';', Punctuation, '#pop'), + ], + 'function': [ + include('whitespace'), + include('statements'), + (';', Punctuation), + ('{', Punctuation, '#push'), + ('}', Punctuation, '#pop'), + ], + 'string': [ + (r'"', String, '#pop'), + (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape), + (r'[^\\"\n]+', String), # all other characters + (r'\\\n', String), # line continuation + (r'\\', String), # stray backslash + ], + 'macro': [ + (r'[^/\n]+', Comment.Preproc), + (r'/[*](.|\n)*?[*]/', Comment.Multiline), + (r'//.*?\n', Comment.Single, '#pop'), + (r'/', Comment.Preproc), + (r'(?<=\\)\n', Comment.Preproc), + (r'\n', Comment.Preproc, '#pop'), + ], + 'if0': [ + (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'), + (r'^\s*#el(?:se|if).*\n', Comment.Preproc, '#pop'), + (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'), + (r'.*?\n', Comment), + ] + } + + stdlib_types = ['size_t', 'ssize_t', 'off_t', 'wchar_t', 'ptrdiff_t', + 'sig_atomic_t', 'fpos_t', 'clock_t', 'time_t', 'va_list', + 'jmp_buf', 'FILE', 'DIR', 'div_t', 'ldiv_t', 'mbstate_t', + 'wctrans_t', 'wint_t', 'wctype_t'] + c99_types = ['_Bool', '_Complex', 'int8_t', 'int16_t', 'int32_t', 'int64_t', + 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', 'int_least8_t', + 'int_least16_t', 'int_least32_t', 'int_least64_t', + 'uint_least8_t', 'uint_least16_t', 'uint_least32_t', + 'uint_least64_t', 'int_fast8_t', 'int_fast16_t', 'int_fast32_t', + 'int_fast64_t', 'uint_fast8_t', 'uint_fast16_t', 'uint_fast32_t', + 'uint_fast64_t', 'intptr_t', 'uintptr_t', 'intmax_t', 'uintmax_t'] + + def __init__(self, **options): + self.stdlibhighlighting = get_bool_opt(options, + 'stdlibhighlighting', True) + self.c99highlighting = get_bool_opt(options, + 'c99highlighting', True) + RegexLexer.__init__(self, **options) + + def get_tokens_unprocessed(self, text): + for index, token, value in \ + RegexLexer.get_tokens_unprocessed(self, text): + if token is Name: + if self.stdlibhighlighting and value in self.stdlib_types: + token = Keyword.Type + elif self.c99highlighting and value in self.c99_types: + token = Keyword.Type + yield index, token, value + + class DLexer(RegexLexer): """ For D source. @@ -986,7 +1136,7 @@ class ScalaLexer(RegexLexer): (r'(true|false|null)\b', Keyword.Constant), (r'(import|package)(\s+)', bygroups(Keyword, Text), 'import'), (r'(type)(\s+)', bygroups(Keyword, Text), 'type'), - (r'"""(?:.|\n)*?"""', String), + (r'""".*?"""', String), (r'"(\\\\|\\"|[^"])*"', String), (ur"'\\.'|'[^\\]'|'\\u[0-9a-f]{4}'", String.Char), # (ur'(\.)(%s|%s|`[^`]+`)' % (idrest, op), bygroups(Operator, @@ -994,7 +1144,7 @@ class ScalaLexer(RegexLexer): (idrest, Name), (r'`[^`]+`', Name), (r'\[', Operator, 'typeparam'), - (r'[\(\)\{\};,.]', Operator), + (r'[\(\)\{\};,.#]', Operator), (op, Operator), (ur'([0-9][0-9]*\.[0-9]*|\.[0-9]+)([eE][+-]?[0-9]+)?[fFdD]?', Number.Float), @@ -1159,6 +1309,13 @@ class ObjectiveCLexer(RegexLexer): bygroups(using(this), Name.Function, using(this), Text, Punctuation), 'function'), + # methods + (r'^([-+])(\s*)' # method marker + r'(\(.*?\))?(\s*)' # return type + r'([a-zA-Z$_][a-zA-Z0-9$_]*:?)', # begin of method name + bygroups(Keyword, Text, using(this), + Text, Name.Function), + 'method'), # function declarations (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments r'([a-zA-Z$_][a-zA-Z0-9$_]*)' # method name @@ -1202,6 +1359,15 @@ class ObjectiveCLexer(RegexLexer): ('{', Punctuation, '#push'), ('}', Punctuation, '#pop'), ], + 'method': [ + include('whitespace'), + (r'(\(.*?\))([a-zA-Z$_][a-zA-Z0-9$_]*)', bygroups(using(this), + Name.Variable)), + (r'[a-zA-Z$_][a-zA-Z0-9$_]*:', Name.Function), + (';', Punctuation, '#pop'), + ('{', Punctuation, 'function'), + ('', Text, '#pop'), + ], 'string': [ (r'"', String, '#pop'), (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape), @@ -1239,7 +1405,7 @@ class FortranLexer(RegexLexer): ''' name = 'Fortran' aliases = ['fortran'] - filenames = ['*.f', '*.f90'] + filenames = ['*.f', '*.f90', '*.F', '*.F90'] mimetypes = ['text/x-fortran'] flags = re.IGNORECASE @@ -2480,3 +2646,144 @@ class BlitzMaxLexer(RegexLexer): (r'[^"]+', String.Double), ], } + + +class NimrodLexer(RegexLexer): + """ + For `Nimrod <http://nimrod-code.org/>`_ source code. + + *New in Pygments 1.5.* + """ + + name = 'Nimrod' + aliases = ['nimrod', 'nim'] + filenames = ['*.nim', '*.nimrod'] + mimetypes = ['text/x-nimrod'] + + flags = re.MULTILINE | re.IGNORECASE | re.UNICODE + + def underscorize(words): + newWords = [] + new = "" + for word in words: + for ch in word: + new += (ch + "_?") + newWords.append(new) + new = "" + return "|".join(newWords) + + keywords = [ + 'addr', 'and', 'as', 'asm', 'atomic', 'bind', 'block', 'break', + 'case', 'cast', 'const', 'continue', 'converter', 'discard', + 'distinct', 'div', 'elif', 'else', 'end', 'enum', 'except', 'finally', + 'for', 'generic', 'if', 'implies', 'in', 'yield', + 'is', 'isnot', 'iterator', 'lambda', 'let', 'macro', 'method', + 'mod', 'not', 'notin', 'object', 'of', 'or', 'out', 'proc', + 'ptr', 'raise', 'ref', 'return', 'shl', 'shr', 'template', 'try', + 'tuple', 'type' , 'when', 'while', 'with', 'without', 'xor' + ] + + keywordsPseudo = [ + 'nil', 'true', 'false' + ] + + opWords = [ + 'and', 'or', 'not', 'xor', 'shl', 'shr', 'div', 'mod', 'in', + 'notin', 'is', 'isnot' + ] + + types = [ + 'int', 'int8', 'int16', 'int32', 'int64', 'float', 'float32', 'float64', + 'bool', 'char', 'range', 'array', 'seq', 'set', 'string' + ] + + tokens = { + 'root': [ + (r'##.*$', String.Doc), + (r'#.*$', Comment), + (r'\*|=|>|<|\+|-|/|@|\$|~|&|%|\!|\?|\||\\|\[|\]', Operator), + (r'\.\.|\.|,|[\.|\.]|{\.|\.}|\(\.|\.\)|{|}|\(|\)|:|\^|`|;', + Punctuation), + + # Strings + (r'(?:[\w]+)"', String, 'rdqs'), + (r'"""', String, 'tdqs'), + ('"', String, 'dqs'), + + # Char + ("'", String.Char, 'chars'), + + # Keywords + (r'(%s)\b' % underscorize(opWords), Operator.Word), + (r'(p_?r_?o_?c_?\s)(?![\(\[\]])', Keyword, 'funcname'), + (r'(%s)\b' % underscorize(keywords), Keyword), + (r'(%s)\b' % underscorize(['from', 'import', 'include']), + Keyword.Namespace), + (r'(v_?a_?r)\b', Keyword.Declaration), + (r'(%s)\b' % underscorize(types), Keyword.Type), + (r'(%s)\b' % underscorize(keywordsPseudo), Keyword.Pseudo), + # Identifiers + (r'\b((?![_\d])\w)(((?!_)\w)|(_(?!_)\w))*', Name), + # Numbers + (r'[0-9][0-9_]*(?=([eE.]|\'[fF](32|64)))', + Number.Float, ('float-suffix', 'float-number')), + (r'0[xX][a-fA-F0-9][a-fA-F0-9_]*', Number.Hex, 'int-suffix'), + (r'0[bB][01][01_]*', Number, 'int-suffix'), + (r'0o[0-7][0-7_]*', Number.Oct, 'int-suffix'), + (r'[0-9][0-9_]*', Number.Integer, 'int-suffix'), + # Whitespace + (r'\s+', Text), + (r'.+$', Error), + ], + 'chars': [ + (r'\\([\\abcefnrtvl"\']|x[a-fA-F0-9]{2}|[0-9]{1,3})', String.Escape), + (r"'", String.Char, '#pop'), + (r".", String.Char) + ], + 'strings': [ + (r'(?<!\$)\$(\d+|#|\w+)+', String.Interpol), + (r'[^\\\'"\$\n]+', String), + # quotes, dollars and backslashes must be parsed one at a time + (r'[\'"\\]', String), + # unhandled string formatting sign + (r'\$', String) + # newlines are an error (use "nl" state) + ], + 'dqs': [ + (r'\\([\\abcefnrtvl"\']|\n|x[a-fA-F0-9]{2}|[0-9]{1,3})', + String.Escape), + (r'"', String, '#pop'), + include('strings') + ], + 'rdqs': [ + (r'"(?!")', String, '#pop'), + (r'""', String.Escape), + include('strings') + ], + 'tdqs': [ + (r'"""(?!")', String, '#pop'), + include('strings'), + include('nl') + ], + 'funcname': [ + (r'((?![\d_])\w)(((?!_)\w)|(_(?!_)\w))*', Name.Function, '#pop'), + (r'`.+`', Name.Function, '#pop') + ], + 'nl': [ + (r'\n', String) + ], + 'float-number': [ + (r'\.(?!\.)[0-9_]*', Number.Float), + (r'[eE][+-]?[0-9][0-9_]*', Number.Float), + (r'', Text, '#pop') + ], + 'float-suffix': [ + (r'\'[fF](32|64)', Number.Float), + (r'', Text, '#pop') + ], + 'int-suffix': [ + (r'\'[iI](32|64)', Number.Integer.Long), + (r'\'[iI](8|16)', Number.Integer), + (r'', Text, '#pop') + ], + } |