Add a Mistral lexer for pygments

This allows us to use the following code blocks in the Mistral documentation.

    .. code-block:: mistral

When we do that the code will then be highlighted in a way specific to
Mistral, rather than the generic YAML highlighting or none.

Change-Id: Ie25725b9f803e247d23f58c4b602be938c75cfbd
This commit is contained in:
Dougal Matthews 2017-04-05 09:48:50 +01:00
parent 66ef4e3848
commit 679fe7bbef
5 changed files with 63 additions and 3 deletions

View File

@ -7,7 +7,7 @@ Task result / Data flow
Mistral supports transferring data from one task to another. In other words, Mistral supports transferring data from one task to another. In other words,
if *taskA* produces a value then *taskB* which follows *taskA* can use it. if *taskA* produces a value then *taskB* which follows *taskA* can use it.
In order to use this data Mistral relies on a query language called `YAQL <https://github.com/openstack/yaql>`_. In order to use this data Mistral relies on a query language called `YAQL <https://github.com/openstack/yaql>`_.
YAQL is a powerful yet simple tool that allows the user to filter information, YAQL is a powerful yet simple tool that allows the user to filter information,
transform data and call functions. Find more information about it in the transform data and call functions. Find more information about it in the
`YAQL official documentation <http://yaql.readthedocs.org>`_ . This mechanism `YAQL official documentation <http://yaql.readthedocs.org>`_ . This mechanism
@ -17,7 +17,7 @@ referred to as Data Flow.
Below is a simple example of how Mistral Data Flow looks like from the DSL Below is a simple example of how Mistral Data Flow looks like from the DSL
(workflow language) perspective: (workflow language) perspective:
.. code-block:: yaml .. code-block:: mistral
version: '2.0' version: '2.0'

View File

@ -37,7 +37,7 @@ Write a workflow
For example, we have the following workflow. For example, we have the following workflow.
.. code-block:: yaml .. code-block:: mistral
--- ---
version: "2.0" version: "2.0"

0
mistral/ext/__init__.py Normal file
View File

View File

@ -0,0 +1,57 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from pygments import lexer
from pygments import token
class MistralLexer(lexer.RegexLexer):
name = 'Mistral'
aliases = ['mistral']
tokens = {
"root": [
(r'^(\s)*(workflows|tasks|input|type)(\s)*:', token.Keyword),
(r'^(\s)*(version|name|description)(\s)*:', token.Keyword),
(r'^(\s)*(publish|timeout|retry|with\-items)(\s)*:',
token.Keyword),
(r'^(\s)*(on\-success|on\-error|on\-complete)(\s)*:',
token.Keyword),
(r'^(\s)*(action|workflow)(\s)*:', token.Keyword, 'call'),
(r'(\-|\:)(\s)*(fail|succeed|pause)(\s)+', token.Operator.Word),
(r'<%', token.Name.Entity, 'expression'),
(r'\{\{', token.Name.Entity, 'expression'),
(r'#.*$', token.Comment),
(r'(^|\s|\-)+\d+', token.Number),
lexer.include("generic"),
],
"expression": [
(r'\$', token.Operator),
(r'\s(json_pp|task|tasks|execution|env|uuid)(?!\w)',
token.Name.Builtin),
lexer.include("generic"),
(r'%>', token.Name.Entity, '#pop'),
(r'}\\}', token.Name.Entity, '#pop'),
],
"call": [
(r'(\s)*[\w\.]+($|\s)', token.Name.Function),
lexer.default('#pop'),
],
"generic": [
(r'(\-|:|=|!|\[|\])', token.Operator),
(r'(null|None|True|False)', token.Name.Builtin),
(r'"(\\\\|\\"|[^"])*"', token.String.Double),
(r"'(\\\\|\\'|[^'])*'", token.String.Single),
(r'\w|\s|\(|\)|,|\.', token.Text),
]
}

View File

@ -89,3 +89,6 @@ mistral.auth =
kombu_driver.executors = kombu_driver.executors =
blocking = futurist:SynchronousExecutor blocking = futurist:SynchronousExecutor
threading = futurist:ThreadPoolExecutor threading = futurist:ThreadPoolExecutor
pygments.lexers =
mistral = mistral.ext.pygmentplugin:MistralLexer