diff options
author | Robin Jarry <robin.jarry@6wind.com> | 2018-06-19 12:59:57 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2019-11-28 06:51:56 +0100 |
commit | a36ec6aa83b215680c241bee30e56a6a69dffcb8 (patch) | |
tree | 5e8806902699e82c2be43b46071144cbac7d2a90 | |
parent | 6a926bbf949a5f85f8fb13098a138e7c96260e13 (diff) | |
download | pygments-git-767/6wind/yang.tar.gz |
lexers: add YANG 1.1 support767/6wind/yang
Based on https://tools.ietf.org/html/rfc7950#page-184
-rw-r--r-- | pygments/lexers/_mapping.py | 1 | ||||
-rw-r--r-- | pygments/lexers/_mapping.py.rej | 10 | ||||
-rw-r--r-- | pygments/lexers/yang.py | 64 |
3 files changed, 75 insertions, 0 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index acb71ad9..61103d37 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -476,6 +476,7 @@ LEXERS = { 'XtlangLexer': ('pygments.lexers.lisp', 'xtlang', ('extempore',), ('*.xtm',), ()), 'YamlJinjaLexer': ('pygments.lexers.templates', 'YAML+Jinja', ('yaml+jinja', 'salt', 'sls'), ('*.sls',), ('text/x-yaml+jinja', 'text/x-sls')), 'YamlLexer': ('pygments.lexers.data', 'YAML', ('yaml',), ('*.yaml', '*.yml'), ('text/x-yaml',)), + 'YangLexer': ('pygments.lexers.yang', 'YANG', ('yang', 'Yang'), ('*.yang',), ('application/yang',)), 'ZeekLexer': ('pygments.lexers.dsls', 'Zeek', ('zeek', 'bro'), ('*.zeek', '*.bro'), ()), 'ZephirLexer': ('pygments.lexers.php', 'Zephir', ('zephir',), ('*.zep',), ()), 'ZigLexer': ('pygments.lexers.zig', 'Zig', ('zig',), ('*.zig',), ('text/zig',)), diff --git a/pygments/lexers/_mapping.py.rej b/pygments/lexers/_mapping.py.rej new file mode 100644 index 00000000..ec0de8af --- /dev/null +++ b/pygments/lexers/_mapping.py.rej @@ -0,0 +1,10 @@ +--- pygments/lexers/_mapping.py ++++ pygments/lexers/_mapping.py +@@ -450,6 +450,7 @@ + 'XtlangLexer': ('pygments.lexers.lisp', 'xtlang', ('extempore',), ('*.xtm',), ()), + 'YamlJinjaLexer': ('pygments.lexers.templates', 'YAML+Jinja', ('yaml+jinja', 'salt', 'sls'), ('*.sls',), ('text/x-yaml+jinja', 'text/x-sls')), + 'YamlLexer': ('pygments.lexers.data', 'YAML', ('yaml',), ('*.yaml', '*.yml'), ('text/x-yaml',)), ++ 'YangLexer': ('pygments.lexers.yang', 'YANG', ('yang', 'Yang'), ('*.yang',), ('application/yang',)), + 'ZephirLexer': ('pygments.lexers.php', 'Zephir', ('zephir',), ('*.zep',), ()), + } + diff --git a/pygments/lexers/yang.py b/pygments/lexers/yang.py new file mode 100644 index 00000000..73fffd77 --- /dev/null +++ b/pygments/lexers/yang.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +""" + pygments.lexers.yang + ~~~~~~~~~~~~~~~~~~~~ + + Lexer for the YANG 1.1 modeling language. See :rfc:`7950`. + + :copyright: Copyright 2006-2018 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +from pygments.lexer import RegexLexer, words +from pygments.token import Comment, Keyword, Name, Punctuation, String, Text + +__all__ = ['YangLexer'] + + +class YangLexer(RegexLexer): + name = 'YANG' + aliases = ['yang', 'Yang'] + filenames = ['*.yang'] + mimetypes = ['application/yang'] + + KEYWORDS = ( + 'action', 'anydata', 'anyxml', 'argument', 'augment', 'base', + 'belongs-to', 'bit', 'case', 'choice', 'config', 'contact', 'container', + 'default', 'description', 'deviate', 'deviation', 'enum', + 'error-app-tag', 'error-message', 'extension', 'feature', + 'fraction-digits', 'grouping', 'identity', 'if-feature', 'import', + 'include', 'input', 'key', 'leaf', 'leaf-list', 'length', 'list', + 'mandatory', 'max-elements', 'min-elements', 'modifier', 'module', + 'must', 'namespace', 'notification', 'ordered-by', 'organization', + 'output', 'path', 'pattern', 'position', 'prefix', 'presence', 'range', + 'reference', 'refine', 'require-instance', 'revision', 'revision-date', + 'rpc', 'status', 'submodule', 'type', 'typedef', 'unique', 'units', + 'uses', 'value', 'when', 'yang-version', 'yin-element', 'add', + 'current', 'delete', 'deprecated', 'false', 'invert-match', 'max', + 'min', 'not-supported', 'obsolete', 'replace', 'system', 'true', + 'unbounded', 'user', 'and', 'or', 'not',) + TYPES = ( + 'binary', 'bits', 'boolean', 'decimal64', 'empty', 'enumeration', + 'int8', 'int16', 'int32', 'int64', 'string', 'uint8', 'uint16', + 'uint32', 'uint64', 'union', 'leafref', 'identityref', + 'instance-identifier',) + + tokens = { + 'comments': [ + (r'[^*/]', Comment), + (r'/\*', Comment, '#push'), + (r'\*/', Comment, '#pop'), + (r'[*/]', Comment), + ], + 'root': [ + (r'\s+', Text), + (r'[\{\};\+]+', Punctuation), + (words(KEYWORDS, suffix=r'(?=[^\w-])'), Keyword), + (words(TYPES, suffix=r'(?=[^\w-])'), Name.Class), + (r'"[^"\\]*(?:\\.[^"\\]*)*"', String), + (r"'[^'\\]*(?:\\.[^'\\]*)*'", String), + (r'/\*', Comment, 'comments'), + (r'//.*?$', Comment), + (r'[^;\{\}\s\*\+\'"]+', Name.Variable), + ], + } |