Source

pygments-puppet / pygments / lexers / puppet.py

Charles McLaughl… 7907735 










Charles McLaughl… 7f72745 
Charles McLaughl… 25873d6 

Charles McLaughl… 7907735 
Charles McLaughl… 1cfe89c 
Charles McLaughl… 7907735 

Charles McLaughl… 1cfe89c 
Charles McLaughl… 7907735 






Charles McLaughl… 7f72745 
Charles McLaughl… 25873d6 


Charles McLaughl… 7f72745 
Charles McLaughl… 25873d6 
Charles McLaughl… 7f72745 
Charles McLaughl… 2be139a 
Charles McLaughl… 34d07af 
Charles McLaughl… 25873d6 
Charles McLaughl… 1cfe89c 
Charles McLaughl… 2f9f268 
Charles McLaughl… 34d07af 
Charles McLaughl… 38a9233 
Charles McLaughl… 1cfe89c 
Charles McLaughl… 7f72745 










Charles McLaughl… 25873d6 
Charles McLaughl… ae933ed 
Charles McLaughl… b6f71a5 

Charles McLaughl… 1cfe89c 
Charles McLaughl… 25873d6 

Charles McLaughl… 7cacfd7 
Charles McLaughl… 25873d6 





Charles McLaughl… 1cfe89c 
Charles McLaughl… 25873d6 
Charles McLaughl… 7f72745 


Charles McLaughl… 1cfe89c 
Charles McLaughl… 7f72745 

Charles McLaughl… 2f9f268 
Charles McLaughl… 7f72745 

Charles McLaughl… 75499ef 
Charles McLaughl… 1cfe89c 
Charles McLaughl… 75499ef 


Charles McLaughl… 1cfe89c 

# -*- coding: utf-8 -*-
"""
    pygments.lexers.puppet
    ~~~~~~~~~~~~~~~~~~~~~~

    Lexer for the Puppet DSL.

    :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""

from pygments.lexer import RegexLexer, bygroups, include
from pygments.token import Comment, Keyword, Name, Number, Operator, \
    Punctuation, String, Text


__all__ = ['PuppetLexer']


class PuppetLexer(RegexLexer):
    name = 'Puppet'
    aliases = ['puppet']
    filenames = ['*.pp']

    tokens = {
        'root': [
            include('comments'),
            include('keywords'),
            include('names'),
            include('numbers'),
            include('operators'),
            include('strings'),

            (r'[]{}:(),;[]', Punctuation),

            # FIXME end of line comments don't work on this rule
            (r'(.*)(include)(\s*)(.*)$',
             bygroups(Text, Keyword, Text, Name.Variable)),

            (r'[^\S\n]+', Text),
        ],

        'comments': [
            (r'\s*#.*$', Comment),
            (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
            ],

        'operators': [
            (r'(=>|\?|<|>|=|\+|-|\/|\*|~|!|\|)', Operator),
            (r'\s+(in|and|or|not)\s+', Operator.Word),
            ],

        'names': [
            ('[a-zA-Z_][a-zA-Z0-9_]*', Name.Attribute),
            # Vars starting with $
            (r'\$\S+', Name.Variable),
        ],

        'numbers': [
            # Copypasta from the Python lexer
            (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?j?', Number.Float),
            (r'\d+[eE][+-]?[0-9]+j?', Number.Float),
            (r'0[0-7]+j?', Number.Oct),
            (r'0[xX][a-fA-F0-9]+', Number.Hex),
            (r'\d+L', Number.Integer.Long),
            (r'\d+j?', Number.Integer)
        ],

        'keywords': [
            (r'(if|else|elsif|case|class|true|false|define)\b', Keyword),
            (r'(inherits|notice|node|realize|import)\b', Keyword),
        ],

        'strings': [
            # Quoted strings
            (r'\'(.*?)\'', String),
            (r'"(.*?)"', String),

            # TODO FIXME more than one new line breaks this
            # Multi-line quoted strings
            (r'\'(.*?)\n(.*?)\'', String),
            (r'"(.*?)\n(.*?)"', String),
        ],

    }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.