1790
1790
(r'[a-zA-Z_]\w*', Name),
1795
class FelixLexer(RegexLexer):
1797
For `Felix <http://www.felix-lang.org>`_ source code.
1799
*New in Pygments 1.2.*
1803
aliases = ['felix', 'flx']
1804
filenames = ['*.flx', '*.flxh']
1805
mimetypes = ['text/x-felix']
1808
'elif', 'else', 'endif', 'if', 'ifdef', 'ifndef',
1812
'_', '_deref', 'all', 'as',
1813
'assert', 'attempt', 'call', 'callback', 'case', 'caseno', 'cclass',
1814
'code', 'compound', 'ctypes', 'do', 'done', 'downto', 'elif', 'else',
1815
'endattempt', 'endcase', 'endif', 'endmatch', 'enum', 'except',
1816
'exceptions', 'expect', 'finally', 'for', 'forall', 'forget', 'fork',
1817
'functor', 'goto', 'ident', 'if', 'incomplete', 'inherit', 'instance',
1818
'interface', 'jump', 'lambda', 'loop', 'match', 'module', 'namespace',
1819
'new', 'noexpand', 'nonterm', 'obj', 'of', 'open', 'parse', 'raise',
1820
'regexp', 'reglex', 'regmatch', 'rename', 'return', 'the', 'then',
1821
'to', 'type', 'typecase', 'typedef', 'typematch', 'typeof', 'upto',
1822
'when', 'whilst', 'with', 'yield',
1825
keyword_directives = [
1826
'_gc_pointer', '_gc_type', 'body', 'comment', 'const', 'export',
1827
'header', 'inline', 'lval', 'macro', 'noinline', 'noreturn',
1828
'package', 'private', 'pod', 'property', 'public', 'publish',
1829
'requires', 'todo', 'virtual', 'use',
1832
keyword_declarations = [
1833
'def', 'let', 'ref', 'val', 'var',
1837
'unit', 'void', 'any', 'bool',
1839
'address', 'caddress', 'cvaddress', 'vaddress',
1840
'tiny', 'short', 'int', 'long', 'vlong',
1841
'utiny', 'ushort', 'vshort', 'uint', 'ulong', 'uvlong',
1842
'int8', 'int16', 'int32', 'int64',
1843
'uint8', 'uint16', 'uint32', 'uint64',
1844
'float', 'double', 'ldouble',
1845
'complex', 'dcomplex', 'lcomplex',
1846
'imaginary', 'dimaginary', 'limaginary',
1847
'char', 'wchar', 'uchar',
1848
'charp', 'charcp', 'ucharp', 'ucharcp',
1849
'string', 'wstring', 'ustring',
1851
'array', 'varray', 'list',
1852
'lvalue', 'opt', 'slice',
1855
keyword_constants = [
1860
'and', 'not', 'in', 'is', 'isin', 'or', 'xor',
1868
'root', 'self', 'this',
1871
decimal_suffixes = '([tTsSiIlLvV]|ll|LL|([iIuU])(8|16|32|64))?'
1875
include('whitespace'),
1878
(r'(axiom|ctor|fun|gen|proc|reduce|union)\b', Keyword,
1880
(r'(class|cclass|cstruct|obj|struct)\b', Keyword, 'classname'),
1881
(r'(instance|module|typeclass)\b', Keyword, 'modulename'),
1883
(r'(%s)\b' % '|'.join(keywords), Keyword),
1884
(r'(%s)\b' % '|'.join(keyword_directives), Name.Decorator),
1885
(r'(%s)\b' % '|'.join(keyword_declarations), Keyword.Declaration),
1886
(r'(%s)\b' % '|'.join(keyword_types), Keyword.Type),
1887
(r'(%s)\b' % '|'.join(keyword_constants), Keyword.Constant),
1890
include('operators'),
1894
(r'0[xX]([0-9a-fA-F_]*\.[0-9a-fA-F_]+|[0-9a-fA-F_]+)'
1895
r'[pP][+\-]?[0-9_]+[lLfFdD]?', Number.Float),
1897
(r'[0-9_]+(\.[0-9_]+[eE][+\-]?[0-9_]+|'
1898
r'\.[0-9_]*|[eE][+\-]?[0-9_]+)[lLfFdD]?', Number.Float),
1899
(r'\.(0|[1-9][0-9_]*)([eE][+\-]?[0-9_]+)?[lLfFdD]?',
1904
(r'0[Bb][01_]+%s' % decimal_suffixes, Number),
1906
(r'0[0-7_]+%s' % decimal_suffixes, Number.Oct),
1908
(r'0[xX][0-9a-fA-F_]+%s' % decimal_suffixes, Number.Hex),
1910
(r'(0|[1-9][0-9_]*)%s' % decimal_suffixes, Number.Integer),
1913
('([rR][cC]?|[cC][rR])"""', String, 'tdqs'),
1914
("([rR][cC]?|[cC][rR])'''", String, 'tsqs'),
1915
('([rR][cC]?|[cC][rR])"', String, 'dqs'),
1916
("([rR][cC]?|[cC][rR])'", String, 'sqs'),
1917
('[cCfFqQwWuU]?"""', String, combined('stringescape', 'tdqs')),
1918
("[cCfFqQwWuU]?'''", String, combined('stringescape', 'tsqs')),
1919
('[cCfFqQwWuU]?"', String, combined('stringescape', 'dqs')),
1920
("[cCfFqQwWuU]?'", String, combined('stringescape', 'sqs')),
1923
(r'[\[\]{}:(),;?]', Punctuation),
1926
(r'[a-zA-Z_]\w*:>', Name.Label),
1929
(r'(%s)\b' % '|'.join(name_builtins), Name.Builtin),
1930
(r'(%s)\b' % '|'.join(name_pseudo), Name.Builtin.Pseudo),
1931
(r'[a-zA-Z_]\w*', Name),
1940
(r'#\s*if\s+0', Comment.Preproc, 'if0'),
1941
(r'#', Comment.Preproc, 'macro'),
1944
(r'(%s)\b' % '|'.join(operator_words), Operator.Word),
1945
(r'!=|==|<<|>>|\|\||&&|[-~+/*%=<>&^|.$]', Operator),
1948
(r'//(.*?)\n', Comment.Single),
1949
(r'/[*]', Comment.Multiline, 'comment2'),
1952
(r'[^\/*]', Comment.Multiline),
1953
(r'/[*]', Comment.Multiline, '#push'),
1954
(r'[*]/', Comment.Multiline, '#pop'),
1955
(r'[\/*]', Comment.Multiline),
1958
(r'^\s*#if.*?(?<!\\)\n', Comment, '#push'),
1959
(r'^\s*#endif.*?(?<!\\)\n', Comment, '#pop'),
1960
(r'.*?\n', Comment),
1964
(r'(import|include)(\s+)(<[^>]*?>)',
1965
bygroups(Comment.Preproc, Text, String), '#pop'),
1966
(r'(import|include)(\s+)("[^"]*?")',
1967
bygroups(Comment.Preproc, Text, String), '#pop'),
1968
(r"(import|include)(\s+)('[^']*?')",
1969
bygroups(Comment.Preproc, Text, String), '#pop'),
1970
(r'[^/\n]+', Comment.Preproc),
1971
##(r'/[*](.|\n)*?[*]/', Comment),
1972
##(r'//.*?\n', Comment, '#pop'),
1973
(r'/', Comment.Preproc),
1974
(r'(?<=\\)\n', Comment.Preproc),
1975
(r'\n', Comment.Preproc, '#pop'),
1978
include('whitespace'),
1979
(r'[a-zA-Z_]\w*', Name.Function, '#pop'),
1980
# anonymous functions
1981
(r'(?=\()', Text, '#pop'),
1984
include('whitespace'),
1985
(r'[a-zA-Z_]\w*', Name.Class, '#pop'),
1987
(r'(?=\{)', Text, '#pop'),
1990
include('whitespace'),
1991
(r'\[', Punctuation, ('modulename2', 'tvarlist')),
1992
(r'', Error, 'modulename2'),
1995
include('whitespace'),
1996
(r'([a-zA-Z_]\w*)', Name.Namespace, '#pop:2'),
1999
include('whitespace'),
2000
include('operators'),
2001
(r'\[', Punctuation, '#push'),
2002
(r'\]', Punctuation, '#pop'),
2003
(r',', Punctuation),
2004
(r'(with|where)\b', Keyword),
2005
(r'[a-zA-Z_]\w*', Name),
2008
(r'\\([\\abfnrtv"\']|\n|N{.*?}|u[a-fA-F0-9]{4}|'
2009
r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape)
2012
(r'%(\([a-zA-Z0-9]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?'
2013
'[hlL]?[diouxXeEfFgGcrs%]', String.Interpol),
2014
(r'[^\\\'"%\n]+', String),
2015
# quotes, percents and backslashes must be parsed one at a time
2016
(r'[\'"\\]', String),
2017
# unhandled string formatting sign
2019
# newlines are an error (use "nl" state)
2025
(r'"', String, '#pop'),
2026
# included here again for raw strings
2027
(r'\\\\|\\"|\\\n', String.Escape),
2031
(r"'", String, '#pop'),
2032
# included here again for raw strings
2033
(r"\\\\|\\'|\\\n", String.Escape),
2037
(r'"""', String, '#pop'),
2042
(r"'''", String, '#pop'),
2049
class AdaLexer(RegexLexer):
2051
For Ada source code.
2053
*New in Pygments 1.3.*
2057
aliases = ['ada', 'ada95' 'ada2005']
2058
filenames = ['*.adb', '*.ads', '*.ada']
2059
mimetypes = ['text/x-ada']
2061
flags = re.MULTILINE | re.I # Ignore case
2063
_ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
2067
(r'[^\S\n]+', Text),
2068
(r'--.*?\n', Comment.Single),
2069
(r'[^\S\n]+', Text),
2070
(r'function|procedure|entry', Keyword.Declaration, 'subprogram'),
2071
(r'(subtype|type)(\s+)([a-z0-9_]+)',
2072
bygroups(Keyword.Declaration, Text, Keyword.Type), 'type_def'),
2073
(r'task|protected', Keyword.Declaration),
2074
(r'(subtype)(\s+)', bygroups(Keyword.Declaration, Text)),
2075
(r'(end)(\s+)', bygroups(Keyword.Reserved, Text), 'end'),
2076
(r'(pragma)(\s+)([a-zA-Z0-9_]+)', bygroups(Keyword.Reserved, Text,
2078
(r'(true|false|null)\b', Keyword.Constant),
2079
(r'(Byte|Character|Float|Integer|Long_Float|Long_Integer|'
2080
r'Long_Long_Float|Long_Long_Integer|Natural|Positive|Short_Float|'
2081
r'Short_Integer|Short_Short_Float|Short_Short_Integer|String|'
2082
r'Wide_String|Duration)\b', Keyword.Type),
2083
(r'(and(\s+then)?|in|mod|not|or(\s+else)|rem)\b', Operator.Word),
2084
(r'generic|private', Keyword.Declaration),
2085
(r'package', Keyword.Declaration, 'package'),
2086
(r'array\b', Keyword.Reserved, 'array_def'),
2087
(r'(with|use)(\s+)', bygroups(Keyword.Namespace, Text), 'import'),
2088
(r'([a-z0-9_]+)(\s*)(:)(\s*)(constant)',
2089
bygroups(Name.Constant, Text, Punctuation, Text,
2091
(r'<<[a-z0-9_]+>>', Name.Label),
2092
(r'([a-z0-9_]+)(\s*)(:)(\s*)(declare|begin|loop|for|while)',
2093
bygroups(Name.Label, Text, Punctuation, Text, Keyword.Reserved)),
2094
(r'\b(abort|abs|abstract|accept|access|aliased|all|array|at|begin|'
2095
r'body|case|constant|declare|delay|delta|digits|do|else|elsif|end|'
2096
r'entry|exception|exit|interface|for|goto|if|is|limited|loop|new|'
2097
r'null|of|or|others|out|overriding|pragma|protected|raise|range|'
2098
r'record|renames|requeue|return|reverse|select|separate|subtype|'
2099
r'synchronized|task|tagged|terminate|then|type|until|when|while|'
2102
(r'"[^"]*"', String),
2103
include('attribute'),
2105
(r"'[^']'", String.Character),
2106
(r'([a-z0-9_]+)(\s*|[(,])', bygroups(Name, using(this))),
2107
(r"(<>|=>|:=|[\(\)\|:;,.'])", Punctuation),
2108
(r'[*<>+=/&-]', Operator),
2112
(r'[0-9_]+#[0-9a-f]+#', Number.Hex),
2113
(r'[0-9_]+\.[0-9_]*', Number.Float),
2114
(r'[0-9_]+', Number.Integer),
2117
(r"(')([a-zA-Z0-9_]+)", bygroups(Punctuation, Name.Attribute)),
2120
(r'\(', Punctuation, ('#pop', 'formal_part')),
2121
(r';', Punctuation, '#pop'),
2122
(r'is\b', Keyword.Reserved, '#pop'),
2123
(r'"[^"]+"|[a-z0-9_]+', Name.Function),
2127
('(if|case|record|loop|select)', Keyword.Reserved),
2128
('"[^"]+"|[a-zA-Z0-9_]+', Name.Function),
2130
(';', Punctuation, '#pop'),
2133
(r';', Punctuation, '#pop'),
2134
(r'\(', Punctuation, 'formal_part'),
2135
(r'with|and|use', Keyword.Reserved),
2136
(r'array\b', Keyword.Reserved, ('#pop', 'array_def')),
2137
(r'record\b', Keyword.Reserved, ('formal_part')),
2141
(r';', Punctuation, '#pop'),
2142
(r'([a-z0-9_]+)(\s+)(range)', bygroups(Keyword.Type, Text,
2147
(r'[a-z0-9_.]+', Name.Namespace, '#pop'),
2150
(r'\)', Punctuation, '#pop'),
2151
(r'([a-z0-9_]+)(\s*)(,|:[^=])', bygroups(Name.Variable,
2152
Text, Punctuation)),
2153
(r'(in|not|null|out|access)\b', Keyword.Reserved),
2157
('body', Keyword.Declaration),
2158
('is\s+new|renames', Keyword.Reserved),
2159
('is', Keyword.Reserved, '#pop'),
2160
(';', Punctuation, '#pop'),
2161
('\(', Punctuation, 'package_instantiation'),
2162
('([a-zA-Z0-9_.]+)', Name.Class),
2165
'package_instantiation': [
2166
(r'("[^"]+"|[a-z0-9_]+)(\s+)(=>)', bygroups(Name.Variable,
2167
Text, Punctuation)),
2168
(r'[a-z0-9._\'"]', Text),
2169
(r'\)', Punctuation, '#pop'),
2175
class Modula2Lexer(RegexLexer):
2177
For `Modula-2 <http://www.modula2.org/>`_ source code.
2179
Additional options that determine which keywords are highlighted:
2182
Select PIM Modula-2 dialect (default: True).
2184
Select ISO Modula-2 dialect (default: False).
2186
Select Objective Modula-2 dialect (default: False).
2188
Also highlight GNU extensions (default: False).
2190
*New in Pygments 1.3.*
2193
aliases = ['modula2', 'm2']
2194
filenames = ['*.def', '*.mod']
2195
mimetypes = ['text/x-modula2']
2197
flags = re.MULTILINE | re.DOTALL
2201
(r'\n+', Text), # blank lines
2202
(r'\s+', Text), # whitespace
2205
(r'([a-zA-Z_\$][a-zA-Z0-9_\$]*)', Name),
2208
(r'[01]+B', Number.Binary), # binary number (ObjM2)
2209
(r'[0-7]+B', Number.Oct), # octal number (PIM + ISO)
2210
(r'[0-7]+C', Number.Oct), # char code (PIM + ISO)
2211
(r'[0-9A-F]+C', Number.Hex), # char code (ObjM2)
2212
(r'[0-9A-F]+H', Number.Hex), # hexadecimal number
2213
(r'[0-9]+\.[0-9]+E[+-][0-9]+', Number.Float), # real number
2214
(r'[0-9]+\.[0-9]+', Number.Float), # real number
2215
(r'[0-9]+', Number.Integer), # decimal whole number
2218
(r"'(\\\\|\\'|[^'])*'", String), # single quoted string
2219
(r'"(\\\\|\\"|[^"])*"', String), # double quoted string
2222
(r'[*/+=#~&<>\^-]', Operator),
2223
(r':=', Operator), # assignment
2224
(r'@', Operator), # pointer deref (ISO)
2225
(r'\.\.', Operator), # ellipsis or range
2226
(r'`', Operator), # Smalltalk message (ObjM2)
2227
(r'::', Operator), # type conversion (ObjM2)
2230
(r'[\(\)\[\]{},.:;|]', Punctuation),
2233
(r'//.*?\n', Comment.Single), # ObjM2
2234
(r'/\*(.*?)\*/', Comment.Multiline), # ObjM2
2235
(r'\(\*([^\$].*?)\*\)', Comment.Multiline),
2236
# TO DO: nesting of (* ... *) comments
2239
(r'\(\*\$(.*?)\*\)', Comment.Preproc), # PIM
2240
(r'<\*(.*?)\*>', Comment.Preproc), # ISO + ObjM2
2243
include('whitespace'),
2244
include('comments'),
2246
include('identifiers'),
2247
include('numliterals'),
2249
include('operators'),
2250
include('punctuation'),
2254
pim_reserved_words = [
2256
'AND', 'ARRAY', 'BEGIN', 'BY', 'CASE', 'CONST', 'DEFINITION',
2257
'DIV', 'DO', 'ELSE', 'ELSIF', 'END', 'EXIT', 'EXPORT', 'FOR',
2258
'FROM', 'IF', 'IMPLEMENTATION', 'IMPORT', 'IN', 'LOOP', 'MOD',
2259
'MODULE', 'NOT', 'OF', 'OR', 'POINTER', 'PROCEDURE', 'QUALIFIED',
2260
'RECORD', 'REPEAT', 'RETURN', 'SET', 'THEN', 'TO', 'TYPE',
2261
'UNTIL', 'VAR', 'WHILE', 'WITH',
2266
'ABS', 'BITSET', 'BOOLEAN', 'CAP', 'CARDINAL', 'CHAR', 'CHR', 'DEC',
2267
'DISPOSE', 'EXCL', 'FALSE', 'FLOAT', 'HALT', 'HIGH', 'INC', 'INCL',
2268
'INTEGER', 'LONGINT', 'LONGREAL', 'MAX', 'MIN', 'NEW', 'NIL', 'ODD',
2269
'ORD', 'PROC', 'REAL', 'SIZE', 'TRUE', 'TRUNC', 'VAL',
2272
iso_reserved_words = [
2274
'AND', 'ARRAY', 'BEGIN', 'BY', 'CASE', 'CONST', 'DEFINITION', 'DIV',
2275
'DO', 'ELSE', 'ELSIF', 'END', 'EXCEPT', 'EXIT', 'EXPORT', 'FINALLY',
2276
'FOR', 'FORWARD', 'FROM', 'IF', 'IMPLEMENTATION', 'IMPORT', 'IN',
2277
'LOOP', 'MOD', 'MODULE', 'NOT', 'OF', 'OR', 'PACKEDSET', 'POINTER',
2278
'PROCEDURE', 'QUALIFIED', 'RECORD', 'REPEAT', 'REM', 'RETRY',
2279
'RETURN', 'SET', 'THEN', 'TO', 'TYPE', 'UNTIL', 'VAR', 'WHILE',
2285
'ABS', 'BITSET', 'BOOLEAN', 'CAP', 'CARDINAL', 'CHAR', 'CHR', 'CMPLX',
2286
'COMPLEX', 'DEC', 'DISPOSE', 'EXCL', 'FALSE', 'FLOAT', 'HALT', 'HIGH',
2287
'IM', 'INC', 'INCL', 'INT', 'INTEGER', 'INTERRUPTIBLE', 'LENGTH',
2288
'LFLOAT', 'LONGCOMPLEX', 'LONGINT', 'LONGREAL', 'MAX', 'MIN', 'NEW',
2289
'NIL', 'ODD', 'ORD', 'PROC', 'PROTECTION', 'RE', 'REAL', 'SIZE',
2290
'TRUE', 'TRUNC', 'UNINTERRUBTIBLE', 'VAL',
2293
objm2_reserved_words = [
2294
# base language, 42 reserved words
2295
'AND', 'ARRAY', 'BEGIN', 'BY', 'CASE', 'CONST', 'DEFINITION', 'DIV',
2296
'DO', 'ELSE', 'ELSIF', 'END', 'ENUM', 'EXIT', 'FOR', 'FROM', 'IF',
2297
'IMMUTABLE', 'IMPLEMENTATION', 'IMPORT', 'IN', 'IS', 'LOOP', 'MOD',
2298
'MODULE', 'NOT', 'OF', 'OPAQUE', 'OR', 'POINTER', 'PROCEDURE',
2299
'RECORD', 'REPEAT', 'RETURN', 'SET', 'THEN', 'TO', 'TYPE',
2300
'UNTIL', 'VAR', 'VARIADIC', 'WHILE',
2301
# OO extensions, 16 reserved words
2302
'BYCOPY', 'BYREF', 'CLASS', 'CONTINUE', 'CRITICAL', 'INOUT', 'METHOD',
2303
'ON', 'OPTIONAL', 'OUT', 'PRIVATE', 'PROTECTED', 'PROTOCOL', 'PUBLIC',
2307
objm2_pervasives = [
2308
# base language, 38 pervasives
2309
'ABS', 'BITSET', 'BOOLEAN', 'CARDINAL', 'CHAR', 'CHR', 'DISPOSE',
2310
'FALSE', 'HALT', 'HIGH', 'INTEGER', 'INRANGE', 'LENGTH', 'LONGCARD',
2311
'LONGINT', 'LONGREAL', 'MAX', 'MIN', 'NEG', 'NEW', 'NEXTV', 'NIL',
2312
'OCTET', 'ODD', 'ORD', 'PRED', 'PROC', 'READ', 'REAL', 'SUCC', 'TMAX',
2313
'TMIN', 'TRUE', 'TSIZE', 'UNICHAR', 'VAL', 'WRITE', 'WRITEF',
2314
# OO extensions, 3 pervasives
2315
'OBJECT', 'NO', 'YES',
2318
gnu_reserved_words = [
2319
# 10 additional reserved words
2320
'ASM', '__ATTRIBUTE__', '__BUILTIN__', '__COLUMN__', '__DATE__',
2321
'__FILE__', '__FUNCTION__', '__LINE__', '__MODULE__', 'VOLATILE',
2325
# 21 identifiers, actually from pseudo-module SYSTEM
2326
# but we will highlight them as if they were pervasives
2327
'BITSET8', 'BITSET16', 'BITSET32', 'CARDINAL8', 'CARDINAL16',
2328
'CARDINAL32', 'CARDINAL64', 'COMPLEX32', 'COMPLEX64', 'COMPLEX96',
2329
'COMPLEX128', 'INTEGER8', 'INTEGER16', 'INTEGER32', 'INTEGER64',
2330
'REAL8', 'REAL16', 'REAL32', 'REAL96', 'REAL128', 'THROW',
2333
def __init__(self, **options):
2334
self.reserved_words = set()
2335
self.pervasives = set()
2337
if get_bool_opt(options, 'iso', False):
2338
self.reserved_words.update(self.iso_reserved_words)
2339
self.pervasives.update(self.iso_pervasives)
2340
# Objective Modula-2
2341
elif get_bool_opt(options, 'objm2', False):
2342
self.reserved_words.update(self.objm2_reserved_words)
2343
self.pervasives.update(self.objm2_pervasives)
2344
# PIM Modula-2 (DEFAULT)
2346
self.reserved_words.update(self.pim_reserved_words)
2347
self.pervasives.update(self.pim_pervasives)
2349
if get_bool_opt(options, 'gm2ext', False):
2350
self.reserved_words.update(self.gnu_reserved_words)
2351
self.pervasives.update(self.gnu_pervasives)
2353
RegexLexer.__init__(self, **options)
2355
def get_tokens_unprocessed(self, text):
2356
for index, token, value in \
2357
RegexLexer.get_tokens_unprocessed(self, text):
2358
# check for reserved words and pervasives
2360
if value in self.reserved_words:
2361
token = Keyword.Reserved
2362
elif value in self.pervasives:
2363
token = Keyword.Pervasive
2365
yield index, token, value