1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
22:
23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33:
34: class Text_Highlighter_PYTHON extends Text_Highlighter
35: {
36: var $_language = 'python';
37:
38: 39: 40: 41: 42: 43:
44: function __construct($options=array())
45: {
46:
47: $this->_options = $options;
48: $this->_regs = array (
49: -1 => '/((?i)\'\'\')|((?i)""")|((?i)")|((?i)\')|((?i)\\()|((?i)\\[)|((?i)[a-z_]\\w*(?=\\s*\\())|((?i)[a-z_]\\w*)|((?i)((\\d+|((\\d*\\.\\d+)|(\\d+\\.\\d*)))[eE][+-]?\\d+))|((?i)((\\d*\\.\\d+)|(\\d+\\.\\d*)|(\\d+))j)|((?i)(\\d*\\.\\d+)|(\\d+\\.\\d*))|((?i)\\d+l?|\\b0l?\\b)|((?i)0[xX][\\da-f]+l?)|((?i)0[0-7]+l?)|((?i)#.+)/',
50: 0 => '/((?i)\\\\.)/',
51: 1 => '/((?i)\\\\.)/',
52: 2 => '/((?i)\\\\.)/',
53: 3 => '/((?i)\\\\.)/',
54: 4 => '/((?i)\'\'\')|((?i)""")|((?i)")|((?i)\')|((?i)\\()|((?i)\\[)|((?i)[a-z_]\\w*(?=\\s*\\())|((?i)[a-z_]\\w*)|((?i)((\\d+|((\\d*\\.\\d+)|(\\d+\\.\\d*)))[eE][+-]?\\d+))|((?i)((\\d*\\.\\d+)|(\\d+\\.\\d*)|(\\d+))j)|((?i)(\\d*\\.\\d+)|(\\d+\\.\\d*))|((?i)\\d+l?|\\b0l?\\b)|((?i)0[xX][\\da-f]+l?)|((?i)0[0-7]+l?)|((?i)#.+)/',
55: 5 => '/((?i)\'\'\')|((?i)""")|((?i)")|((?i)\')|((?i)\\()|((?i)\\[)|((?i)[a-z_]\\w*(?=\\s*\\())|((?i)[a-z_]\\w*)|((?i)((\\d+|((\\d*\\.\\d+)|(\\d+\\.\\d*)))[eE][+-]?\\d+))|((?i)((\\d*\\.\\d+)|(\\d+\\.\\d*)|(\\d+))j)|((?i)(\\d*\\.\\d+)|(\\d+\\.\\d*))|((?i)\\d+l?|\\b0l?\\b)|((?i)0[xX][\\da-f]+l?)|((?i)0[0-7]+l?)|((?i)#.+)/',
56: );
57: $this->_counts = array (
58: -1 =>
59: array (
60: 0 => 0,
61: 1 => 0,
62: 2 => 0,
63: 3 => 0,
64: 4 => 0,
65: 5 => 0,
66: 6 => 0,
67: 7 => 0,
68: 8 => 5,
69: 9 => 4,
70: 10 => 2,
71: 11 => 0,
72: 12 => 0,
73: 13 => 0,
74: 14 => 0,
75: ),
76: 0 =>
77: array (
78: 0 => 0,
79: ),
80: 1 =>
81: array (
82: 0 => 0,
83: ),
84: 2 =>
85: array (
86: 0 => 0,
87: ),
88: 3 =>
89: array (
90: 0 => 0,
91: ),
92: 4 =>
93: array (
94: 0 => 0,
95: 1 => 0,
96: 2 => 0,
97: 3 => 0,
98: 4 => 0,
99: 5 => 0,
100: 6 => 0,
101: 7 => 0,
102: 8 => 5,
103: 9 => 4,
104: 10 => 2,
105: 11 => 0,
106: 12 => 0,
107: 13 => 0,
108: 14 => 0,
109: ),
110: 5 =>
111: array (
112: 0 => 0,
113: 1 => 0,
114: 2 => 0,
115: 3 => 0,
116: 4 => 0,
117: 5 => 0,
118: 6 => 0,
119: 7 => 0,
120: 8 => 5,
121: 9 => 4,
122: 10 => 2,
123: 11 => 0,
124: 12 => 0,
125: 13 => 0,
126: 14 => 0,
127: ),
128: );
129: $this->_delim = array (
130: -1 =>
131: array (
132: 0 => 'quotes',
133: 1 => 'quotes',
134: 2 => 'quotes',
135: 3 => 'quotes',
136: 4 => 'brackets',
137: 5 => 'brackets',
138: 6 => '',
139: 7 => '',
140: 8 => '',
141: 9 => '',
142: 10 => '',
143: 11 => '',
144: 12 => '',
145: 13 => '',
146: 14 => '',
147: ),
148: 0 =>
149: array (
150: 0 => '',
151: ),
152: 1 =>
153: array (
154: 0 => '',
155: ),
156: 2 =>
157: array (
158: 0 => '',
159: ),
160: 3 =>
161: array (
162: 0 => '',
163: ),
164: 4 =>
165: array (
166: 0 => 'quotes',
167: 1 => 'quotes',
168: 2 => 'quotes',
169: 3 => 'quotes',
170: 4 => 'brackets',
171: 5 => 'brackets',
172: 6 => '',
173: 7 => '',
174: 8 => '',
175: 9 => '',
176: 10 => '',
177: 11 => '',
178: 12 => '',
179: 13 => '',
180: 14 => '',
181: ),
182: 5 =>
183: array (
184: 0 => 'quotes',
185: 1 => 'quotes',
186: 2 => 'quotes',
187: 3 => 'quotes',
188: 4 => 'brackets',
189: 5 => 'brackets',
190: 6 => '',
191: 7 => '',
192: 8 => '',
193: 9 => '',
194: 10 => '',
195: 11 => '',
196: 12 => '',
197: 13 => '',
198: 14 => '',
199: ),
200: );
201: $this->_inner = array (
202: -1 =>
203: array (
204: 0 => 'string',
205: 1 => 'string',
206: 2 => 'string',
207: 3 => 'string',
208: 4 => 'code',
209: 5 => 'code',
210: 6 => 'identifier',
211: 7 => 'identifier',
212: 8 => 'number',
213: 9 => 'number',
214: 10 => 'number',
215: 11 => 'number',
216: 12 => 'number',
217: 13 => 'number',
218: 14 => 'comment',
219: ),
220: 0 =>
221: array (
222: 0 => 'special',
223: ),
224: 1 =>
225: array (
226: 0 => 'special',
227: ),
228: 2 =>
229: array (
230: 0 => 'special',
231: ),
232: 3 =>
233: array (
234: 0 => 'special',
235: ),
236: 4 =>
237: array (
238: 0 => 'string',
239: 1 => 'string',
240: 2 => 'string',
241: 3 => 'string',
242: 4 => 'code',
243: 5 => 'code',
244: 6 => 'identifier',
245: 7 => 'identifier',
246: 8 => 'number',
247: 9 => 'number',
248: 10 => 'number',
249: 11 => 'number',
250: 12 => 'number',
251: 13 => 'number',
252: 14 => 'comment',
253: ),
254: 5 =>
255: array (
256: 0 => 'string',
257: 1 => 'string',
258: 2 => 'string',
259: 3 => 'string',
260: 4 => 'code',
261: 5 => 'code',
262: 6 => 'identifier',
263: 7 => 'identifier',
264: 8 => 'number',
265: 9 => 'number',
266: 10 => 'number',
267: 11 => 'number',
268: 12 => 'number',
269: 13 => 'number',
270: 14 => 'comment',
271: ),
272: );
273: $this->_end = array (
274: 0 => '/(?i)\'\'\'/',
275: 1 => '/(?i)"""/',
276: 2 => '/(?i)"/',
277: 3 => '/(?i)\'/',
278: 4 => '/(?i)\\)/',
279: 5 => '/(?i)\\]/',
280: );
281: $this->_states = array (
282: -1 =>
283: array (
284: 0 => 0,
285: 1 => 1,
286: 2 => 2,
287: 3 => 3,
288: 4 => 4,
289: 5 => 5,
290: 6 => -1,
291: 7 => -1,
292: 8 => -1,
293: 9 => -1,
294: 10 => -1,
295: 11 => -1,
296: 12 => -1,
297: 13 => -1,
298: 14 => -1,
299: ),
300: 0 =>
301: array (
302: 0 => -1,
303: ),
304: 1 =>
305: array (
306: 0 => -1,
307: ),
308: 2 =>
309: array (
310: 0 => -1,
311: ),
312: 3 =>
313: array (
314: 0 => -1,
315: ),
316: 4 =>
317: array (
318: 0 => 0,
319: 1 => 1,
320: 2 => 2,
321: 3 => 3,
322: 4 => 4,
323: 5 => 5,
324: 6 => -1,
325: 7 => -1,
326: 8 => -1,
327: 9 => -1,
328: 10 => -1,
329: 11 => -1,
330: 12 => -1,
331: 13 => -1,
332: 14 => -1,
333: ),
334: 5 =>
335: array (
336: 0 => 0,
337: 1 => 1,
338: 2 => 2,
339: 3 => 3,
340: 4 => 4,
341: 5 => 5,
342: 6 => -1,
343: 7 => -1,
344: 8 => -1,
345: 9 => -1,
346: 10 => -1,
347: 11 => -1,
348: 12 => -1,
349: 13 => -1,
350: 14 => -1,
351: ),
352: );
353: $this->_keywords = array (
354: -1 =>
355: array (
356: 0 => -1,
357: 1 => -1,
358: 2 => -1,
359: 3 => -1,
360: 4 => -1,
361: 5 => -1,
362: 6 =>
363: array (
364: 'builtin' => '/^(__import__|abs|apply|basestring|bool|buffer|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|min|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|round|setattr|slice|staticmethod|sum|super|str|tuple|type|unichr|unicode|vars|xrange|zip)$/',
365: ),
366: 7 =>
367: array (
368: 'reserved' => '/^(and|del|for|is|raise|assert|elif|from|lambda|return|break|else|global|not|try|class|except|if|or|while|continue|exec|import|pass|yield|def|finally|in|print|False|True|None|NotImplemented|Ellipsis|Exception|SystemExit|StopIteration|StandardError|KeyboardInterrupt|ImportError|EnvironmentError|IOError|OSError|WindowsError|EOFError|RuntimeError|NotImplementedError|NameError|UnboundLocalError|AttributeError|SyntaxError|IndentationError|TabError|TypeError|AssertionError|LookupError|IndexError|KeyError|ArithmeticError|OverflowError|ZeroDivisionError|FloatingPointError|ValueError|UnicodeError|UnicodeEncodeError|UnicodeDecodeError|UnicodeTranslateError|ReferenceError|SystemError|MemoryError|Warning|UserWarning|DeprecationWarning|PendingDeprecationWarning|SyntaxWarning|OverflowWarning|RuntimeWarning|FutureWarning)$/',
369: ),
370: 8 =>
371: array (
372: ),
373: 9 =>
374: array (
375: ),
376: 10 =>
377: array (
378: ),
379: 11 =>
380: array (
381: ),
382: 12 =>
383: array (
384: ),
385: 13 =>
386: array (
387: ),
388: 14 =>
389: array (
390: ),
391: ),
392: 0 =>
393: array (
394: 0 =>
395: array (
396: ),
397: ),
398: 1 =>
399: array (
400: 0 =>
401: array (
402: ),
403: ),
404: 2 =>
405: array (
406: 0 =>
407: array (
408: ),
409: ),
410: 3 =>
411: array (
412: 0 =>
413: array (
414: ),
415: ),
416: 4 =>
417: array (
418: 0 => -1,
419: 1 => -1,
420: 2 => -1,
421: 3 => -1,
422: 4 => -1,
423: 5 => -1,
424: 6 =>
425: array (
426: 'builtin' => '/^(__import__|abs|apply|basestring|bool|buffer|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|min|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|round|setattr|slice|staticmethod|sum|super|str|tuple|type|unichr|unicode|vars|xrange|zip)$/',
427: ),
428: 7 =>
429: array (
430: 'reserved' => '/^(and|del|for|is|raise|assert|elif|from|lambda|return|break|else|global|not|try|class|except|if|or|while|continue|exec|import|pass|yield|def|finally|in|print|False|True|None|NotImplemented|Ellipsis|Exception|SystemExit|StopIteration|StandardError|KeyboardInterrupt|ImportError|EnvironmentError|IOError|OSError|WindowsError|EOFError|RuntimeError|NotImplementedError|NameError|UnboundLocalError|AttributeError|SyntaxError|IndentationError|TabError|TypeError|AssertionError|LookupError|IndexError|KeyError|ArithmeticError|OverflowError|ZeroDivisionError|FloatingPointError|ValueError|UnicodeError|UnicodeEncodeError|UnicodeDecodeError|UnicodeTranslateError|ReferenceError|SystemError|MemoryError|Warning|UserWarning|DeprecationWarning|PendingDeprecationWarning|SyntaxWarning|OverflowWarning|RuntimeWarning|FutureWarning)$/',
431: ),
432: 8 =>
433: array (
434: ),
435: 9 =>
436: array (
437: ),
438: 10 =>
439: array (
440: ),
441: 11 =>
442: array (
443: ),
444: 12 =>
445: array (
446: ),
447: 13 =>
448: array (
449: ),
450: 14 =>
451: array (
452: ),
453: ),
454: 5 =>
455: array (
456: 0 => -1,
457: 1 => -1,
458: 2 => -1,
459: 3 => -1,
460: 4 => -1,
461: 5 => -1,
462: 6 =>
463: array (
464: 'builtin' => '/^(__import__|abs|apply|basestring|bool|buffer|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|min|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|round|setattr|slice|staticmethod|sum|super|str|tuple|type|unichr|unicode|vars|xrange|zip)$/',
465: ),
466: 7 =>
467: array (
468: 'reserved' => '/^(and|del|for|is|raise|assert|elif|from|lambda|return|break|else|global|not|try|class|except|if|or|while|continue|exec|import|pass|yield|def|finally|in|print|False|True|None|NotImplemented|Ellipsis|Exception|SystemExit|StopIteration|StandardError|KeyboardInterrupt|ImportError|EnvironmentError|IOError|OSError|WindowsError|EOFError|RuntimeError|NotImplementedError|NameError|UnboundLocalError|AttributeError|SyntaxError|IndentationError|TabError|TypeError|AssertionError|LookupError|IndexError|KeyError|ArithmeticError|OverflowError|ZeroDivisionError|FloatingPointError|ValueError|UnicodeError|UnicodeEncodeError|UnicodeDecodeError|UnicodeTranslateError|ReferenceError|SystemError|MemoryError|Warning|UserWarning|DeprecationWarning|PendingDeprecationWarning|SyntaxWarning|OverflowWarning|RuntimeWarning|FutureWarning)$/',
469: ),
470: 8 =>
471: array (
472: ),
473: 9 =>
474: array (
475: ),
476: 10 =>
477: array (
478: ),
479: 11 =>
480: array (
481: ),
482: 12 =>
483: array (
484: ),
485: 13 =>
486: array (
487: ),
488: 14 =>
489: array (
490: ),
491: ),
492: );
493: $this->_parts = array (
494: 0 =>
495: array (
496: 0 => NULL,
497: ),
498: 1 =>
499: array (
500: 0 => NULL,
501: ),
502: 2 =>
503: array (
504: 0 => NULL,
505: ),
506: 3 =>
507: array (
508: 0 => NULL,
509: ),
510: 4 =>
511: array (
512: 0 => NULL,
513: 1 => NULL,
514: 2 => NULL,
515: 3 => NULL,
516: 4 => NULL,
517: 5 => NULL,
518: 6 => NULL,
519: 7 => NULL,
520: 8 => NULL,
521: 9 => NULL,
522: 10 => NULL,
523: 11 => NULL,
524: 12 => NULL,
525: 13 => NULL,
526: 14 => NULL,
527: ),
528: 5 =>
529: array (
530: 0 => NULL,
531: 1 => NULL,
532: 2 => NULL,
533: 3 => NULL,
534: 4 => NULL,
535: 5 => NULL,
536: 6 => NULL,
537: 7 => NULL,
538: 8 => NULL,
539: 9 => NULL,
540: 10 => NULL,
541: 11 => NULL,
542: 12 => NULL,
543: 13 => NULL,
544: 14 => NULL,
545: ),
546: );
547: $this->_subst = array (
548: -1 =>
549: array (
550: 0 => false,
551: 1 => false,
552: 2 => false,
553: 3 => false,
554: 4 => false,
555: 5 => false,
556: 6 => false,
557: 7 => false,
558: 8 => false,
559: 9 => false,
560: 10 => false,
561: 11 => false,
562: 12 => false,
563: 13 => false,
564: 14 => false,
565: ),
566: 0 =>
567: array (
568: 0 => false,
569: ),
570: 1 =>
571: array (
572: 0 => false,
573: ),
574: 2 =>
575: array (
576: 0 => false,
577: ),
578: 3 =>
579: array (
580: 0 => false,
581: ),
582: 4 =>
583: array (
584: 0 => false,
585: 1 => false,
586: 2 => false,
587: 3 => false,
588: 4 => false,
589: 5 => false,
590: 6 => false,
591: 7 => false,
592: 8 => false,
593: 9 => false,
594: 10 => false,
595: 11 => false,
596: 12 => false,
597: 13 => false,
598: 14 => false,
599: ),
600: 5 =>
601: array (
602: 0 => false,
603: 1 => false,
604: 2 => false,
605: 3 => false,
606: 4 => false,
607: 5 => false,
608: 6 => false,
609: 7 => false,
610: 8 => false,
611: 9 => false,
612: 10 => false,
613: 11 => false,
614: 12 => false,
615: 13 => false,
616: 14 => false,
617: ),
618: );
619: $this->_conditions = array (
620: );
621: $this->_kwmap = array (
622: 'builtin' => 'builtin',
623: 'reserved' => 'reserved',
624: );
625: $this->_defClass = 'code';
626: $this->_checkDefines();
627: }
628:
629: }