|
1 # -*- coding: utf-8 -*- |
|
2 """ |
|
3 pygments.lexers.oberon |
|
4 ~~~~~~~~~~~~~~~~~~~~~~ |
|
5 |
|
6 Lexers for Oberon family languages. |
|
7 |
|
8 :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. |
|
9 :license: BSD, see LICENSE for details. |
|
10 """ |
|
11 |
|
12 import re |
|
13 |
|
14 from pygments.lexer import RegexLexer, include, words |
|
15 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
|
16 Number, Punctuation |
|
17 |
|
18 __all__ = ['ComponentPascalLexer'] |
|
19 |
|
20 |
|
21 class ComponentPascalLexer(RegexLexer): |
|
22 """ |
|
23 For `Component Pascal <http://www.oberon.ch/pdf/CP-Lang.pdf>`_ source code. |
|
24 |
|
25 .. versionadded:: 2.1 |
|
26 """ |
|
27 name = 'Component Pascal' |
|
28 aliases = ['componentpascal', 'cp'] |
|
29 filenames = ['*.cp', '*.cps'] |
|
30 mimetypes = ['text/x-component-pascal'] |
|
31 |
|
32 flags = re.MULTILINE | re.DOTALL |
|
33 |
|
34 tokens = { |
|
35 'root': [ |
|
36 include('whitespace'), |
|
37 include('comments'), |
|
38 include('punctuation'), |
|
39 include('numliterals'), |
|
40 include('strings'), |
|
41 include('operators'), |
|
42 include('builtins'), |
|
43 include('identifiers'), |
|
44 ], |
|
45 'whitespace': [ |
|
46 (r'\n+', Text), # blank lines |
|
47 (r'\s+', Text), # whitespace |
|
48 ], |
|
49 'comments': [ |
|
50 (r'\(\*([^\$].*?)\*\)', Comment.Multiline), |
|
51 # TODO: nested comments (* (* ... *) ... (* ... *) *) not supported! |
|
52 ], |
|
53 'punctuation': [ |
|
54 (r'[\(\)\[\]\{\},.:;\|]', Punctuation), |
|
55 ], |
|
56 'numliterals': [ |
|
57 (r'[0-9A-F]+X\b', Number.Hex), # char code |
|
58 (r'[0-9A-F]+[HL]\b', Number.Hex), # hexadecimal number |
|
59 (r'[0-9]+\.[0-9]+E[+-][0-9]+', Number.Float), # real number |
|
60 (r'[0-9]+\.[0-9]+', Number.Float), # real number |
|
61 (r'[0-9]+', Number.Integer), # decimal whole number |
|
62 ], |
|
63 'strings': [ |
|
64 (r"'[^\n']*'", String), # single quoted string |
|
65 (r'"[^\n"]*"', String), # double quoted string |
|
66 ], |
|
67 'operators': [ |
|
68 # Arithmetic Operators |
|
69 (r'[+-]', Operator), |
|
70 (r'[*/]', Operator), |
|
71 # Relational Operators |
|
72 (r'[=#<>]', Operator), |
|
73 # Dereferencing Operator |
|
74 (r'\^', Operator), |
|
75 # Logical AND Operator |
|
76 (r'&', Operator), |
|
77 # Logical NOT Operator |
|
78 (r'~', Operator), |
|
79 # Assignment Symbol |
|
80 (r':=', Operator), |
|
81 # Range Constructor |
|
82 (r'\.\.', Operator), |
|
83 (r'\$', Operator), |
|
84 ], |
|
85 'identifiers': [ |
|
86 (r'([a-zA-Z_\$][\w\$]*)', Name), |
|
87 ], |
|
88 'builtins': [ |
|
89 (words(( |
|
90 'ANYPTR', 'ANYREC', 'BOOLEAN', 'BYTE', 'CHAR', 'INTEGER', 'LONGINT', |
|
91 'REAL', 'SET', 'SHORTCHAR', 'SHORTINT', 'SHORTREAL' |
|
92 ), suffix=r'\b'), Keyword.Type), |
|
93 (words(( |
|
94 'ABS', 'ABSTRACT', 'ARRAY', 'ASH', 'ASSERT', 'BEGIN', 'BITS', 'BY', |
|
95 'CAP', 'CASE', 'CHR', 'CLOSE', 'CONST', 'DEC', 'DIV', 'DO', 'ELSE', |
|
96 'ELSIF', 'EMPTY', 'END', 'ENTIER', 'EXCL', 'EXIT', 'EXTENSIBLE', 'FOR', |
|
97 'HALT', 'IF', 'IMPORT', 'IN', 'INC', 'INCL', 'IS', 'LEN', 'LIMITED', |
|
98 'LONG', 'LOOP', 'MAX', 'MIN', 'MOD', 'MODULE', 'NEW', 'ODD', 'OF', |
|
99 'OR', 'ORD', 'OUT', 'POINTER', 'PROCEDURE', 'RECORD', 'REPEAT', 'RETURN', |
|
100 'SHORT', 'SHORTCHAR', 'SHORTINT', 'SIZE', 'THEN', 'TYPE', 'TO', 'UNTIL', |
|
101 'VAR', 'WHILE', 'WITH' |
|
102 ), suffix=r'\b'), Keyword.Reserved), |
|
103 (r'(TRUE|FALSE|NIL|INF)\b', Keyword.Constant), |
|
104 ] |
|
105 } |