About ads on Siafoo
Hide Siafoo is here to make coding less frustrating and to save you time. Learn More Join Siafoo

Nodebox Pygments Lexer

In Brief: A simple, nigh-boilerplate Pygments lexer extending PythonLexer to include the Nodebox builtin environmental names.... more
Language Python
# 's
 1from pygments.lexers.agile import PythonLexer
2
3class NodeboxLexer(PythonLexer):
4 '''
5 An extension to the Pygments PythonLexer based on the Nodebox environment.
6
7 Creative Commons Attribution License, 2008, Theodore Test
8
9 '''
10
11 name = 'Nodebox Python'
12 aliases = ['nodebox','Nodebox']
13 filenames = ['*.py']
14
15 NODEBOX_MOD = [# Primitive Functions
16 'rect', 'line', 'star', 'oval', 'arrow',
17 # Path Functions
18 'beginpath', 'moveto', 'lineto', 'curveto',
19 'endpath', 'drawpath', 'beginclip', 'endclip',
20 'autoclosepath', 'findpath', 'closepath'
21 # Transform Functions
22 'transform', 'translate', 'rotate', 'scale',
23 'skew', 'push', 'pop', 'reset',
24 # Color Functions
25 'outputmode', 'colormode', 'fill', 'nofill',
26 'nostroke', 'strokewidth', 'background',
27 # Typography Functions
28 'font', 'fontsize', 'text', 'textpath', 'textwidth',
29 'textheight', 'textmetrics', 'lineheight', 'align',
30 # Image Functions
31 'image', 'imagesize'
32 # Utility Functions
33 'size', 'var', 'random', 'choice', 'grid',
34 'open', 'files', 'autotext'
35 # Constants
36 'BOOLEAN', 'BUTTON', 'CENTER', 'CLOSE', 'CMYK',
37 'CORNER', 'CURVETO', 'DEFAULT_HEIGHT', 'DEFAULT_WIDTH',
38 'FORTYFIVE', 'FRAME', 'HEIGHT', 'JUSTIFY',
39 'KEY_BACKSPACE', 'KEY_DOWN', 'KEY_LEFT', 'KEY_RIGHT',
40 'KEY_UP', 'LEFT', 'LINETO', 'MOUSEX', 'MOUSEY', 'MOVETO',
41 'NORMAL', 'NUMBER', 'PAGENUM', 'RGB', 'RIGHT', 'TEXT','HEIGHT'
42 # Various Classes
43 'BezierPath', 'Canvas', 'ClippingPath', 'Color',
44 'Context', 'Grob', 'Image', 'Oval', 'PathElement',
45 'Point', 'Rect', 'Text', 'Transform', 'Variable'
46 # Misc Functions
47 'addvar', 'canvas', 'cm', 'colorrange', 'findvar', 'inch',
48 'key', 'keycode', 'keydown', 'mm', 'mousedown', 'save',
49 'scale', 'scrollwheel', 'wheeldelta', 'ximport']
50
51
52
53
54 def get_tokens_unprocessed(self, text):
55 for index, token, value in PythonLexer.get_tokens_unprocessed(self, text):
56 if token is Name and value in self.NODEBOX_MOD:
57 yield index, Name.Builtin, value
58 else:
59 yield index, token, value

A simple, nigh-boilerplate Pygments lexer extending PythonLexer to include the Nodebox builtin environmental names.

Currently the basis for the Siafoo Nodebox syntax highlighting.

Keywords nodebox (7) pygments (6) lexer (6)
Included in this Library
Average
n/a
Rated
0
Times
5
4
3
2
1
0
License New BSD license
Lines 51
Owner: Theodore Test
Viewable by Everyone
Editable by All Siafoo Users
Sponsored Links
About ads on Siafoo