pygments-jennifer 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ # SPDX-License-Identifier: BSD-2-Clause
2
+ # SPDX-FileCopyrightText: Copyright (C) 2026 mplx <mplx@jennifer-lang.dev>
3
+ """Pygments lexer plugin for Jennifer (https://jennifer-lang.dev/).
4
+
5
+ Installing the package registers the lexer with Pygments under the alias
6
+ `jennifer` and the filename `*.j`; nothing needs importing.
7
+ """
8
+
9
+ from pygments_jennifer.lexer import JenniferLexer
10
+
11
+ __all__ = ["JenniferLexer"]
12
+ __version__ = "0.1.0"
@@ -0,0 +1,186 @@
1
+ # SPDX-License-Identifier: BSD-2-Clause
2
+ # SPDX-FileCopyrightText: Copyright (C) 2026 mplx <mplx@jennifer-lang.dev>
3
+ """A Pygments lexer for Jennifer (https://jennifer-lang.dev/).
4
+
5
+ The token classes follow the other definitions in jennifer/editors (see
6
+ editors/README.md, "Contributing another editor"): `$` variables,
7
+ `UPPER_CASE` constants, `CamelCase` types, `ns.name` calls with the prefix as
8
+ a namespace, nested `/* */` comments, `/** */` docblocks with `@tags`, raw
9
+ `'...'` and cooked `"..."` strings with `{expr}` slots.
10
+ """
11
+
12
+ import re
13
+
14
+ from pygments.lexer import RegexLexer, bygroups, include, words
15
+ from pygments.token import (
16
+ Comment,
17
+ Error,
18
+ Keyword,
19
+ Name,
20
+ Number,
21
+ Operator,
22
+ Punctuation,
23
+ String,
24
+ Whitespace,
25
+ )
26
+
27
+ __all__ = ["JenniferLexer"]
28
+
29
+ TYPES = ("int", "float", "string", "bool", "bytes", "list", "map", "task")
30
+
31
+
32
+ class JenniferLexer(RegexLexer):
33
+ """Lexer for Jennifer source (`.j` files and `#!... jennifer` scripts)."""
34
+
35
+ name = "Jennifer"
36
+ url = "https://jennifer-lang.dev/"
37
+ aliases = ["jennifer"]
38
+ filenames = ["*.j"]
39
+ mimetypes = ["text/x-jennifer"]
40
+ # Pygments' Objective-J lexer claims `*.j` too. Without source to
41
+ # analyse, the higher priority wins the file name; with source,
42
+ # analyse_text decides.
43
+ priority = 0.1
44
+
45
+ tokens = {
46
+ "root": [
47
+ (r"\A#!.*\n", Comment.Hashbang),
48
+ (r"\s+", Whitespace),
49
+ (r"#\s*pragma-jennifer-[a-z]+:[^\n]*", Comment.Preproc),
50
+ (r"#\s*lint-disable(-file)?:[^\n]*", Comment.Special),
51
+ (r"#[^\n]*", Comment.Single),
52
+ (r"/\*\*(?!/)", Comment.Multiline, "docblock"),
53
+ (r"/\*", Comment.Multiline, "comment"),
54
+ (r'"', String.Double, "cooked"),
55
+ (r"'", String.Single, "raw"),
56
+ (r"0[xX][0-9a-fA-F](_?[0-9a-fA-F])*", Number.Hex),
57
+ (r"0[oO][0-7](_?[0-7])*", Number.Oct),
58
+ (r"0[bB][01](_?[01])*", Number.Bin),
59
+ (
60
+ r"[0-9](_?[0-9])*"
61
+ r"(\.[0-9](_?[0-9])*([eE][+\-]?[0-9]+)?|[eE][+\-]?[0-9]+)",
62
+ Number.Float,
63
+ ),
64
+ (r"[0-9](_?[0-9])*", Number.Integer),
65
+ (r"\.\.", Operator),
66
+ # After a `.`, any spelling is a name, keywords included.
67
+ (
68
+ r"(\.)([A-Za-z][A-Za-z0-9_]*)(?=\s*\()",
69
+ bygroups(Punctuation, Name.Function),
70
+ ),
71
+ (
72
+ r"(\.)([A-Z][A-Z0-9]*(?:_[A-Z][A-Z0-9]*)*)\b",
73
+ bygroups(Punctuation, Name.Constant),
74
+ ),
75
+ (r"(\.)([A-Z][A-Za-z0-9]*)", bygroups(Punctuation, Name.Class)),
76
+ (r"(\.)([a-z][A-Za-z0-9]*)", bygroups(Punctuation, Name.Property)),
77
+ (r"\$[A-Za-z][A-Za-z0-9]*", Name.Variable),
78
+ (
79
+ r"\b(use)(\s+)([a-z][A-Za-z0-9]*)",
80
+ bygroups(Keyword.Namespace, Whitespace, Name.Namespace),
81
+ ),
82
+ (
83
+ r"\b(as)(\s+)(?!(?:%s|func|null|true|false)\b)"
84
+ r"([a-z][A-Za-z0-9]*)(?=\s*;)" % "|".join(TYPES),
85
+ bygroups(Keyword.Declaration, Whitespace, Name.Namespace),
86
+ ),
87
+ (r"\b[a-z][A-Za-z0-9]*(?=\.[A-Za-z])", Name.Namespace),
88
+ # A field position: `to as Point`, `Written{bytes: 0}`.
89
+ (r"\b[a-z][A-Za-z0-9]*(?=\s*:|\s+as\b)", Name),
90
+ (words(("use", "include", "import"), prefix=r"\b", suffix=r"\b"),
91
+ Keyword.Namespace),
92
+ (
93
+ words(
94
+ ("export", "def", "const", "func", "struct", "enum", "as",
95
+ "of", "to", "init"),
96
+ prefix=r"\b",
97
+ suffix=r"\b",
98
+ ),
99
+ Keyword.Declaration,
100
+ ),
101
+ (
102
+ words(
103
+ ("if", "elseif", "else", "while", "for", "in", "repeat",
104
+ "until", "match", "when", "break", "continue", "return",
105
+ "exit", "try", "catch", "throw", "defer", "errdefer",
106
+ "spawn"),
107
+ prefix=r"\b",
108
+ suffix=r"\b",
109
+ ),
110
+ Keyword,
111
+ ),
112
+ (words(("and", "or", "not"), prefix=r"\b", suffix=r"\b"),
113
+ Operator.Word),
114
+ (words(("true", "false", "null"), prefix=r"\b", suffix=r"\b"),
115
+ Keyword.Constant),
116
+ (words(TYPES, prefix=r"\b", suffix=r"\b"), Keyword.Type),
117
+ (r"\bchannel(?=\s+of\b)", Keyword.Type),
118
+ (r"\blen\b", Name.Builtin),
119
+ (r"\b[A-Z][A-Z0-9]*(_[A-Z][A-Z0-9]*)*\b", Name.Constant),
120
+ (r"\b[A-Z][A-Za-z0-9]*\b", Name.Class),
121
+ (r"[a-z][A-Za-z0-9]*(?=\s*\()", Name.Function),
122
+ (r"[A-Za-z][A-Za-z0-9_]*", Name),
123
+ (r"//|<<|>>|<=|>=|==|!=|[\-+*/%&|^~<>=]", Operator),
124
+ (r"[{}()\[\];,.:]", Punctuation),
125
+ ],
126
+ "comment": [
127
+ (r"/\*", Comment.Multiline, "#push"),
128
+ (r"\*/", Comment.Multiline, "#pop"),
129
+ (r"[^*/]+", Comment.Multiline),
130
+ (r"[*/]", Comment.Multiline),
131
+ ],
132
+ "docblock": [
133
+ (r"(?<=\s)@[a-z]+\b", Comment.Special),
134
+ (r"/\*", Comment.Multiline, "comment"),
135
+ (r"\*/", Comment.Multiline, "#pop"),
136
+ (r"[^*/@]+", Comment.Multiline),
137
+ (r"[*/@]", Comment.Multiline),
138
+ ],
139
+ "cooked": [
140
+ (r'"', String.Double, "#pop"),
141
+ (r"""\\([nrt\\"'0{}]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})""",
142
+ String.Escape),
143
+ (r"\\.?", Error),
144
+ (r"\{", String.Interpol, "interpolation"),
145
+ (r"\}", Error),
146
+ (r'[^"\\{}]+', String.Double),
147
+ ],
148
+ "raw": [
149
+ (r"'", String.Single, "#pop"),
150
+ (r"[^']+", String.Single),
151
+ ],
152
+ # A `{expr}` slot. A map literal inside it opens `braces`, so the
153
+ # slot ends at its own `}`.
154
+ "interpolation": [
155
+ (r"\}", String.Interpol, "#pop"),
156
+ (r"\{", Punctuation, "braces"),
157
+ include("root"),
158
+ ],
159
+ "braces": [
160
+ (r"\}", Punctuation, "#pop"),
161
+ (r"\{", Punctuation, "#push"),
162
+ include("root"),
163
+ ],
164
+ }
165
+
166
+ _SHEBANG = re.compile(r"\A#!.*\bjennifer\b")
167
+ _PRAGMA = re.compile(r"^#\s*pragma-jennifer-version:", re.M)
168
+ _USE = re.compile(
169
+ r"^\s*use\s+[a-z][A-Za-z0-9]*(\s+as\s+[a-z][A-Za-z0-9]*)?\s*;", re.M
170
+ )
171
+ _DEF = re.compile(
172
+ r"^\s*(export\s+)?def\s+(const\s+)?[A-Za-z][A-Za-z0-9_]*\s+as\s+"
173
+ r"(%s|func)\b" % "|".join(TYPES),
174
+ re.M,
175
+ )
176
+
177
+ def analyse_text(text):
178
+ if JenniferLexer._SHEBANG.search(text):
179
+ return 1.0
180
+ if JenniferLexer._PRAGMA.search(text):
181
+ return 1.0
182
+ if JenniferLexer._USE.search(text):
183
+ return 0.5
184
+ if JenniferLexer._DEF.search(text):
185
+ return 0.3
186
+ return 0.0
@@ -0,0 +1,146 @@
1
+ Metadata-Version: 2.5
2
+ Name: pygments-jennifer
3
+ Version: 0.1.0
4
+ Summary: Pygments lexer plugin for the Jennifer programming language
5
+ Project-URL: Homepage, https://jennifer-lang.dev/
6
+ Project-URL: Source, https://github.com/jennifer-language/pygments-jennifer
7
+ Author-email: mplx <mplx@jennifer-lang.dev>
8
+ License: BSD 2-Clause License
9
+
10
+ Copyright (C) 2026 mplx <mplx@jennifer-lang.dev>
11
+
12
+ Redistribution and use in source and binary forms, with or without
13
+ modification, are permitted provided that the following conditions are met:
14
+
15
+ 1. Redistributions of source code must retain the above copyright notice, this
16
+ list of conditions and the following disclaimer.
17
+
18
+ 2. Redistributions in binary form must reproduce the above copyright notice,
19
+ this list of conditions and the following disclaimer in the documentation
20
+ and/or other materials provided with the distribution.
21
+
22
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+ License-File: LICENSE
33
+ Keywords: jennifer,lexer,pygments,syntax highlighting
34
+ Classifier: License :: OSI Approved :: BSD License
35
+ Classifier: Programming Language :: Python :: 3
36
+ Classifier: Topic :: Software Development :: Documentation
37
+ Classifier: Topic :: Text Processing :: Filters
38
+ Requires-Python: >=3.9
39
+ Requires-Dist: pygments>=2.13
40
+ Provides-Extra: test
41
+ Requires-Dist: pytest; extra == 'test'
42
+ Description-Content-Type: text/markdown
43
+
44
+ # pygments-jennifer
45
+
46
+ A [Pygments](https://pygments.org) lexer for [Jennifer](https://jennifer-lang.dev/),
47
+ packaged as a plugin. Once installed, Pygments highlights Jennifer wherever it
48
+ is used: `pygmentize`, Sphinx, MkDocs, Jupyter, and any other tool built on
49
+ it. Pygments takes new languages as plugins until they have a community of
50
+ their own; this is that plugin.
51
+
52
+ ## Install
53
+
54
+ ```sh
55
+ pip install pygments-jennifer
56
+ ```
57
+
58
+ Or the development version, from the repository:
59
+
60
+ ```sh
61
+ pip install git+https://github.com/jennifer-language/pygments-jennifer.git
62
+ ```
63
+
64
+ Needs Python 3.9 or newer and Pygments 2.13 or newer, the first release that
65
+ loads plugins through `importlib.metadata`. Install it into the same
66
+ environment as the tool that runs Pygments (the Sphinx or MkDocs virtualenv,
67
+ say).
68
+
69
+ ## Use
70
+
71
+ The lexer registers the alias `jennifer`, the filename pattern `*.j` and the
72
+ MIME type `text/x-jennifer`:
73
+
74
+ ```sh
75
+ pygmentize -l jennifer main.j # by alias
76
+ pygmentize main.j # by file name
77
+ pygmentize -f html -O full -o main.html main.j
78
+ ```
79
+
80
+ In Markdown for MkDocs (with `pymdownx.highlight`) or in Sphinx's MyST, fence
81
+ code as ```` ```jennifer ````. In reStructuredText:
82
+
83
+ ```rst
84
+ .. code-block:: jennifer
85
+
86
+ use io;
87
+ io.printf("hello\n");
88
+ ```
89
+
90
+ From Python:
91
+
92
+ ```python
93
+ from pygments import highlight
94
+ from pygments.formatters import HtmlFormatter
95
+ from pygments.lexers import get_lexer_by_name
96
+
97
+ html = highlight(source, get_lexer_by_name("jennifer"), HtmlFormatter())
98
+ ```
99
+
100
+ `guess_lexer` recognises Jennifer by a `#!... jennifer` first line or a
101
+ `# pragma-jennifer-version:` header, which extensionless scripts carry, and
102
+ less surely by a `use name;` line.
103
+
104
+ Pygments' built-in Objective-J lexer claims `*.j` as well. With this plugin
105
+ installed, a `.j` file name alone selects Jennifer; when Pygments also sees
106
+ the source, it picks whichever lexer recognises the content, so an Objective-J
107
+ file with its `@import` lines still goes to Objective-J.
108
+
109
+ ## What it highlights
110
+
111
+ The same token classes as the other Jennifer editor definitions: keywords and
112
+ type keywords, `$` variables, `UPPER_CASE` constants, `CamelCase` types,
113
+ `name(` calls, `ns.name` with the prefix as a namespace (and the name after
114
+ `use` or an alias), keyword-spelled names after a `.` or in a field position,
115
+ `#` comments, nested `/* */` comments, `/** */` docblocks with `@tags`,
116
+ `# pragma-jennifer-...:` and `# lint-disable:` directives, raw `'...'` and
117
+ cooked `"..."` strings with escapes and `{expr}` slots, and the numeric
118
+ forms.
119
+
120
+ ## Development
121
+
122
+ The lexer is maintained in the interpreter repository, at
123
+ [`editors/pygments/`](https://github.com/jennifer-language/jennifer/tree/main/editors/pygments),
124
+ where it is checked against the interpreter's own lexer over every Jennifer
125
+ source file in the project. `src/pygments_jennifer/lexer.py`,
126
+ `tests/example.j` and `tests/example.tokens` are byte-for-byte copies of the
127
+ files there. Change them there, then:
128
+
129
+ ```sh
130
+ tools/sync.sh # copy from a sibling checkout ../jennifer
131
+ tools/sync.sh --check # what CI runs
132
+ python -m pip install -e ".[test]" && python -m pytest
133
+ ```
134
+
135
+ ## Releasing
136
+
137
+ Set the version in `pyproject.toml` and `src/pygments_jennifer/__init__.py`,
138
+ add it to `CHANGELOG.md`, commit, and push a tag of the same name (`0.1.0`, no
139
+ `v`) to GitHub. CI builds the sdist and the wheel once the tests and the sync
140
+ check pass, and publishes them to PyPI as a trusted publisher: the PyPI
141
+ project trusts this repository's `ci.yml`, so no token is involved. A tag that
142
+ does not match the version fails before anything is built.
143
+
144
+ ## License
145
+
146
+ BSD-2-Clause, like Pygments. See [LICENSE](LICENSE).
@@ -0,0 +1,7 @@
1
+ pygments_jennifer/__init__.py,sha256=UWkdF99bUO0qNNe0OvlDO4oFuKk6muzTCfLmBlfkKXI,423
2
+ pygments_jennifer/lexer.py,sha256=3jDnEp0_9BExq4maVJbl_3RyslhDunSQsx2Hwql6VFI,6970
3
+ pygments_jennifer-0.1.0.dist-info/METADATA,sha256=72xqcrHMR55D9it96D00bIJOc1DP4AdzyjLv99NZwJo,5893
4
+ pygments_jennifer-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
5
+ pygments_jennifer-0.1.0.dist-info/entry_points.txt,sha256=BWeh1Ay22D2KB_Cb1pSrGUKr55bqDeWdVze6BVhch1Q,67
6
+ pygments_jennifer-0.1.0.dist-info/licenses/LICENSE,sha256=rDaWzLuuEfnp2Q5QvSEXZFFWVf_b9g88gsJRtb41C-k,1317
7
+ pygments_jennifer-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [pygments.lexers]
2
+ jennifer = pygments_jennifer.lexer:JenniferLexer
@@ -0,0 +1,24 @@
1
+ BSD 2-Clause License
2
+
3
+ Copyright (C) 2026 mplx <mplx@jennifer-lang.dev>
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.