3 pygments.lexers.esoteric |
3 pygments.lexers.esoteric |
4 ~~~~~~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Lexers for esoteric languages. |
6 Lexers for esoteric languages. |
7 |
7 |
8 :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. |
9 :license: BSD, see LICENSE for details. |
9 :license: BSD, see LICENSE for details. |
10 """ |
10 """ |
11 |
11 |
12 from pygments.lexer import RegexLexer, include, words |
12 from pygments.lexer import RegexLexer, include, words |
13 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
13 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
14 Number, Punctuation, Error, Whitespace |
14 Number, Punctuation, Error |
15 |
15 |
16 __all__ = ['BrainfuckLexer', 'BefungeLexer', 'BoogieLexer', 'RedcodeLexer', 'CAmkESLexer'] |
16 __all__ = ['BrainfuckLexer', 'BefungeLexer', 'RedcodeLexer', 'CAmkESLexer', |
|
17 'CapDLLexer', 'AheuiLexer'] |
17 |
18 |
18 |
19 |
19 class BrainfuckLexer(RegexLexer): |
20 class BrainfuckLexer(RegexLexer): |
20 """ |
21 """ |
21 Lexer for the esoteric `BrainFuck <http://www.muppetlabs.com/~breadbox/bf/>`_ |
22 Lexer for the esoteric `BrainFuck <http://www.muppetlabs.com/~breadbox/bf/>`_ |
88 name = 'CAmkES' |
89 name = 'CAmkES' |
89 aliases = ['camkes', 'idl4'] |
90 aliases = ['camkes', 'idl4'] |
90 filenames = ['*.camkes', '*.idl4'] |
91 filenames = ['*.camkes', '*.idl4'] |
91 |
92 |
92 tokens = { |
93 tokens = { |
93 'root':[ |
94 'root': [ |
94 # C pre-processor directive |
95 # C pre-processor directive |
95 (r'^\s*#.*\n', Comment.Preproc), |
96 (r'^\s*#.*\n', Comment.Preproc), |
96 |
97 |
97 # Whitespace, comments |
98 # Whitespace, comments |
98 (r'\s+', Text), |
99 (r'\s+', Text), |
99 (r'/\*(.|\n)*?\*/', Comment), |
100 (r'/\*(.|\n)*?\*/', Comment), |
100 (r'//.*\n', Comment), |
101 (r'//.*\n', Comment), |
101 |
102 |
102 (r'[\[\(\){},\.;=\]]', Punctuation), |
103 (r'[\[(){},.;\]]', Punctuation), |
|
104 (r'[~!%^&*+=|?:<>/-]', Operator), |
103 |
105 |
104 (words(('assembly', 'attribute', 'component', 'composition', |
106 (words(('assembly', 'attribute', 'component', 'composition', |
105 'configuration', 'connection', 'connector', 'consumes', |
107 'configuration', 'connection', 'connector', 'consumes', |
106 'control', 'dataport', 'Dataport', 'emits', 'event', |
108 'control', 'dataport', 'Dataport', 'Dataports', 'emits', |
107 'Event', 'from', 'group', 'hardware', 'has', 'interface', |
109 'event', 'Event', 'Events', 'export', 'from', 'group', |
108 'Interface', 'maybe', 'procedure', 'Procedure', 'provides', |
110 'hardware', 'has', 'interface', 'Interface', 'maybe', |
109 'template', 'to', 'uses'), suffix=r'\b'), Keyword), |
111 'procedure', 'Procedure', 'Procedures', 'provides', |
|
112 'template', 'thread', 'threads', 'to', 'uses', 'with'), |
|
113 suffix=r'\b'), Keyword), |
110 |
114 |
111 (words(('bool', 'boolean', 'Buf', 'char', 'character', 'double', |
115 (words(('bool', 'boolean', 'Buf', 'char', 'character', 'double', |
112 'float', 'in', 'inout', 'int', 'int16_6', 'int32_t', |
116 'float', 'in', 'inout', 'int', 'int16_6', 'int32_t', |
113 'int64_t', 'int8_t', 'integer', 'mutex', 'out', 'real', |
117 'int64_t', 'int8_t', 'integer', 'mutex', 'out', 'real', |
114 'refin', 'semaphore', 'signed', 'string', 'uint16_t', |
118 'refin', 'semaphore', 'signed', 'string', 'struct', |
115 'uint32_t', 'uint64_t', 'uint8_t', 'uintptr_t', 'unsigned', |
119 'uint16_t', 'uint32_t', 'uint64_t', 'uint8_t', 'uintptr_t', |
116 'void'), suffix=r'\b'), Keyword.Type), |
120 'unsigned', 'void'), |
|
121 suffix=r'\b'), Keyword.Type), |
117 |
122 |
118 # Recognised attributes |
123 # Recognised attributes |
119 (r'[a-zA-Z_]\w*_(priority|domain|buffer)', Keyword.Reserved), |
124 (r'[a-zA-Z_]\w*_(priority|domain|buffer)', Keyword.Reserved), |
120 (words(('dma_pool', 'from_access', 'to_access'), suffix=r'\b'), |
125 (words(('dma_pool', 'from_access', 'to_access'), suffix=r'\b'), |
121 Keyword.Reserved), |
126 Keyword.Reserved), |
129 # Literals |
134 # Literals |
130 (r'0[xX][\da-fA-F]+', Number.Hex), |
135 (r'0[xX][\da-fA-F]+', Number.Hex), |
131 (r'-?[\d]+', Number), |
136 (r'-?[\d]+', Number), |
132 (r'-?[\d]+\.[\d]+', Number.Float), |
137 (r'-?[\d]+\.[\d]+', Number.Float), |
133 (r'"[^"]*"', String), |
138 (r'"[^"]*"', String), |
|
139 (r'[Tt]rue|[Ff]alse', Name.Builtin), |
134 |
140 |
135 # Identifiers |
141 # Identifiers |
136 (r'[a-zA-Z_]\w*', Name), |
142 (r'[a-zA-Z_]\w*', Name), |
|
143 ], |
|
144 } |
|
145 |
|
146 |
|
147 class CapDLLexer(RegexLexer): |
|
148 """ |
|
149 Basic lexer for |
|
150 `CapDL <https://ssrg.nicta.com.au/publications/nictaabstracts/Kuz_KLW_10.abstract.pml>`_. |
|
151 |
|
152 The source of the primary tool that reads such specifications is available |
|
153 at https://github.com/seL4/capdl/tree/master/capDL-tool. Note that this |
|
154 lexer only supports a subset of the grammar. For example, identifiers can |
|
155 shadow type names, but these instances are currently incorrectly |
|
156 highlighted as types. Supporting this would need a stateful lexer that is |
|
157 considered unnecessarily complex for now. |
|
158 |
|
159 .. versionadded:: 2.2 |
|
160 """ |
|
161 name = 'CapDL' |
|
162 aliases = ['capdl'] |
|
163 filenames = ['*.cdl'] |
|
164 |
|
165 tokens = { |
|
166 'root': [ |
|
167 # C pre-processor directive |
|
168 (r'^\s*#.*\n', Comment.Preproc), |
|
169 |
|
170 # Whitespace, comments |
|
171 (r'\s+', Text), |
|
172 (r'/\*(.|\n)*?\*/', Comment), |
|
173 (r'(//|--).*\n', Comment), |
|
174 |
|
175 (r'[<>\[(){},:;=\]]', Punctuation), |
|
176 (r'\.\.', Punctuation), |
|
177 |
|
178 (words(('arch', 'arm11', 'caps', 'child_of', 'ia32', 'irq', 'maps', |
|
179 'objects'), suffix=r'\b'), Keyword), |
|
180 |
|
181 (words(('aep', 'asid_pool', 'cnode', 'ep', 'frame', 'io_device', |
|
182 'io_ports', 'io_pt', 'notification', 'pd', 'pt', 'tcb', |
|
183 'ut', 'vcpu'), suffix=r'\b'), Keyword.Type), |
|
184 |
|
185 # Properties |
|
186 (words(('asid', 'addr', 'badge', 'cached', 'dom', 'domainID', 'elf', |
|
187 'fault_ep', 'G', 'guard', 'guard_size', 'init', 'ip', |
|
188 'prio', 'sp', 'R', 'RG', 'RX', 'RW', 'RWG', 'RWX', 'W', |
|
189 'WG', 'WX', 'level', 'masked', 'master_reply', 'paddr', |
|
190 'ports', 'reply', 'uncached'), suffix=r'\b'), |
|
191 Keyword.Reserved), |
|
192 |
|
193 # Literals |
|
194 (r'0[xX][\da-fA-F]+', Number.Hex), |
|
195 (r'\d+(\.\d+)?(k|M)?', Number), |
|
196 (words(('bits',), suffix=r'\b'), Number), |
|
197 (words(('cspace', 'vspace', 'reply_slot', 'caller_slot', |
|
198 'ipc_buffer_slot'), suffix=r'\b'), Number), |
|
199 |
|
200 # Identifiers |
|
201 (r'[a-zA-Z_][-@\.\w]*', Name), |
137 ], |
202 ], |
138 } |
203 } |
139 |
204 |
140 |
205 |
141 class RedcodeLexer(RegexLexer): |
206 class RedcodeLexer(RegexLexer): |
172 (r'[-+]?\d+', Number.Integer), |
237 (r'[-+]?\d+', Number.Integer), |
173 ], |
238 ], |
174 } |
239 } |
175 |
240 |
176 |
241 |
177 class BoogieLexer(RegexLexer): |
242 class AheuiLexer(RegexLexer): |
178 """ |
243 """ |
179 For `Boogie <https://boogie.codeplex.com/>`_ source code. |
244 Aheui_ Lexer. |
180 |
245 |
181 .. versionadded:: 2.1 |
246 Aheui_ is esoteric language based on Korean alphabets. |
182 """ |
247 |
183 name = 'Boogie' |
248 .. _Aheui:: http://aheui.github.io/ |
184 aliases = ['boogie'] |
249 |
185 filenames = ['*.bpl'] |
250 """ |
186 |
251 |
187 tokens = { |
252 name = 'Aheui' |
188 'root': [ |
253 aliases = ['aheui'] |
189 # Whitespace and Comments |
254 filenames = ['*.aheui'] |
190 (r'\n', Whitespace), |
255 |
191 (r'\s+', Whitespace), |
256 tokens = { |
192 (r'//[/!](.*?)\n', Comment.Doc), |
257 'root': [ |
193 (r'//(.*?)\n', Comment.Single), |
258 (u'[' |
194 (r'/\*', Comment.Multiline, 'comment'), |
259 u'나-낳냐-냫너-넣녀-녛노-놓뇨-눟뉴-닇' |
195 |
260 u'다-닿댜-댷더-덯뎌-뎧도-돟됴-둫듀-딓' |
196 (words(( |
261 u'따-땋땨-떃떠-떻뗘-뗳또-똫뚀-뚷뜌-띟' |
197 'axiom', 'break', 'call', 'ensures', 'else', 'exists', 'function', |
262 u'라-랗랴-럏러-렇려-렿로-롷료-뤃류-릫' |
198 'forall', 'if', 'invariant', 'modifies', 'procedure', 'requires', |
263 u'마-맣먀-먛머-멓며-몋모-뫃묘-뭏뮤-믷' |
199 'then', 'var', 'while'), |
264 u'바-밯뱌-뱧버-벟벼-볗보-봏뵤-붛뷰-빃' |
200 suffix=r'\b'), Keyword), |
265 u'빠-빻뺘-뺳뻐-뻫뼈-뼣뽀-뽛뾰-뿧쀼-삏' |
201 (words(('const',), suffix=r'\b'), Keyword.Reserved), |
266 u'사-샇샤-샿서-섷셔-셯소-솧쇼-숳슈-싛' |
202 |
267 u'싸-쌓쌰-썋써-쎃쎠-쎻쏘-쏳쑈-쑿쓔-씧' |
203 (words(('bool', 'int', 'ref'), suffix=r'\b'), Keyword.Type), |
268 u'자-잫쟈-쟣저-젛져-졓조-좋죠-줗쥬-즿' |
204 include('numbers'), |
269 u'차-챃챠-챻처-첳쳐-쳫초-촣쵸-춯츄-칗' |
205 (r"(>=|<=|:=|!=|==>|&&|\|\||[+/\-=>*<\[\]])", Operator), |
270 u'카-캏캬-컇커-컿켜-켷코-콯쿄-쿻큐-킣' |
206 (r"([{}():;,.])", Punctuation), |
271 u'타-탛탸-턓터-텋텨-톃토-톻툐-퉇튜-틯' |
207 # Identifier |
272 u'파-팧퍄-퍟퍼-펗펴-폏포-퐇표-풓퓨-픻' |
208 (r'[a-zA-Z_]\w*', Name), |
273 u'하-핳햐-햫허-헣혀-혛호-홓효-훟휴-힇' |
209 ], |
274 u']', Operator), |
210 'comment': [ |
275 ('.', Comment), |
211 (r'[^*/]+', Comment.Multiline), |
276 ], |
212 (r'/\*', Comment.Multiline, '#push'), |
277 } |
213 (r'\*/', Comment.Multiline, '#pop'), |
|
214 (r'[*/]', Comment.Multiline), |
|
215 ], |
|
216 'numbers': [ |
|
217 (r'[0-9]+', Number.Integer), |
|
218 ], |
|
219 } |
|