1 # QEMU Monitor Protocol Lexer Extension
3 # Copyright (C) 2019, Red Hat Inc.
6 # Eduardo Habkost <ehabkost@redhat.com>
7 # John Snow <jsnow@redhat.com>
9 # This work is licensed under the terms of the GNU GPLv2 or later.
10 # See the COPYING file in the top-level directory.
11 """qmp_lexer is a Sphinx extension that provides a QMP lexer for code blocks."""
13 from pygments
.lexer
import RegexLexer
, DelegatingLexer
14 from pygments
.lexers
.data
import JsonLexer
15 from pygments
import token
16 from sphinx
import errors
18 class QMPExampleMarkersLexer(RegexLexer
):
20 QMPExampleMarkersLexer lexes QMP example annotations.
21 This lexer adds support for directionality flow and elision indicators.
25 (r
'-> ', token
.Generic
.Prompt
),
26 (r
'<- ', token
.Generic
.Prompt
),
27 (r
' ?\.{3} ?', token
.Generic
.Prompt
),
31 class QMPExampleLexer(DelegatingLexer
):
32 """QMPExampleLexer lexes annotated QMP examples."""
33 def __init__(self
, **options
):
34 super(QMPExampleLexer
, self
).__init
__(JsonLexer
, QMPExampleMarkersLexer
,
35 token
.Error
, **options
)
38 """For use by the Sphinx extensions API."""
40 sphinx
.require_sphinx('2.1')
41 sphinx
.add_lexer('QMP', QMPExampleLexer
)
42 except errors
.VersionRequirementError
:
43 sphinx
.add_lexer('QMP', QMPExampleLexer())