diff options
author | Diego Zamboni <diego@zzamboni.org> | 2011-08-08 09:13:14 -0500 |
---|---|---|
committer | Diego Zamboni <diego@zzamboni.org> | 2011-08-08 09:13:14 -0500 |
commit | dcd3c26c20a912e8665e4efed00b445fa83a08bd (patch) | |
tree | edcd543c9efd175f860c7db59edc078e06c7f46d | |
parent | bcc9247239b5260f306e37181956c7d0f059ba85 (diff) | |
download | pygments-dcd3c26c20a912e8665e4efed00b445fa83a08bd.tar.gz |
Added lexer for CFEngine3 files (http://cfengine.org/)
-rw-r--r-- | pygments/lexers/_mapping.py | 1 | ||||
-rw-r--r-- | pygments/lexers/other.py | 60 |
2 files changed, 60 insertions, 1 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 933404d7..5878e135 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -46,6 +46,7 @@ LEXERS = { 'CObjdumpLexer': ('pygments.lexers.asm', 'c-objdump', ('c-objdump',), ('*.c-objdump',), ('text/x-c-objdump',)), 'CSharpAspxLexer': ('pygments.lexers.dotnet', 'aspx-cs', ('aspx-cs',), ('*.aspx', '*.asax', '*.ascx', '*.ashx', '*.asmx', '*.axd'), ()), 'CSharpLexer': ('pygments.lexers.dotnet', 'C#', ('csharp', 'c#'), ('*.cs',), ('text/x-csharp',)), + 'Cfengine3Lexer': ('pygments.lexers.other', 'CFEngine3', ('cfengine3', 'cf3'), ('*.cf',), ()), 'CheetahHtmlLexer': ('pygments.lexers.templates', 'HTML+Cheetah', ('html+cheetah', 'html+spitfire'), (), ('text/html+cheetah', 'text/html+spitfire')), 'CheetahJavascriptLexer': ('pygments.lexers.templates', 'JavaScript+Cheetah', ('js+cheetah', 'javascript+cheetah', 'js+spitfire', 'javascript+spitfire'), (), ('application/x-javascript+cheetah', 'text/x-javascript+cheetah', 'text/javascript+cheetah', 'application/x-javascript+spitfire', 'text/x-javascript+spitfire', 'text/javascript+spitfire')), 'CheetahLexer': ('pygments.lexers.templates', 'Cheetah', ('cheetah', 'spitfire'), ('*.tmpl', '*.spt'), ('application/x-cheetah', 'application/x-spitfire')), diff --git a/pygments/lexers/other.py b/pygments/lexers/other.py index 9c6209a1..52ae3841 100644 --- a/pygments/lexers/other.py +++ b/pygments/lexers/other.py @@ -26,7 +26,8 @@ __all__ = ['SqlLexer', 'MySqlLexer', 'SqliteConsoleLexer', 'BrainfuckLexer', 'BashSessionLexer', 'ModelicaLexer', 'RebolLexer', 'ABAPLexer', 'NewspeakLexer', 'GherkinLexer', 'AsymptoteLexer', 'PostScriptLexer', 'AutohotkeyLexer', 'GoodDataCLLexer', - 'MaqlLexer', 'ProtoBufLexer', 'HybrisLexer', 'AwkLexer'] + 'MaqlLexer', 'ProtoBufLexer', 'HybrisLexer', 'AwkLexer', + 'Cfengine3Lexer'] line_re = re.compile('.*?\n') @@ -2904,3 +2905,60 @@ class AwkLexer(RegexLexer): (r"'(\\\\|\\'|[^'])*'", String.Single), ] } + +class Cfengine3Lexer(RegexLexer): + """ + Lexer for `CFEngine3 <http://cfengine.org>`_ policy files. + + """ + + 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'\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), + ], + } |