Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add pygments lexer for TQL #1506

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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__
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"restructuredtext.preview.name": "docutils",
"cSpell.words": [
"Tuleap"
],
"python.analysis.extraPaths": [
"./languages/en/_pygments"
]
}
38 changes: 38 additions & 0 deletions languages/en/_pygments/lexer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
def setup(app):
return

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-]+', Name.Constant),
(r'[.\w-]+', Literal),

(r',', Punctuation)
],
}
22 changes: 22 additions & 0 deletions languages/en/_pygments/tuleap_style.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def setup(app):
return

from pygments.style import Style
from pygments.token import *

class TuleapStyle(Style):
styles = {
Token: '#282621', # typo-default-text-color

Keyword: '#005f90', # class:'k' deep-blue-text
Name: '#6a14a7', # class:'n' plum-crazy-text
Name.Constant: '#945600', # class:'no' clockwork-orange-text
Name.Other: '#774a0a', # class:'nx' teddy-brown-text
String: '#137900', # class:'s' neon-green-text
Number: '#bf4747', # class:'m' coral-pink-text
Literal: '#525252', # class:'l' inca-silver-text

Comment: '#717171', # class:'c' dimmed-color
Comment.Preproc: '#1b805e', # class:'cp' surf-green-text
Punctuation: '#717171', # class:'p' dimmed-color
}
7 changes: 6 additions & 1 deletion languages/en/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
sys.path.append(os.path.abspath("./_pygments"))

# -- General configuration -----------------------------------------------------

Expand All @@ -30,6 +31,8 @@
'sphinx_rtd_theme',
'sphinxext.rediraffe',
'notfound.extension',
'lexer',
'tuleap_style',
]

# Add any paths that contain templates here, relative to this directory.
Expand Down Expand Up @@ -86,7 +89,7 @@
#show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'tango'
pygments_style = 'tuleap_style.TuleapStyle'

# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
Expand Down Expand Up @@ -282,6 +285,8 @@
lexers['php-annotations'] = PhpLexer(startinline=True, linenos=1)
from pygments.lexers.markup import MarkdownLexer
lexers['markdown'] = MarkdownLexer(startinline=True, linenos=1)
from lexer import TqlLexer
lexers['tql'] = TqlLexer()

# Redirections

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