Skip to content

Commit 4bb6a1c

Browse files
committed
Refactor doc building to not depend on liblkqllang anymore
1 parent f4094a5 commit 4bb6a1c

File tree

6 files changed

+70
-206
lines changed

6 files changed

+70
-206
lines changed

lkql/extensions/python

Lines changed: 0 additions & 42 deletions
This file was deleted.

lkql_checker/doc/share/conf.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,32 @@
44

55
# -- Project information -----------------------------------------------------
66

7-
import os
7+
from os import path as P
88
import sys
99
import time
1010

11-
from liblkqllang import LKQLPygmentsLexer
11+
# Add own dir path
12+
own_dir_path = P.dirname(P.realpath(__file__))
13+
sys.path.append(own_dir_path)
1214

13-
dir_path = os.path.dirname(os.path.realpath(__file__))
14-
sys.path.append(dir_path)
15+
# Add lkql user_manual path into the Python path, so that we have access to the
16+
# lkql pygments lexer module.
17+
lkql_user_manual_path = P.join(
18+
P.dirname(P.dirname(P.dirname(P.dirname(P.realpath(__file__))))),
19+
"user_manual", "source"
20+
)
21+
22+
sys.path.append(lkql_user_manual_path)
1523

1624
import ada_pygments
1725
import latex_elements
26+
import lkql_lexer
1827

1928
# -- General configuration ---------------------------------------------------
2029

2130
from sphinx.highlighting import lexers
2231

23-
lexers['lkql'] = LKQLPygmentsLexer()
32+
lexers['lkql'] = lkql_lexer.LKQLPygmentsLexer()
2433
lexers['ada'] = ada_pygments.AdaLexer()
2534
lexers['gpr'] = ada_pygments.GNATProjectLexer()
2635

@@ -30,9 +39,8 @@
3039
# relative to this directory. They are copied after the builtin static files,
3140
# so a file named "default.css" will overwrite the builtin "default.css".
3241

33-
extensions = ['lkql_doc_class',
34-
'sphinx.ext.viewcode',
35-
]
42+
# TODO: Add back the lkql syntax check, factor it from LKQL's user manual
43+
extensions = ['sphinx.ext.viewcode', 'lkql_doc_class']
3644
templates_path = ['_templates']
3745
source_suffix = '.rst'
3846
master_doc = 'gnatcheck_rm'
@@ -57,7 +65,7 @@ def get_version():
5765
pygments_style = 'sphinx'
5866

5967
html_theme = 'sphinx_rtd_theme'
60-
if os.path.isfile('favicon.ico'):
68+
if P.isfile('favicon.ico'):
6169
html_favicon = 'favicon.ico'
6270

6371
html_logo = 'adacore-logo-white.png'

lkql_checker/doc/share/lkql_doc_class.py

Lines changed: 0 additions & 141 deletions
This file was deleted.

user_manual/source/conf.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@
2020
import os
2121
import sys
2222
from sphinx.highlighting import lexers
23-
from liblkqllang import LKQLPygmentsLexer
2423

2524
dir_path = os.path.dirname(os.path.realpath(__file__))
2625
sys.path.append(dir_path)
2726

27+
import lkql_lexer
28+
2829
project = 'LKQL'
2930
copyright = '2020, AdaCore'
3031
author = 'Raphael Amiard'
3132

32-
lexers['lkql'] = LKQLPygmentsLexer()
33+
lexers['lkql'] = lkql_lexer.LKQLPygmentsLexer()
3334

3435
# -- General configuration ---------------------------------------------------
3536

user_manual/source/lkql_doc_class.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@
1111

1212
from sphinx.util.docutils import SphinxDirective
1313

14-
import liblkqllang
15-
import traceback
14+
try:
15+
import liblkqllang
16+
LKQL_CLASSES = [
17+
v for _, v in liblkqllang.__dict__.items()
18+
if (type(v) == type
19+
and issubclass(v, liblkqllang.LkqlNode))
20+
]
21+
22+
except ImportError:
23+
liblkqllang = None
24+
LKQL_CLASSES = []
1625

17-
lkql_classes = [
18-
v for _, v in liblkqllang.__dict__.items()
19-
if (type(v) == type
20-
and issubclass(v, liblkqllang.LkqlNode))
21-
]
26+
import traceback
2227

2328

2429
@lru_cache
@@ -27,7 +32,7 @@ def lkql_cls_subclasses():
2732
Return a dict of class to direct subclasses.
2833
"""
2934
res = defaultdict(list)
30-
for cls in lkql_classes:
35+
for cls in LKQL_CLASSES:
3136
if cls != liblkqllang.LkqlNode:
3237
res[cls.__base__].append(cls)
3338
return res
@@ -82,7 +87,7 @@ def process_lkql_classes_coverage(app, doctree, fromdocname):
8287
warnings for every non-documented class.
8388
"""
8489
try:
85-
for cls in lkql_classes:
90+
for cls in LKQL_CLASSES:
8691
if not is_class_documented(cls):
8792
doctree.reporter.warning(f"Class not documented: {cls}")
8893
except Exception as e:
@@ -130,9 +135,10 @@ def unknown_visit(self, node) -> None:
130135

131136

132137
def setup(app):
133-
app.add_directive('lkql_doc_class', LkqlDocClassDirective)
134-
app.connect('doctree-resolved', process_lkql_classes_coverage)
135-
app.connect('doctree-resolved', check_lkql_code)
138+
if liblkqllang:
139+
app.add_directive('lkql_doc_class', LkqlDocClassDirective)
140+
app.connect('doctree-resolved', process_lkql_classes_coverage)
141+
app.connect('doctree-resolved', check_lkql_code)
136142

137143
return {
138144
'version': '0.1',

user_manual/source/lkql_lexer.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from pygments.lexer import RegexLexer, words
2+
from pygments import token
3+
4+
class LKQLPygmentsLexer(RegexLexer):
5+
"""
6+
Pygments lexer for LKQL
7+
"""
8+
name = 'LKQL'
9+
filenames = ['*.lkql']
10+
11+
tokens = {
12+
'root': [
13+
(words(('select', 'let', 'when', 'val', 'fun', 'selector',
14+
'match', 'rec', 'skip', 'is', 'in', 'true', 'false',
15+
'if', 'else', 'then', 'not', 'null', 'from'),
16+
prefix=r'\b', suffix=r'\b'),
17+
token.Keyword),
18+
(r"\|\".+", token.String),
19+
(r"#(.?)+", token.Comment),
20+
(r"(\-\>|=|\=\>|\<\=|\>\=|\=|\!\=|\+|\-|\*|\/|\&|"
21+
r"\@|\||\>|\<)", token.Operator),
22+
(r"\b(and|or|not)\b", token.Operator),
23+
(r"\{|\}|\(|\)|\[|\]|;|\.|,", token.Punctuation),
24+
(r'"(\\.|[^"])*"', token.String),
25+
(r'[0-9]+', token.Number),
26+
(r'_?[a-zA-Z][\w\']*', token.Name),
27+
(r'_', token.Name),
28+
(r'\n', token.Text),
29+
(r'[^\S\n]+', token.Text),
30+
]
31+
}
32+

0 commit comments

Comments
 (0)