Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes
MoinMoin.support.pygments.lexers.compiled.DelphiLexer Class Reference
Inheritance diagram for MoinMoin.support.pygments.lexers.compiled.DelphiLexer:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.support.pygments.lexers.compiled.DelphiLexer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def get_tokens_unprocessed

Public Attributes

 keywords
 builtins

Static Public Attributes

string name = 'Delphi'
list aliases = ['delphi', 'pas', 'pascal', 'objectpascal']
list filenames = ['*.pas']
list mimetypes = ['text/x-pascal']
list TURBO_PASCAL_KEYWORDS
list DELPHI_KEYWORDS
list FREE_PASCAL_KEYWORDS
tuple BLOCK_KEYWORDS
tuple FUNCTION_MODIFIERS
tuple DIRECTIVES
tuple BUILTIN_TYPES
dictionary BUILTIN_UNITS
tuple ASM_REGISTERS
tuple ASM_INSTRUCTIONS

Detailed Description

For `Delphi <http://www.borland.com/delphi/>`_ (Borland Object Pascal),
Turbo Pascal and Free Pascal source code.

Additional options accepted:

`turbopascal`
    Highlight Turbo Pascal specific keywords (default: ``True``).
`delphi`
    Highlight Borland Delphi specific keywords (default: ``True``).
`freepascal`
    Highlight Free Pascal specific keywords (default: ``True``).
`units`
    A list of units that should be considered builtin, supported are
    ``System``, ``SysUtils``, ``Classes`` and ``Math``.
    Default is to consider all of them builtin.

Definition at line 389 of file compiled.py.


Constructor & Destructor Documentation

Definition at line 663 of file compiled.py.

00663 
00664     def __init__(self, **options):
00665         Lexer.__init__(self, **options)
00666         self.keywords = set()
00667         if get_bool_opt(options, 'turbopascal', True):
00668             self.keywords.update(self.TURBO_PASCAL_KEYWORDS)
00669         if get_bool_opt(options, 'delphi', True):
00670             self.keywords.update(self.DELPHI_KEYWORDS)
00671         if get_bool_opt(options, 'freepascal', True):
00672             self.keywords.update(self.FREE_PASCAL_KEYWORDS)
00673         self.builtins = set()
00674         for unit in get_list_opt(options, 'units', self.BUILTIN_UNITS.keys()):
00675             self.builtins.update(self.BUILTIN_UNITS[unit])


Member Function Documentation

Definition at line 676 of file compiled.py.

00676 
00677     def get_tokens_unprocessed(self, text):
00678         scanner = Scanner(text, re.DOTALL | re.MULTILINE | re.IGNORECASE)
00679         stack = ['initial']
00680         in_function_block = False
00681         in_property_block = False
00682         was_dot = False
00683         next_token_is_function = False
00684         next_token_is_property = False
00685         collect_labels = False
00686         block_labels = set()
00687         brace_balance = [0, 0]
00688 
00689         while not scanner.eos:
00690             token = Error
00691 
00692             if stack[-1] == 'initial':
00693                 if scanner.scan(r'\s+'):
00694                     token = Text
00695                 elif scanner.scan(r'\{.*?\}|\(\*.*?\*\)'):
00696                     if scanner.match.startswith('$'):
00697                         token = Comment.Preproc
00698                     else:
00699                         token = Comment.Multiline
00700                 elif scanner.scan(r'//.*?$'):
00701                     token = Comment.Single
00702                 elif scanner.scan(r'[-+*\/=<>:;,.@\^]'):
00703                     token = Operator
00704                     # stop label highlighting on next ";"
00705                     if collect_labels and scanner.match == ';':
00706                         collect_labels = False
00707                 elif scanner.scan(r'[\(\)\[\]]+'):
00708                     token = Punctuation
00709                     # abort function naming ``foo = Function(...)``
00710                     next_token_is_function = False
00711                     # if we are in a function block we count the open
00712                     # braces because ootherwise it's impossible to
00713                     # determine the end of the modifier context
00714                     if in_function_block or in_property_block:
00715                         if scanner.match == '(':
00716                             brace_balance[0] += 1
00717                         elif scanner.match == ')':
00718                             brace_balance[0] -= 1
00719                         elif scanner.match == '[':
00720                             brace_balance[1] += 1
00721                         elif scanner.match == ']':
00722                             brace_balance[1] -= 1
00723                 elif scanner.scan(r'[A-Za-z_][A-Za-z_0-9]*'):
00724                     lowercase_name = scanner.match.lower()
00725                     if lowercase_name == 'result':
00726                         token = Name.Builtin.Pseudo
00727                     elif lowercase_name in self.keywords:
00728                         token = Keyword
00729                         # if we are in a special block and a
00730                         # block ending keyword occours (and the parenthesis
00731                         # is balanced) we end the current block context
00732                         if (in_function_block or in_property_block) and \
00733                            lowercase_name in self.BLOCK_KEYWORDS and \
00734                            brace_balance[0] <= 0 and \
00735                            brace_balance[1] <= 0:
00736                             in_function_block = False
00737                             in_property_block = False
00738                             brace_balance = [0, 0]
00739                             block_labels = set()
00740                         if lowercase_name in ('label', 'goto'):
00741                             collect_labels = True
00742                         elif lowercase_name == 'asm':
00743                             stack.append('asm')
00744                         elif lowercase_name == 'property':
00745                             in_property_block = True
00746                             next_token_is_property = True
00747                         elif lowercase_name in ('procedure', 'operator',
00748                                                 'function', 'constructor',
00749                                                 'destructor'):
00750                             in_function_block = True
00751                             next_token_is_function = True
00752                     # we are in a function block and the current name
00753                     # is in the set of registered modifiers. highlight
00754                     # it as pseudo keyword
00755                     elif in_function_block and \
00756                          lowercase_name in self.FUNCTION_MODIFIERS:
00757                         token = Keyword.Pseudo
00758                     # if we are in a property highlight some more
00759                     # modifiers
00760                     elif in_property_block and \
00761                          lowercase_name in ('read', 'write'):
00762                         token = Keyword.Pseudo
00763                         next_token_is_function = True
00764                     # if the last iteration set next_token_is_function
00765                     # to true we now want this name highlighted as
00766                     # function. so do that and reset the state
00767                     elif next_token_is_function:
00768                         # Look if the next token is a dot. If yes it's
00769                         # not a function, but a class name and the
00770                         # part after the dot a function name
00771                         if scanner.test(r'\s*\.\s*'):
00772                             token = Name.Class
00773                         # it's not a dot, our job is done
00774                         else:
00775                             token = Name.Function
00776                             next_token_is_function = False
00777                     # same for properties
00778                     elif next_token_is_property:
00779                         token = Name.Property
00780                         next_token_is_property = False
00781                     # Highlight this token as label and add it
00782                     # to the list of known labels
00783                     elif collect_labels:
00784                         token = Name.Label
00785                         block_labels.add(scanner.match.lower())
00786                     # name is in list of known labels
00787                     elif lowercase_name in block_labels:
00788                         token = Name.Label
00789                     elif lowercase_name in self.BUILTIN_TYPES:
00790                         token = Keyword.Type
00791                     elif lowercase_name in self.DIRECTIVES:
00792                         token = Keyword.Pseudo
00793                     # builtins are just builtins if the token
00794                     # before isn't a dot
00795                     elif not was_dot and lowercase_name in self.builtins:
00796                         token = Name.Builtin
00797                     else:
00798                         token = Name
00799                 elif scanner.scan(r"'"):
00800                     token = String
00801                     stack.append('string')
00802                 elif scanner.scan(r'\#(\d+|\$[0-9A-Fa-f]+)'):
00803                     token = String.Char
00804                 elif scanner.scan(r'\$[0-9A-Fa-f]+'):
00805                     token = Number.Hex
00806                 elif scanner.scan(r'\d+(?![eE]|\.[^.])'):
00807                     token = Number.Integer
00808                 elif scanner.scan(r'\d+(\.\d+([eE][+-]?\d+)?|[eE][+-]?\d+)'):
00809                     token = Number.Float
00810                 else:
00811                     # if the stack depth is deeper than once, pop
00812                     if len(stack) > 1:
00813                         stack.pop()
00814                     scanner.get_char()
00815 
00816             elif stack[-1] == 'string':
00817                 if scanner.scan(r"''"):
00818                     token = String.Escape
00819                 elif scanner.scan(r"'"):
00820                     token = String
00821                     stack.pop()
00822                 elif scanner.scan(r"[^']*"):
00823                     token = String
00824                 else:
00825                     scanner.get_char()
00826                     stack.pop()
00827 
00828             elif stack[-1] == 'asm':
00829                 if scanner.scan(r'\s+'):
00830                     token = Text
00831                 elif scanner.scan(r'end'):
00832                     token = Keyword
00833                     stack.pop()
00834                 elif scanner.scan(r'\{.*?\}|\(\*.*?\*\)'):
00835                     if scanner.match.startswith('$'):
00836                         token = Comment.Preproc
00837                     else:
00838                         token = Comment.Multiline
00839                 elif scanner.scan(r'//.*?$'):
00840                     token = Comment.Single
00841                 elif scanner.scan(r"'"):
00842                     token = String
00843                     stack.append('string')
00844                 elif scanner.scan(r'@@[A-Za-z_][A-Za-z_0-9]*'):
00845                     token = Name.Label
00846                 elif scanner.scan(r'[A-Za-z_][A-Za-z_0-9]*'):
00847                     lowercase_name = scanner.match.lower()
00848                     if lowercase_name in self.ASM_INSTRUCTIONS:
00849                         token = Keyword
00850                     elif lowercase_name in self.ASM_REGISTERS:
00851                         token = Name.Builtin
00852                     else:
00853                         token = Name
00854                 elif scanner.scan(r'[-+*\/=<>:;,.@\^]+'):
00855                     token = Operator
00856                 elif scanner.scan(r'[\(\)\[\]]+'):
00857                     token = Punctuation
00858                 elif scanner.scan(r'\$[0-9A-Fa-f]+'):
00859                     token = Number.Hex
00860                 elif scanner.scan(r'\d+(?![eE]|\.[^.])'):
00861                     token = Number.Integer
00862                 elif scanner.scan(r'\d+(\.\d+([eE][+-]?\d+)?|[eE][+-]?\d+)'):
00863                     token = Number.Float
00864                 else:
00865                     scanner.get_char()
00866                     stack.pop()
00867 
00868             # save the dot!!!11
00869             if scanner.match.strip():
00870                 was_dot = scanner.match == '.'
00871             yield scanner.start_pos, token, scanner.match or ''
00872 

Here is the caller graph for this function:


Member Data Documentation

list MoinMoin.support.pygments.lexers.compiled.DelphiLexer.aliases = ['delphi', 'pas', 'pascal', 'objectpascal'] [static]

Definition at line 408 of file compiled.py.

Definition at line 622 of file compiled.py.

Initial value:
set([
        'ah', 'al', 'ax', 'bh', 'bl', 'bp', 'bx', 'ch', 'cl', 'cr0',
        'cr1', 'cr2', 'cr3', 'cr4', 'cs', 'cx', 'dh', 'di', 'dl', 'dr0',
        'dr1', 'dr2', 'dr3', 'dr4', 'dr5', 'dr6', 'dr7', 'ds', 'dx',
        'eax', 'ebp', 'ebx', 'ecx', 'edi', 'edx', 'es', 'esi', 'esp',
        'fs', 'gs', 'mm0', 'mm1', 'mm2', 'mm3', 'mm4', 'mm5', 'mm6',
        'mm7', 'si', 'sp', 'ss', 'st0', 'st1', 'st2', 'st3', 'st4', 'st5',
        'st6', 'st7', 'xmm0', 'xmm1', 'xmm2', 'xmm3', 'xmm4', 'xmm5',
        'xmm6', 'xmm7'
    ])

Definition at line 611 of file compiled.py.

Initial value:
set([
        'begin', 'class', 'const', 'constructor', 'destructor', 'end',
        'finalization', 'function', 'implementation', 'initialization',
        'label', 'library', 'operator', 'procedure', 'program', 'property',
        'record', 'threadvar', 'type', 'unit', 'uses', 'var'
    ])

Definition at line 433 of file compiled.py.

Initial value:
set([
        'ansichar', 'ansistring', 'bool', 'boolean', 'byte', 'bytebool',
        'cardinal', 'char', 'comp', 'currency', 'double', 'dword',
        'extended', 'int64', 'integer', 'iunknown', 'longbool', 'longint',
        'longword', 'pansichar', 'pansistring', 'pbool', 'pboolean',
        'pbyte', 'pbytearray', 'pcardinal', 'pchar', 'pcomp', 'pcurrency',
        'pdate', 'pdatetime', 'pdouble', 'pdword', 'pextended', 'phandle',
        'pint64', 'pinteger', 'plongint', 'plongword', 'pointer',
        'ppointer', 'pshortint', 'pshortstring', 'psingle', 'psmallint',
        'pstring', 'pvariant', 'pwidechar', 'pwidestring', 'pword',
        'pwordarray', 'pwordbool', 'real', 'real48', 'shortint',
        'shortstring', 'single', 'smallint', 'string', 'tclass', 'tdate',
        'tdatetime', 'textfile', 'thandle', 'tobject', 'ttime', 'variant',
        'widechar', 'widestring', 'word', 'wordbool'
    ])

Definition at line 455 of file compiled.py.

Definition at line 471 of file compiled.py.

Definition at line 672 of file compiled.py.

Initial value:
[
        'as', 'class', 'except', 'exports', 'finalization', 'finally',
        'initialization', 'is', 'library', 'on', 'property', 'raise',
        'threadvar', 'try'
    ]

Definition at line 423 of file compiled.py.

Initial value:
set([
        'absolute', 'abstract', 'assembler', 'cppdecl', 'default', 'far',
        'far16', 'forward', 'index', 'oldfpccall', 'private', 'protected',
        'published', 'public'
    ])

Definition at line 449 of file compiled.py.

Definition at line 409 of file compiled.py.

Initial value:
[
        'dispose', 'exit', 'false', 'new', 'true'
    ]

Definition at line 429 of file compiled.py.

Initial value:
set([
        'alias', 'cdecl', 'export', 'inline', 'interrupt', 'nostackframe',
        'pascal', 'register', 'safecall', 'softfloat', 'stdcall',
        'varargs', 'name', 'dynamic', 'near', 'virtual', 'external',
        'override', 'assembler'
    ])

Definition at line 440 of file compiled.py.

Definition at line 665 of file compiled.py.

Definition at line 410 of file compiled.py.

Definition at line 407 of file compiled.py.

Initial value:
[
        'absolute', 'and', 'array', 'asm', 'begin', 'break', 'case',
        'const', 'constructor', 'continue', 'destructor', 'div', 'do',
        'downto', 'else', 'end', 'file', 'for', 'function', 'goto',
        'if', 'implementation', 'in', 'inherited', 'inline', 'interface',
        'label', 'mod', 'nil', 'not', 'object', 'of', 'on', 'operator',
        'or', 'packed', 'procedure', 'program', 'record', 'reintroduce',
        'repeat', 'self', 'set', 'shl', 'shr', 'string', 'then', 'to',
        'type', 'unit', 'until', 'uses', 'var', 'while', 'with', 'xor'
    ]

Definition at line 412 of file compiled.py.


The documentation for this class was generated from the following file: