Permalink
Browse files

Initial commit

  • Loading branch information...
rodjek committed Apr 8, 2011
0 parents commit a30e1374c0c14516657b9c1ddc58fac51f77f7a4
Showing with 52 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +34 −0 puppet_lexer/__init__.py
  3. +14 −0 setup.py
@@ -0,0 +1,4 @@
+dist/
+Puppet_Pygments_Lexer.egg-info/
+build/
+*.swp
@@ -0,0 +1,34 @@
+from pygments.lexer import RegexLexer, bygroups, include
+from pygments.token import *
+
+class PuppetLexer(RegexLexer):
+ name = 'Puppet'
+ aliases = ['puppet']
+ filenames = ['*.pp']
+
+ tokens = {
+ 'root': [
+ (r' .*\n', Text),
+ (r'\s*#.*\n', Comment.Singleline),
+ (r'(class)(\s*)(.*?)(\s*)(\{)', bygroups(Keyword.Declaration, Text, Name.Class, Text, Punctuation)),
+ (r'(.*?)(\s*)(\{)(\s*)', bygroups(Name.Class, Text, Punctuation, Text), 'resource'),
+ (r'.*\n', Text),
+ ],
+ 'resource': [
+ (r'(".+?")(:)', bygroups(String, Punctuation), 'instance'),
+ (r"('.+?')(:)", bygroups(String, Punctuation), 'instance'),
+ (r'(\S+?)(:)', bygroups(String, Punctuation), 'instance'),
+ (r'\}', Punctuation, '#pop'),
+ ],
+ 'instance': [
+ (r"(\s*)(\S+?)(\s*)(=>)(\s*)(\S+)(,)", bygroups(Text, Name.Attribute, Text, Operator, Text, String, Punctuation)),
+ (r"(\s*)(\S+?)(\s*)(=>)(\s*)('.+')(,)", bygroups(Text, Name.Attribute, Text, Operator, Text, String, Punctuation)),
+ (r'(\s*)(\S+?)(\s*)(=>)(\s*)(".+")(,)', bygroups(Text, Name.Attribute, Text, Operator, Text, String, Punctuation)),
+ (r"(\s*)(\S+?)(\s*)(=>)(\s*)(\S+)(;)", bygroups(Text, Name.Attribute, Text, Operator, Text, String, Punctuation), '#pop'),
+ (r"(\s*)(\S+?)(\s*)(=>)(\s*)('.+')(;)", bygroups(Text, Name.Attribute, Text, Operator, Text, String, Punctuation), '#pop'),
+ (r'(\s*)(\S+?)(\s*)(=>)(\s*)(".+")(;)', bygroups(Text, Name.Attribute, Text, Operator, Text, String, Punctuation), '#pop'),
+ (r"(\s*)(\S+?)(\s*)(=>)(\s*)([^;'\"\s]+)", bygroups(Text, Name.Attribute, Text, Operator, Text, String)),
+ (r"(\s*)(\S+?)(\s*)(=>)(\s*)('.*')", bygroups(Text, Name.Attribute, Text, Operator, Text, String)),
+ (r'(\s*)(\S+?)(\s*)(=>)(\s*)(".+")', bygroups(Text, Name.Attribute, Text, Operator, Text, String)),
+ ],
+ }
@@ -0,0 +1,14 @@
+from setuptools import setup
+
+__author__ = 'tim@sharpe.id.au'
+
+setup(
+ name='Puppet Pygments Lexer',
+ version='0.0.1',
+ description=__doc__,
+ author=__author__,
+ packages=['puppet_lexer'],
+ entry_points='''[pygments.lexers]
+puppetlexer = puppet_lexer:PuppetLexer
+'''
+)

0 comments on commit a30e137

Please sign in to comment.