Skip to content

Commit

Permalink
feat: Add pygments lexer for TQL
Browse files Browse the repository at this point in the history
It allow to have syntax highlight for TQL code blocks
  • Loading branch information
Gashmob committed Sep 16, 2024
1 parent 6f7f83b commit f39366d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ nbproject
.idea/
venv/
node_modules/
languages/en/_themes/tuleap_org/static/assets/
languages/en/_themes/tuleap_org/static/assets/
__pycache__
37 changes: 37 additions & 0 deletions languages/en/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
8 changes: 4 additions & 4 deletions languages/en/user-guide/tql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit f39366d

Please sign in to comment.