summaryrefslogtreecommitdiffstats
path: root/contrib/pygments_crmsh_lexers
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/pygments_crmsh_lexers')
-rw-r--r--contrib/pygments_crmsh_lexers/__init__.py3
-rw-r--r--contrib/pygments_crmsh_lexers/ansiclr.py50
-rw-r--r--contrib/pygments_crmsh_lexers/crmsh.py88
3 files changed, 141 insertions, 0 deletions
diff --git a/contrib/pygments_crmsh_lexers/__init__.py b/contrib/pygments_crmsh_lexers/__init__.py
new file mode 100644
index 0000000..938d6e8
--- /dev/null
+++ b/contrib/pygments_crmsh_lexers/__init__.py
@@ -0,0 +1,3 @@
+from __future__ import unicode_literals
+from .ansiclr import ANSIColorsLexer
+from .crmsh import CrmshLexer
diff --git a/contrib/pygments_crmsh_lexers/ansiclr.py b/contrib/pygments_crmsh_lexers/ansiclr.py
new file mode 100644
index 0000000..b30ee85
--- /dev/null
+++ b/contrib/pygments_crmsh_lexers/ansiclr.py
@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+"""
+ pygments.lexers.console
+ ~~~~~~~~~~~~~~~~~~~~~~~
+
+ Lexers for misc console output.
+
+ :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+from __future__ import unicode_literals
+
+from pygments.lexer import RegexLexer, bygroups
+from pygments.token import Generic, Text
+
+__all__ = ['ANSIColorsLexer']
+
+_ESC = "\x1b\["
+# this is normally to reset (reset attributes, set primary font)
+# there could be however other reset sequences and in that case
+# sgr0 needs to be updated
+_SGR0 = "%s(?:0;10|10;0)m" % _ESC
+# BLACK RED GREEN YELLOW
+# BLUE MAGENTA CYAN WHITE
+_ANSI_COLORS = (Generic.Emph, Generic.Error, Generic.Inserted, Generic.Keyword,
+ Generic.Keyword, Generic.Prompt, Generic.Traceback, Generic.Output)
+
+
+def _ansi2rgb(lexer, match):
+ code = match.group(1)
+ text = match.group(2)
+ yield match.start(), _ANSI_COLORS[int(code)-30], text
+
+
+class ANSIColorsLexer(RegexLexer):
+ """
+ Interpret ANSI colors.
+ """
+ name = 'ANSI Colors'
+ aliases = ['ansiclr']
+ filenames = ["*.typescript"]
+
+ tokens = {
+ 'root': [
+ (r'%s(3[0-7]+)m(.*?)%s' % (_ESC, _SGR0), _ansi2rgb),
+ (r'[^\x1b]+', Text),
+ # drop the rest of the graphic codes
+ (r'(%s[0-9;]+m)()' % _ESC, bygroups(None, Text)),
+ ]
+ }
diff --git a/contrib/pygments_crmsh_lexers/crmsh.py b/contrib/pygments_crmsh_lexers/crmsh.py
new file mode 100644
index 0000000..d4f1b14
--- /dev/null
+++ b/contrib/pygments_crmsh_lexers/crmsh.py
@@ -0,0 +1,88 @@
+# -*- coding: utf-8 -*-
+"""
+ pygments.lexers.dsls
+ ~~~~~~~~~~~~~~~~~~~~
+
+ Lexers for various domain-specific languages.
+
+ :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+from __future__ import unicode_literals
+
+
+from pygments.lexer import RegexLexer, bygroups, words
+from pygments.token import Comment, Operator, Keyword, Name, String, Number, Punctuation, Whitespace
+
+__all__ = ['CrmshLexer']
+
+
+class CrmshLexer(RegexLexer):
+ """
+ Lexer for `crmsh <http://crmsh.github.io/>`_ configuration files
+ for Pacemaker clusters.
+
+ .. versionadded:: 2.1
+ """
+ name = 'Crmsh'
+ aliases = ['crmsh', 'pcmk']
+ filenames = ['*.crmsh', '*.pcmk']
+ mimetypes = []
+
+ elem = words((
+ 'node', 'primitive', 'group', 'clone', 'ms', 'location',
+ 'colocation', 'order', 'fencing_topology', 'rsc_ticket',
+ 'rsc_template', 'property', 'rsc_defaults',
+ 'op_defaults', 'acl_target', 'acl_group', 'user', 'role',
+ 'tag'), suffix=r'(?![\w#$-])')
+ sub = words((
+ 'params', 'meta', 'operations', 'op', 'rule',
+ 'attributes', 'utilization'), suffix=r'(?![\w#$-])')
+ acl = words(('read', 'write', 'deny'), suffix=r'(?![\w#$-])')
+ bin_rel = words(('and', 'or'), suffix=r'(?![\w#$-])')
+ un_ops = words(('defined', 'not_defined'), suffix=r'(?![\w#$-])')
+ date_exp = words(('in_range', 'date', 'spec', 'in'), suffix=r'(?![\w#$-])')
+ acl_mod = (r'(?:tag|ref|reference|attribute|type|xpath)')
+ bin_ops = (r'(?:lt|gt|lte|gte|eq|ne)')
+ val_qual = (r'(?:string|version|number)')
+ rsc_role_action = (r'(?:Master|Started|Slave|Stopped|'
+ r'start|promote|demote|stop)')
+
+ tokens = {
+ 'root': [
+ (r'^#.*\n?', Comment),
+ # attr=value (nvpair)
+ (r'([\w#$-]+)(=)("(?:""|[^"])*"|\S+)',
+ bygroups(Name.Attribute, Punctuation, String)),
+ # need this construct, otherwise numeric node ids
+ # are matched as scores
+ # elem id:
+ (r'(node)(\s+)([\w#$-]+)(:)',
+ bygroups(Keyword, Whitespace, Name, Punctuation)),
+ # scores
+ (r'([+-]?([0-9]+|inf)):', Number),
+ # keywords (elements and other)
+ (elem, Keyword),
+ (sub, Keyword),
+ (acl, Keyword),
+ # binary operators
+ (r'(?:%s:)?(%s)(?![\w#$-])' % (val_qual, bin_ops),
+ Operator.Word),
+ # other operators
+ (bin_rel, Operator.Word),
+ (un_ops, Operator.Word),
+ (date_exp, Operator.Word),
+ # builtin attributes (e.g. #uname)
+ (r'#[a-z]+(?![\w#$-])', Name.Builtin),
+ # acl_mod:blah
+ (r'(%s)(:)("(?:""|[^"])*"|\S+)' % acl_mod,
+ bygroups(Keyword, Punctuation, Name)),
+ # rsc_id[:(role|action)]
+ # NB: this matches all other identifiers
+ (r'([\w#$-]+)(?:(:)(%s))?(?![\w#$-])' % rsc_role_action,
+ bygroups(Name, Punctuation, Operator.Word)),
+ # punctuation
+ (r'(\\(?=\n)|[[\](){}/:@])', Punctuation),
+ (r'\s+|\n', Whitespace),
+ ],
+ }