License New BSD license
Lines 102
Keywords
blender (1) lexer (6) pygments (6)
Included in this Library
Permissions
Owner: Stou S.
Viewable by Everyone
Editable by All Siafoo Users

Blender Python Lexer Atom Feed 0

In Brief A simple pygments lexer for highlighting blender python scripts. This lexer is supported by Siafoo.
# 's
  1"""
2Copyright 2007 (c) Siafoo.net
3
4Some lexers based on code from Pygments project, by Georg Brandl, Tim Hatch
5
6Custom Siafoo Lexers, or Lexers not implemented in Pygments
7"""
8
9from pygments.lexers.agile import PythonLexer
10from pygments.token import Error, Punctuation, Text, Comment, Operator, Keyword, Name, String, Number
11
12class BlenderLexer(PythonLexer):
13 '''
14 A lexer for Blender python builtins
15 '''
16
17 name = 'Blender Python'
18 aliases = ['blender']
19
20 BLENDER_MOD = ['Armature', 'NLA', 'Action', 'BezTriple', 'Blender', 'BGL', 'Camera', 'Curve', 'Draw', 'Effect'
21 'Geometry', 'Group', 'Image', 'Ipo', 'IpoCurve', 'Key', 'Lamp', 'Lattice', 'Library',
22 'Material', 'Mathutils', 'Mesh', 'MeshPrimitives', 'Metaball', 'NMesh', 'Noise', 'Object',
23 'Modifier', 'Pose', 'Constraint', 'ActionStrips', 'Registry', 'Scene', 'Radio', 'Render',
24 'Sound', 'Text', 'Text3d', 'Font', 'Texture', 'TimeLine', 'Types', 'Window', 'Theme',
25 'World', 'bpy', 'sys',
26 # Sub modules and classes
27 'Blender_CountPackedFiles', 'Get', 'Load', 'PackAll', 'Quit', 'Redraw', 'Run', 'Save', 'Set', 'ShowHelp', 'UnpackAll', 'UpdateMenus', # Blender
28 'Bone', 'BonesDict', 'Editbone', # Armature
29 'ActionStrip', 'ActionStrips', 'CopyAction', 'GetActions', 'NewAction', # Armature - > NLA
30 'glAccum', 'glAlphaFunc', 'glAreTexturesResident', 'glBegin', 'glBindTexture', 'glBitmap', 'glBlendFunc', 'glCallList',
31 'glCallLists', 'glClear', 'glClearAccum', 'glClearColor', 'glClearDepth', 'glClearIndex', 'glClearStencil', 'glClipPlane',
32 'glColor3b', 'glColor3d', 'glColor3f', 'glColor3i', 'glColor3s', 'glColor3ub', 'glColor3ui', 'glColor3us', 'glColor4b',
33 'glColor4d', 'glColor4f', 'glColor4i', 'glColor4s', 'glColor4ub', 'glColor4ui', 'glColor4us', 'glColor3bv', 'glColor3dv',
34 'glColor3fv', 'glColor3iv', 'glColor3sv', 'glColor3ubv', 'glColor3uiv', 'glColor3usv', 'glColor4bv', 'glColor4dv', 'glColor4fv',
35 'glColor4iv', 'glColor4sv', 'glColor4ubv', 'glColor4uiv', 'glColor4usv', 'glColorMask', 'glColorMaterial', 'glCopyPixels',
36 'glCullFace', 'glDeleteLists', 'glDeleteTextures', 'glDepthFunc', 'glDepthMask', 'glDepthRange', 'glDisable', 'glDrawBuffer',
37 'glDrawPixels', 'glEdgeFlag', 'glEdgeFlagv', 'glEnable', 'glEnd', 'glEndList', 'glEvalCoord1d', 'glEvalCoord1f', 'glEvalCoord2d',
38 'glEvalCoord2f', 'glEvalCoord1dv', 'glEvalCoord1fv', 'glEvalCoord2dv', 'glEvalCoord2fv', 'glEvalMesh1', 'glEvalMesh2', 'glEvalPoint',
39 'glEvalPoint1', 'glEvalPoint2', 'glFeedbackBuffer', 'glFinish', 'glFlush', 'glFog', 'glFogf', 'glFogi', 'glFogfv', 'glFogiv',
40 'glFrontFace', 'glFrustum', 'glGenLists', 'glGenTextures', 'glGetBooleanv', 'glGetfloatv', 'glGetFloatv', 'glGetIntegerv',
41 'glGetClipPlane', 'glGetError', 'glGetLightfv', 'glGetLightiv', 'glGetMap', 'glGetMapdv', 'glGetMapfv', 'glGetMapiv', 'glGetMaterial',
42 'glGetMaterialfv', 'glGetMaterialiv', 'glGetPixelMap', 'glGetPixelMapfv', 'glGetPixelMapuiv', 'glGetPixelMapusv', 'glGetPolygonStipple',
43 'glGetString', 'glGetTexEnv', 'glGetTexEnvfv', 'glGetTexEnviv', 'glGetTexGen', 'glGetTexGendv', 'glGetTexGenfv', 'glGetTexGeniv',
44 'glGetTexImage', 'glGetTexLevelParameterfv', 'glGetTexLevelParameteriv', 'glGetTexParameterfv', 'glGetTexParameteriv', 'glHint',
45 'glIndexd', 'glIndexf', 'glIndexi', 'glIndexs', 'glIndexdv', 'glIndexfv', 'glIndexiv', 'glIndexsv', 'glInitNames', 'glIsEnabled',
46 'glIsList', 'glIsTexture', 'glLightf', 'glLighti', 'glLightfv', 'glLightiv', 'glLightModelf', 'glLightModeli', 'glLightModelfv',
47 'glLightModeliv', 'glLineStipple', 'glLineWidth', 'glListBase', 'glLoadIdentity', 'glLoadMatrixd', 'glLoadMatixf', 'glLoadName',
48 'glLogicOp', 'glMap1d', 'glMap1f', 'glMap2d', 'glMap2f', 'glMapGrid1d', 'glMapGrid1f', 'glMapGrid2d', 'glMapGrid2f', 'glMaterial',
49 'glMatrixMode', 'glMultMatrixd', 'glMultMatrixf', 'glNewList', 'glNormal3b', 'glNormal3bv', 'glNormal3d', 'glNormal3dv', 'glNormal3f',
50 'glNormal3fv', 'glNormal3i', 'glNormal3iv', 'glNormal3s', 'glNormal3sv''glOrtho', 'glPassThrough', 'glPixelMapfv', 'glPixelMapuiv',
51 'glPixelMapusv', 'glPixelStoref', 'glPixelStorei', 'glPixelTransferf', 'glPixelTransferi', 'glPixelZoom', 'glPointSize', 'glPolygonMode',
52 'glPolygonOffset', 'glPolygonStipple', 'glPopAttrib', 'glPopMatrix', 'glPopName', 'glPrioritizeTextures', 'glPushAttrib', 'glPushMatrix',
53 'glPushName', 'glRasterPos2d', 'glRasterPos2f', 'glRasterPos2i', 'glRasterPos2s', 'glRasterPos3d', 'glRasterPos3f', 'glRasterPos3i',
54 'glRasterPos3s', 'glRasterPos4d', 'glRasterPos4f', 'glRasterPos4i', 'glRasterPos4s', 'glRasterPos2dv', 'glRasterPos2fv', 'glRasterPos2iv',
55 'glRasterPos2sv', 'glRasterPos3dv', 'glRasterPos3fv', 'glRasterPos3iv', 'glRasterPos3sv', 'glRasterPos4dv', 'glRasterPos4fv',
56 'glRasterPos4iv', 'glRasterPos4sv', 'glReadBuffer', 'glReadPixels', 'glRectd', 'glRectf', 'glRecti', 'glRects', 'glRectdv', 'glRectfv',
57 'glRectiv', 'glRectsv', 'glRenderMode', 'glRotated', 'glRotatef', 'glScaled', 'glScalef', 'glScissor', 'glSelectBuffer', 'glShadeModel',
58 'glStencilFuc', 'glStencilMask', 'glStencilOp', 'glTexCoord1d', 'glTexCoord1f', 'glTexCoord1i', 'glTexCoord1s', 'glTexCoord2d', 'glTexCoord2f',
59 'glTexCoord2i', 'glTexCoord2s', 'glTexCoord3d', 'glTexCoord3f', 'glTexCoord3i', 'glTexCoord3s', 'glTexCoord4d', 'glTexCoord4f', 'glTexCoord4i',
60 'glTexCoord4s', 'glTexCoord1dv', 'glTexCoord1fv', 'glTexCoord1iv', 'glTexCoord1sv', 'glTexCoord2dv', 'glTexCoord2fv', 'glTexCoord2iv',
61 'glTexCoord2sv', 'glTexCoord3dv', 'glTexCoord3fv', 'glTexCoord3iv', 'glTexCoord3sv', 'glTexCoord4dv', 'glTexCoord4fv', 'glTexCoord4iv',
62 'glTexCoord4sv', 'glTextEnvf', 'glTextEnvi', 'glTextEnvfv', 'glTextEnviv', 'glTexGend', 'glTexGenf', 'glTexGeni', 'glTexGendv', 'glTexGenfv',
63 'glTexGeniv', 'glTexImage1D', 'glTexImage2D', 'glTexParameterf', 'glTexParameteri', 'glTexParameterfv', 'glTexParameteriv', 'glTranslatef',
64 'glTranslated', 'gluLookAt', 'gluOrtho2D', 'gluPerspective', 'gluPickMatrix', 'gluProject', 'gluUnProject', 'glVertex2d','glVertex2f',
65 'glVertex2i', 'glVertex2s', 'glVertex3d', 'glVertex3f', 'glVertex3i', 'glVertex3s', 'glVertex4d', 'glVertex4f', 'glVertex4i', 'glVertex4s',
66 'glVertex2dv', 'glVertex2fv', 'glVertex2iv', 'glVertex2sv', 'glVertex3dv', 'glVertex3fv', 'glVertex3iv', 'glVertex3sv', 'glVertex4dv',
67 'glVertex4fv', 'glVertex4iv', 'glVertex4sv', 'glViewport', # BGL
68 'Constraints', # Constraints
69 'CurNurb', 'SurfNurb', # Curve
70 'BeginAlign', 'ColorPicker', 'Create', 'EndAlign', 'Exit', 'GetStringWidth', 'Image', 'NoneLabel', 'Menu', 'Normal', 'Number', 'PupBlock',
71 'PupFloatInput', 'PupIntInput', 'PupMenu', 'PupStrInput', 'PushButton', 'Redraw', 'Slider', 'String', 'Toggle', 'UIBlock', # Draw
72 'BoxPack2D', 'LineIntersect2D', 'PointInTriangle2D', 'PolyFill', # Geometry
73 'KeyBlock', # Key
74 'Euler', 'Matrix', 'Quaternion', 'Vector', 'AngleBetweenVecs', 'CopyEuler', 'CopyMat', 'CopyQuat', 'CopyVec', 'CrossQuats', 'CrossVecs',
75 'DifferenceQuats', 'DotQuats', 'DotVecs', 'Intersect', 'MatMultVec', 'MidpointVecs', 'OrthoProjectionMatrix', 'ProjectVecs', 'QuadNormal',
76 'Rand', 'RotateEuler', 'RotationMatrix', 'ScaleMatrix', 'ShearMatrix', 'Slerp', 'TranslationMatrix', 'TriangleArea', 'TriangleNormal', 'VecMultMat' # Mathutils
77 'MCol', 'MEdge', 'MEdgeSeq', 'Mesh', 'MFace', 'MFaceSeq', 'MVert', 'MVertSeq', # Mesh module
78 'Circle', 'Cone', 'Cube', 'Cylinder', 'Grid', 'Icosphere', 'Monkey', 'Plane', 'Tube', 'UVsphere', # Mesh Primitives
79 'Metaelem', 'MetaElemSeq', # Metaball
80 'ModSeq', # Modifier
81 'NMCol', 'NMEdge', 'NMFace', 'NMVert', 'Col', 'Face', 'GetNames', 'GetRaw', 'GetRawFromObject', 'PutRaw', 'Vert', # NMesh
82 'cellNoise', 'cellNoiseV', 'fBm', 'heteroTerrain', 'hybridMFractal', 'multiFractal', 'noise', 'random', 'randuvec',
83 'ridgedMFractal', 'setRandomSeed', 'turbulence', 'vlNoise', 'vNoise', 'voronoi', 'vTurbulence', # Noise
84 'Close', 'Datablocks', 'getName', 'LinkableGroups', 'Open', 'Update', # Library
85 'PoseBone', 'PoseBonesDict', # Pose
86 'GetKey', 'Keys', 'RemoveKey', 'SetKey', # Registry
87 'RenderData', 'CloseRenderWindow', 'EnableDispView', 'EnableDispWin', 'EnableEdgeAll', 'EnableEdgeShift', 'SetRenderWinPos', # Render
88 'SceneObjects', 'Unlink', # Scene
89 'MTex', # Texture
90 'ThemeSpace', 'ThemeUI' # Theme
91 'ArmatureType', 'BoneType', 'bufferType', 'ButtonType', 'CameraType', 'constantType', 'CurveType', 'eulerType', 'GroupType', 'IDArrayType',
92 'IDGroupType', 'ImageType', 'IpoType', 'LampType', 'MaterialType', 'matrix_Type', 'MColType', 'MEdgeType', 'MeshType', 'MetaballType',
93 'MFaceType', 'MTexType', 'MVertType', 'NMColType', 'NMeshType', 'NMFaceType', 'NMVertType', 'ObjectType', 'PVertType', 'quaternionType',
94 'rgbTupleType', 'SceneType', 'Text3dType', 'TextType', 'TextureType', # Type
95 'CameraView', 'DrawProgressBar', 'EditMode', 'FileSelector', 'GetActiveLayer', 'GetAreaID', 'GetAreaSize', 'GetCursorPos', 'GetKeyQualifiers',
96 'GetMouseButtons', 'GetMouseCoords', 'GetPerspMatrix', 'GetScreens', 'GetScreenSize', 'GetViewMatrix', 'GetViewOffset', 'GetViewQuat',
97 'GetViewVector', 'ImageSelector', 'QAdd', 'QHandle', 'QRead', 'QRedrawAll', 'QTest', 'Redraw', 'RedrawAll', 'SetActiveLayer', 'SetCursorPos',
98 'SetKeyQualifiers', 'SetMouseCoords', 'SetScreen', 'SetViewOffset', 'SetViewQuat', 'ViewLayers', 'WaitCursor', # Window
99 'basename', 'dirname', 'exists', 'expandpath', 'join', 'makename', 'sleep', 'splitext', 'time', # sys
100 'GetCurrent', 'New', 'unlink' # Font, 'Material', Metaball, Sound, Text, Theme, World
101 ]
102
103 def get_tokens_unprocessed(self, text):
104 for index, token, value in PythonLexer.get_tokens_unprocessed(self, text):
105 if token is Name and value in self.BLENDER_MOD:
106 yield index, Name.Builtin, value
107 else:
108 yield index, token, value

A simple pygments lexer for highlighting blender python scripts. This lexer is supported by Siafoo.