diff options
Diffstat (limited to 'pygments/lexers/configs.py')
-rw-r--r-- | pygments/lexers/configs.py | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/pygments/lexers/configs.py b/pygments/lexers/configs.py index e4f18803..44408199 100644 --- a/pygments/lexers/configs.py +++ b/pygments/lexers/configs.py @@ -9,11 +9,11 @@ :license: BSD, see LICENSE for details. """ -from pygments.lexer import RegexLexer, default, words +from pygments.lexer import RegexLexer, default, words, bygroups from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation -__all__ = ['KconfigLexer'] +__all__ = ['KconfigLexer', 'Cfengine3Lexer'] def _rx_indent(level): @@ -103,3 +103,64 @@ class KconfigLexer(RegexLexer): 'indent2': do_indent(2), 'indent1': do_indent(1), } + + +class Cfengine3Lexer(RegexLexer): + """ + Lexer for `CFEngine3 <http://cfengine.org>`_ policy files. + + .. versionadded:: 1.5 + """ + + name = 'CFEngine3' + aliases = ['cfengine3', 'cf3'] + filenames = ['*.cf'] + mimetypes = [] + + tokens = { + 'root': [ + (r'#.*?\n', Comment), + (r'(body)(\s+)(\S+)(\s+)(control)', + bygroups(Keyword, Text, Keyword, Text, Keyword)), + (r'(body|bundle)(\s+)(\S+)(\s+)(\w+)(\()', + bygroups(Keyword, Text, Keyword, Text, Name.Function, Punctuation), + 'arglist'), + (r'(body|bundle)(\s+)(\S+)(\s+)(\w+)', + bygroups(Keyword, Text, Keyword, Text, Name.Function)), + (r'(")([^"]+)(")(\s+)(string|slist|int|real)(\s*)(=>)(\s*)', + bygroups(Punctuation, Name.Variable, Punctuation, + Text, Keyword.Type, Text, Operator, Text)), + (r'(\S+)(\s*)(=>)(\s*)', + bygroups(Keyword.Reserved, Text, Operator, Text)), + (r'"', String, 'string'), + (r'(\w+)(\()', bygroups(Name.Function, Punctuation)), + (r'([\w.!&|\(\)]+)(::)', bygroups(Name.Class, Punctuation)), + (r'(\w+)(:)', bygroups(Keyword.Declaration, Punctuation)), + (r'@[\{\(][^\)\}]+[\}\)]', Name.Variable), + (r'[(){},;]', Punctuation), + (r'=>', Operator), + (r'->', Operator), + (r'\d+\.\d+', Number.Float), + (r'\d+', Number.Integer), + (r'\w+', Name.Function), + (r'\s+', Text), + ], + 'string': [ + (r'\$[\{\(]', String.Interpol, 'interpol'), + (r'\\.', String.Escape), + (r'"', String, '#pop'), + (r'\n', String), + (r'.', String), + ], + 'interpol': [ + (r'\$[\{\(]', String.Interpol, '#push'), + (r'[\}\)]', String.Interpol, '#pop'), + (r'[^\$\{\(\)\}]+', String.Interpol), + ], + 'arglist': [ + (r'\)', Punctuation, '#pop'), + (r',', Punctuation), + (r'\w+', Name.Variable), + (r'\s+', Text), + ], + } |