From f39366d4ac60b82db04cf51fedb1a5ac4474d2d9 Mon Sep 17 00:00:00 2001 From: Kevin Traini Date: Mon, 16 Sep 2024 14:00:17 +0200 Subject: [PATCH] feat: Add pygments lexer for TQL It allow to have syntax highlight for TQL code blocks --- .gitignore | 3 ++- languages/en/conf.py | 37 +++++++++++++++++++++++++++++++++ languages/en/user-guide/tql.rst | 8 +++---- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 41e1cd2e..b69dbf18 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ nbproject .idea/ venv/ node_modules/ -languages/en/_themes/tuleap_org/static/assets/ \ No newline at end of file +languages/en/_themes/tuleap_org/static/assets/ +__pycache__ \ No newline at end of file diff --git a/languages/en/conf.py b/languages/en/conf.py index 3fa34d09..d204d925 100644 --- a/languages/en/conf.py +++ b/languages/en/conf.py @@ -283,6 +283,43 @@ from pygments.lexers.markup import MarkdownLexer lexers['markdown'] = MarkdownLexer(startinline=True, linenos=1) +from pygments.lexer import RegexLexer +from pygments.token import * +import re + +class TqlLexer(RegexLexer): + """ + A lexer for TQL (Tuleap Query Language) + """ + name = 'TQL' + flags = re.MULTILINE + re.IGNORECASE + + tokens = { + 'root': [ + (r'\s+', Whitespace), + (r'\/{2}.*', Comment), + + (r"'(?:[^\\]|\\.)*?(?:'|$)", String), + (r'"(?:[^\\]|\\.)*?(?:"|$)', String), + + (r'/\d+[dwmy]/i', Number), + (r'\d+(?:\.\d+)?', Number), + + (r'linked\s*from\b', Name), + (r'(?:and|from|or|select|where)\b', Keyword), + (r'(?:artifact|between|by|child|children|covered|covering|from|in|is|linked|myself|not|now|open|parent|to|tracker|type|with|without)\b', Name), + + (r'[=<>!+-]+', Operator), + (r'[()]', Operator), + + (r'@[.\w-]+', Literal), + (r'[.\w-]+', Literal), + + (r',', Punctuation) + ], + } +lexers['tql'] = TqlLexer() + # Redirections rediraffe_redirects = { diff --git a/languages/en/user-guide/tql.rst b/languages/en/user-guide/tql.rst index 6c46116c..f02ebc0d 100644 --- a/languages/en/user-guide/tql.rst +++ b/languages/en/user-guide/tql.rst @@ -94,7 +94,7 @@ To construct a query you can combine all these elements. Query example: -.. code-block:: sql +.. code-block:: tql (summary = "soap" OR summary = "rest") AND description = "documentation" AND story_points BETWEEN(3, 8) @@ -261,7 +261,7 @@ Comparison values Example ------- -:: +.. code-block:: tql @title = 'documentation' AND @status = OPEN() AND @last_update_date > NOW() - 1w //Returns all open artifacts with 'documentation' in the title that have been @@ -284,7 +284,7 @@ Cross-tracker search widget is also available in expert mode allowing you to use In this extended syntax of TQL you can choose which fields you want to display on the widget through ``SELECT`` syntax, and also on which tracker to perform the query with ``FROM``: -:: +.. code-block:: tql SELECT @pretty_title, @status, open_date FROM @project = 'self' AND @tracker.name IN('release', 'sprint') WHERE @assigned_to = MYSELF() // Returns all artifacts from current project release and sprint trackers assigned to me and display their title, status and opening date. @@ -332,7 +332,7 @@ To provide both condition, you can use ``AND`` between them. There is no restric Some example you can take inspiration from: -:: +.. code-block:: tql SELECT @pretty_title, @status, @submitted_by, @last_update_date FROM @project.name = 'support' AND @tracker.name = 'ticket'