1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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),
],
}
|