pygments-plum 1.0.0__tar.gz
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.
- pygments_plum-1.0.0/.gitignore +10 -0
- pygments_plum-1.0.0/LICENSE +21 -0
- pygments_plum-1.0.0/NOTICE +42 -0
- pygments_plum-1.0.0/PKG-INFO +177 -0
- pygments_plum-1.0.0/README.md +142 -0
- pygments_plum-1.0.0/pygments_plum/__init__.py +180 -0
- pygments_plum-1.0.0/pyproject.toml +58 -0
- pygments_plum-1.0.0/tests/examples/LICENSE +202 -0
- pygments_plum-1.0.0/tests/examples/README.md +15 -0
- pygments_plum-1.0.0/tests/examples/examples/bank.plum +59 -0
- pygments_plum-1.0.0/tests/examples/examples/config/main.plum +23 -0
- pygments_plum-1.0.0/tests/examples/examples/config/settings.plum +141 -0
- pygments_plum-1.0.0/tests/examples/examples/echo.plum +36 -0
- pygments_plum-1.0.0/tests/examples/examples/garden/main.plum +21 -0
- pygments_plum-1.0.0/tests/examples/examples/garden/models/bed.plum +20 -0
- pygments_plum-1.0.0/tests/examples/examples/garden/models/plant.plum +21 -0
- pygments_plum-1.0.0/tests/examples/examples/http/chat.plum +139 -0
- pygments_plum-1.0.0/tests/examples/examples/http/hello.plum +22 -0
- pygments_plum-1.0.0/tests/examples/examples/http/rest_api.plum +82 -0
- pygments_plum-1.0.0/tests/examples/examples/shapes.plum +44 -0
- pygments_plum-1.0.0/tests/examples/examples/todo.plum +54 -0
- pygments_plum-1.0.0/tests/examples/examples/wordcount.plum +85 -0
- pygments_plum-1.0.0/tests/examples/lang/control/break_continue.plum +17 -0
- pygments_plum-1.0.0/tests/examples/lang/control/for_range.plum +10 -0
- pygments_plum-1.0.0/tests/examples/lang/control/if_else.plum +99 -0
- pygments_plum-1.0.0/tests/examples/lang/control/if_expression.plum +3 -0
- pygments_plum-1.0.0/tests/examples/lang/control/in_range.plum +9 -0
- pygments_plum-1.0.0/tests/examples/lang/control/nested_loops.plum +7 -0
- pygments_plum-1.0.0/tests/examples/lang/control/while.plum +6 -0
- pygments_plum-1.0.0/tests/examples/lang/errors/builtin.plum +21 -0
- pygments_plum-1.0.0/tests/examples/lang/errors/callbacks.plum +30 -0
- pygments_plum-1.0.0/tests/examples/lang/errors/catch.plum +64 -0
- pygments_plum-1.0.0/tests/examples/lang/errors/error_finally_uncaught.plum +7 -0
- pygments_plum-1.0.0/tests/examples/lang/errors/error_rethrow.plum +10 -0
- pygments_plum-1.0.0/tests/examples/lang/errors/error_uncaught.plum +17 -0
- pygments_plum-1.0.0/tests/examples/lang/errors/finally.plum +77 -0
- pygments_plum-1.0.0/tests/examples/lang/errors/try_expr.plum +23 -0
- pygments_plum-1.0.0/tests/examples/lang/fmt/comments.plum +44 -0
- pygments_plum-1.0.0/tests/examples/lang/fmt/error_syntax.plum +4 -0
- pygments_plum-1.0.0/tests/examples/lang/fmt/layout.plum +45 -0
- pygments_plum-1.0.0/tests/examples/lang/fmt/literals.plum +21 -0
- pygments_plum-1.0.0/tests/examples/lang/fmt/multiline.plum +34 -0
- pygments_plum-1.0.0/tests/examples/lang/kinds/kinds_match.plum +63 -0
- pygments_plum-1.0.0/tests/examples/lang/kinds/match_values.plum +33 -0
- pygments_plum-1.0.0/tests/examples/lang/kinds/values.plum +40 -0
- pygments_plum-1.0.0/tests/examples/lang/lexer/error_brackets.plum +5 -0
- pygments_plum-1.0.0/tests/examples/lang/lexer/error_foreign.plum +6 -0
- pygments_plum-1.0.0/tests/examples/lang/lexer/error_numbers.plum +10 -0
- pygments_plum-1.0.0/tests/examples/lang/lexer/error_strings.plum +6 -0
- pygments_plum-1.0.0/tests/examples/lang/lexer/error_utf8.plum +4 -0
- pygments_plum-1.0.0/tests/examples/lang/lexer/keywords.plum +6 -0
- pygments_plum-1.0.0/tests/examples/lang/lexer/newlines.plum +18 -0
- pygments_plum-1.0.0/tests/examples/lang/lexer/numbers.plum +5 -0
- pygments_plum-1.0.0/tests/examples/lang/lexer/operators.plum +5 -0
- pygments_plum-1.0.0/tests/examples/lang/lexer/strings.plum +9 -0
- pygments_plum-1.0.0/tests/examples/lang/lexer/triple_strings.plum +8 -0
- pygments_plum-1.0.0/tests/examples/lang/modules/error_cycle.plum +1 -0
- pygments_plum-1.0.0/tests/examples/lang/modules/error_missing.plum +2 -0
- pygments_plum-1.0.0/tests/examples/lang/modules/error_private.plum +3 -0
- pygments_plum-1.0.0/tests/examples/lang/modules/error_trace.plum +4 -0
- pygments_plum-1.0.0/tests/examples/lang/modules/imports.plum +17 -0
- pygments_plum-1.0.0/tests/examples/lang/modules/same_names.plum +7 -0
- pygments_plum-1.0.0/tests/examples/lang/operators/bitwise.plum +18 -0
- pygments_plum-1.0.0/tests/examples/lang/operators/bitwise_precedence.plum +6 -0
- pygments_plum-1.0.0/tests/examples/lang/operators/comparison.plum +8 -0
- pygments_plum-1.0.0/tests/examples/lang/operators/compound.plum +29 -0
- pygments_plum-1.0.0/tests/examples/lang/operators/logic.plum +41 -0
- pygments_plum-1.0.0/tests/examples/lang/operators/shifts.plum +11 -0
- pygments_plum-1.0.0/tests/examples/lang/operators/short_circuit.plum +8 -0
- pygments_plum-1.0.0/tests/examples/lang/strings/error_empty.plum +2 -0
- pygments_plum-1.0.0/tests/examples/lang/strings/error_index.plum +2 -0
- pygments_plum-1.0.0/tests/examples/lang/strings/error_slice.plum +2 -0
- pygments_plum-1.0.0/tests/examples/lang/strings/sequences.plum +19 -0
- pygments_plum-1.0.0/tests/examples/lang/tasks/error_callback_wait.plum +4 -0
- pygments_plum-1.0.0/tests/examples/lang/tasks/error_deadlock.plum +4 -0
- pygments_plum-1.0.0/tests/examples/lang/tasks/error_objects.plum +12 -0
- pygments_plum-1.0.0/tests/examples/lang/tasks/error_unwaited.plum +10 -0
- pygments_plum-1.0.0/tests/examples/lang/tasks/many.plum +15 -0
- pygments_plum-1.0.0/tests/examples/lang/tasks/order.plum +29 -0
- pygments_plum-1.0.0/tests/examples/lang/tasks/tasks.plum +68 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/compare.plum +93 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/construct.plum +14 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/deep_free.plum +12 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/deep_to_str.plum +18 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/equals.plum +17 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/equals_lists.plum +50 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/error_extends_itself.plum +5 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/error_init_fields.plum +12 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/error_operator_shapes.plum +9 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/error_operator_use.plum +16 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/error_override.plum +6 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/error_private.plum +6 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/error_special.plum +4 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/error_too_deep.plum +37 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/error_too_many_fields.plum +260 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/error_trait_missing.plum +6 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/errors.plum +6 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/field_places.plum +20 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/inherit.plum +16 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/inherit_methods.plum +18 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/init.plum +35 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/large_hierarchies.plum +307 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/methods.plum +46 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/operators.plum +52 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/operators_override.plum +41 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/optional.plum +20 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/self_closure.plum +15 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/shared.plum +30 -0
- pygments_plum-1.0.0/tests/examples/lang/trees/traits.plum +37 -0
- pygments_plum-1.0.0/tests/test_examples.py +45 -0
- pygments_plum-1.0.0/tests/test_plugin.py +58 -0
- pygments_plum-1.0.0/tests/test_tokens.py +306 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Elixpo and the Plumlang contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
NOTICE
|
|
2
|
+
======
|
|
3
|
+
|
|
4
|
+
The code in this repository is licensed under the MIT licence (see
|
|
5
|
+
./LICENSE). This file records what that licence does NOT grant.
|
|
6
|
+
|
|
7
|
+
REPOSITORY
|
|
8
|
+
----------
|
|
9
|
+
|
|
10
|
+
Name: plumlang/pygments-plum
|
|
11
|
+
What it is: The Plumlang lexer plugin for Pygments, published on PyPI
|
|
12
|
+
as `pygments-plum`: syntax highlighting for Plumlang in
|
|
13
|
+
Sphinx, MkDocs, pygmentize and anything else that uses
|
|
14
|
+
Pygments.
|
|
15
|
+
|
|
16
|
+
TRADEMARKS
|
|
17
|
+
----------
|
|
18
|
+
|
|
19
|
+
The following are trademarks and brand property of Elixpo and are NOT
|
|
20
|
+
licensed by the MIT licence:
|
|
21
|
+
|
|
22
|
+
* The name "Plumlang", and "Plum" when used as the name of a programming
|
|
23
|
+
language, its tools, or its packages.
|
|
24
|
+
* The Plumlang marks (the plum logos and the lockups that combine them
|
|
25
|
+
with the name).
|
|
26
|
+
* The Elixpo name and identity.
|
|
27
|
+
|
|
28
|
+
You may use, copy, modify and redistribute the code under the MIT licence,
|
|
29
|
+
and you may truthfully say that your work supports or works with Plumlang.
|
|
30
|
+
You may NOT, without written permission from Elixpo, publish a fork of this
|
|
31
|
+
plugin, or any other package, under the Plumlang name or marks or a
|
|
32
|
+
confusingly similar name (on PyPI or elsewhere), or present it as the
|
|
33
|
+
official Plumlang lexer.
|
|
34
|
+
|
|
35
|
+
The test programs in tests/examples/ are copied from plumlang/plumlang and
|
|
36
|
+
are under its Apache-2.0 licence (tests/examples/LICENSE).
|
|
37
|
+
|
|
38
|
+
The plum binary and its language server (plumlang/plumlang), the
|
|
39
|
+
Tree-sitter grammar (plumlang/tree-sitter-plum), and the documentation at
|
|
40
|
+
https://plum.elixpo.com are separate projects under their own terms.
|
|
41
|
+
|
|
42
|
+
Contact: hello@elixpo.com
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pygments-plum
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Plumlang lexer plugin for Pygments: highlighting in Sphinx, MkDocs and anything else that uses Pygments
|
|
5
|
+
Project-URL: Homepage, https://plum.elixpo.com
|
|
6
|
+
Project-URL: Source, https://github.com/plumlang/pygments-plum
|
|
7
|
+
Project-URL: Issues, https://github.com/plumlang/pygments-plum/issues
|
|
8
|
+
Project-URL: Plumlang, https://github.com/plumlang/plumlang
|
|
9
|
+
Author-email: Elixpo and the Plumlang contributors <hello@elixpo.com>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
License-File: NOTICE
|
|
13
|
+
Keywords: lexer,plum,plumlang,pygments,syntax highlighting
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Environment :: Plugins
|
|
16
|
+
Classifier: Framework :: Sphinx :: Extension
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
26
|
+
Classifier: Topic :: Documentation
|
|
27
|
+
Classifier: Topic :: Software Development :: Documentation
|
|
28
|
+
Classifier: Topic :: Text Processing :: Filters
|
|
29
|
+
Classifier: Topic :: Text Processing :: Markup
|
|
30
|
+
Requires-Python: >=3.10
|
|
31
|
+
Requires-Dist: pygments>=2.13
|
|
32
|
+
Provides-Extra: test
|
|
33
|
+
Requires-Dist: pytest>=7; extra == 'test'
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# Plumlang for Pygments
|
|
37
|
+
|
|
38
|
+
A [Pygments](https://pygments.org) lexer plugin for
|
|
39
|
+
[Plumlang](https://plum.elixpo.com), for `.plum` files. Once it is
|
|
40
|
+
installed, everything that highlights code with Pygments knows Plumlang:
|
|
41
|
+
Sphinx, MkDocs (Material included), `pygmentize`, Jupyter, and the many
|
|
42
|
+
static site generators and chat tools built on Pygments.
|
|
43
|
+
|
|
44
|
+
It highlights:
|
|
45
|
+
|
|
46
|
+
- **Keywords**: declarations (`plant`, `root`, `branch`, `tree`, `trait`,
|
|
47
|
+
`kind`), `seed` imports with their module paths and aliases, control flow,
|
|
48
|
+
`and`/`or`/`not`/`in`/`is`/`as`, and the constants `good`, `bad` and
|
|
49
|
+
`none`.
|
|
50
|
+
- **Names at declarations**: functions and methods after `branch`, trees,
|
|
51
|
+
traits and kinds after their keyword, constants after `root`.
|
|
52
|
+
- **Types and built-ins**: `int`, `str`, `list`, `map`, ...; the built-in
|
|
53
|
+
functions (`drop`, `ask`, `len`, ...); conversions such as `int(text)`;
|
|
54
|
+
the built-in error trees (`ValueError`, `IOError`, ...); `self` and
|
|
55
|
+
`super`.
|
|
56
|
+
- **Strings** with escapes (`\n`, `\{`, `\u{1F351}`) and `{interpolation}`,
|
|
57
|
+
whose expression is highlighted like any other code, with format specs
|
|
58
|
+
(`{total:.2}`, `{n:>5}`); `"""` strings across lines.
|
|
59
|
+
- **Numbers** in every form (`1_000`, `0xFF`, `0o755`, `0b1010`, `6.022e23`),
|
|
60
|
+
operators, punctuation and `#` comments.
|
|
61
|
+
|
|
62
|
+
The rules follow the reference lexer in
|
|
63
|
+
[plumlang/plumlang](https://github.com/plumlang/plumlang). The lexer never
|
|
64
|
+
produces Pygments' `Error` token: code the compiler would reject (`&&`, a
|
|
65
|
+
`'single-quoted'` string, a bad escape) is still highlighted sensibly.
|
|
66
|
+
|
|
67
|
+
## Install
|
|
68
|
+
|
|
69
|
+
```sh
|
|
70
|
+
pip install pygments-plum
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The package registers itself with Pygments through the `pygments.lexers`
|
|
74
|
+
entry point, so nothing else needs configuring. Check it with:
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
pygmentize -L lexers | grep -A1 Plumlang
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Use
|
|
81
|
+
|
|
82
|
+
The lexer's names are `plum` and `plumlang`; it is picked for `*.plum` files
|
|
83
|
+
and the `text/x-plum` MIME type.
|
|
84
|
+
|
|
85
|
+
### On the command line
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
pygmentize -l plum hello.plum # to the terminal
|
|
89
|
+
pygmentize -l plum -f terminal256 -O style=monokai hello.plum
|
|
90
|
+
pygmentize -l plum -f html -O full -o hello.html hello.plum
|
|
91
|
+
pygmentize hello.plum # picked by the .plum suffix
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### In Sphinx
|
|
95
|
+
|
|
96
|
+
Add `pygments-plum` to your docs' requirements (for example
|
|
97
|
+
`docs/requirements.txt` on Read the Docs), then write:
|
|
98
|
+
|
|
99
|
+
````rst
|
|
100
|
+
.. code-block:: plum
|
|
101
|
+
|
|
102
|
+
plant name = "Ada"
|
|
103
|
+
drop("Hello, {name}!")
|
|
104
|
+
````
|
|
105
|
+
|
|
106
|
+
or, with MyST Markdown, a ```` ```plum ```` fence.
|
|
107
|
+
|
|
108
|
+
### In MkDocs
|
|
109
|
+
|
|
110
|
+
With [`pymdownx.highlight`](https://facelessuser.github.io/pymdown-extensions/extensions/highlight/)
|
|
111
|
+
and `pymdownx.superfences` (Material for MkDocs turns them on in its
|
|
112
|
+
recommended setup), add `pygments-plum` to the requirements your docs are
|
|
113
|
+
built with and use ```` ```plum ```` fences:
|
|
114
|
+
|
|
115
|
+
```yaml
|
|
116
|
+
# mkdocs.yml
|
|
117
|
+
markdown_extensions:
|
|
118
|
+
- pymdownx.highlight:
|
|
119
|
+
use_pygments: true
|
|
120
|
+
- pymdownx.superfences
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
````markdown
|
|
124
|
+
```plum
|
|
125
|
+
tree Account {
|
|
126
|
+
owner: str
|
|
127
|
+
balance: float = 0.0
|
|
128
|
+
|
|
129
|
+
branch to_str() -> str => "{self.owner}: {self.balance:.2}"
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
````
|
|
133
|
+
|
|
134
|
+
### From Python
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
from pygments import highlight
|
|
138
|
+
from pygments.formatters import HtmlFormatter
|
|
139
|
+
from pygments.lexers import get_lexer_by_name
|
|
140
|
+
|
|
141
|
+
html = highlight('drop("Hello, {name}!")', get_lexer_by_name("plum"), HtmlFormatter())
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
`from pygments_plum import PlumLexer` works too.
|
|
145
|
+
|
|
146
|
+
## Development
|
|
147
|
+
|
|
148
|
+
```sh
|
|
149
|
+
python -m venv .venv
|
|
150
|
+
.venv/bin/pip install -e '.[test]'
|
|
151
|
+
.venv/bin/pytest
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
The tests lex every program in `tests/examples/` (a copy of Plumlang's
|
|
155
|
+
examples and language tests), checking that no `Error` token appears and
|
|
156
|
+
that the tokens put back together give the input unchanged, then check the
|
|
157
|
+
tokens of keywords, strings, interpolation, numbers and comments one by one,
|
|
158
|
+
and that Pygments finds the lexer through its entry point. To run the first
|
|
159
|
+
test over a full Plumlang checkout as well, point `PLUM_SOURCE` at it:
|
|
160
|
+
|
|
161
|
+
```sh
|
|
162
|
+
PLUM_SOURCE=../plumlang .venv/bin/pytest
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Links
|
|
166
|
+
|
|
167
|
+
- Plumlang: <https://plum.elixpo.com>
|
|
168
|
+
- Docs: <https://plum.elixpo.com/docs/>
|
|
169
|
+
- Language specification: <https://github.com/plumlang/plumlang/blob/main/docs/spec.md>
|
|
170
|
+
- Tree-sitter grammar: <https://github.com/plumlang/tree-sitter-plum>
|
|
171
|
+
- Writing Pygments plugins: <https://pygments.org/docs/plugins/>
|
|
172
|
+
|
|
173
|
+
## Licence
|
|
174
|
+
|
|
175
|
+
The code in this repository is under the [MIT licence](LICENSE). The
|
|
176
|
+
Plumlang name and logo are trademarks of Elixpo and are not licensed by it;
|
|
177
|
+
see [NOTICE](NOTICE).
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Plumlang for Pygments
|
|
2
|
+
|
|
3
|
+
A [Pygments](https://pygments.org) lexer plugin for
|
|
4
|
+
[Plumlang](https://plum.elixpo.com), for `.plum` files. Once it is
|
|
5
|
+
installed, everything that highlights code with Pygments knows Plumlang:
|
|
6
|
+
Sphinx, MkDocs (Material included), `pygmentize`, Jupyter, and the many
|
|
7
|
+
static site generators and chat tools built on Pygments.
|
|
8
|
+
|
|
9
|
+
It highlights:
|
|
10
|
+
|
|
11
|
+
- **Keywords**: declarations (`plant`, `root`, `branch`, `tree`, `trait`,
|
|
12
|
+
`kind`), `seed` imports with their module paths and aliases, control flow,
|
|
13
|
+
`and`/`or`/`not`/`in`/`is`/`as`, and the constants `good`, `bad` and
|
|
14
|
+
`none`.
|
|
15
|
+
- **Names at declarations**: functions and methods after `branch`, trees,
|
|
16
|
+
traits and kinds after their keyword, constants after `root`.
|
|
17
|
+
- **Types and built-ins**: `int`, `str`, `list`, `map`, ...; the built-in
|
|
18
|
+
functions (`drop`, `ask`, `len`, ...); conversions such as `int(text)`;
|
|
19
|
+
the built-in error trees (`ValueError`, `IOError`, ...); `self` and
|
|
20
|
+
`super`.
|
|
21
|
+
- **Strings** with escapes (`\n`, `\{`, `\u{1F351}`) and `{interpolation}`,
|
|
22
|
+
whose expression is highlighted like any other code, with format specs
|
|
23
|
+
(`{total:.2}`, `{n:>5}`); `"""` strings across lines.
|
|
24
|
+
- **Numbers** in every form (`1_000`, `0xFF`, `0o755`, `0b1010`, `6.022e23`),
|
|
25
|
+
operators, punctuation and `#` comments.
|
|
26
|
+
|
|
27
|
+
The rules follow the reference lexer in
|
|
28
|
+
[plumlang/plumlang](https://github.com/plumlang/plumlang). The lexer never
|
|
29
|
+
produces Pygments' `Error` token: code the compiler would reject (`&&`, a
|
|
30
|
+
`'single-quoted'` string, a bad escape) is still highlighted sensibly.
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
pip install pygments-plum
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The package registers itself with Pygments through the `pygments.lexers`
|
|
39
|
+
entry point, so nothing else needs configuring. Check it with:
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
pygmentize -L lexers | grep -A1 Plumlang
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Use
|
|
46
|
+
|
|
47
|
+
The lexer's names are `plum` and `plumlang`; it is picked for `*.plum` files
|
|
48
|
+
and the `text/x-plum` MIME type.
|
|
49
|
+
|
|
50
|
+
### On the command line
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
pygmentize -l plum hello.plum # to the terminal
|
|
54
|
+
pygmentize -l plum -f terminal256 -O style=monokai hello.plum
|
|
55
|
+
pygmentize -l plum -f html -O full -o hello.html hello.plum
|
|
56
|
+
pygmentize hello.plum # picked by the .plum suffix
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### In Sphinx
|
|
60
|
+
|
|
61
|
+
Add `pygments-plum` to your docs' requirements (for example
|
|
62
|
+
`docs/requirements.txt` on Read the Docs), then write:
|
|
63
|
+
|
|
64
|
+
````rst
|
|
65
|
+
.. code-block:: plum
|
|
66
|
+
|
|
67
|
+
plant name = "Ada"
|
|
68
|
+
drop("Hello, {name}!")
|
|
69
|
+
````
|
|
70
|
+
|
|
71
|
+
or, with MyST Markdown, a ```` ```plum ```` fence.
|
|
72
|
+
|
|
73
|
+
### In MkDocs
|
|
74
|
+
|
|
75
|
+
With [`pymdownx.highlight`](https://facelessuser.github.io/pymdown-extensions/extensions/highlight/)
|
|
76
|
+
and `pymdownx.superfences` (Material for MkDocs turns them on in its
|
|
77
|
+
recommended setup), add `pygments-plum` to the requirements your docs are
|
|
78
|
+
built with and use ```` ```plum ```` fences:
|
|
79
|
+
|
|
80
|
+
```yaml
|
|
81
|
+
# mkdocs.yml
|
|
82
|
+
markdown_extensions:
|
|
83
|
+
- pymdownx.highlight:
|
|
84
|
+
use_pygments: true
|
|
85
|
+
- pymdownx.superfences
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
````markdown
|
|
89
|
+
```plum
|
|
90
|
+
tree Account {
|
|
91
|
+
owner: str
|
|
92
|
+
balance: float = 0.0
|
|
93
|
+
|
|
94
|
+
branch to_str() -> str => "{self.owner}: {self.balance:.2}"
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
````
|
|
98
|
+
|
|
99
|
+
### From Python
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from pygments import highlight
|
|
103
|
+
from pygments.formatters import HtmlFormatter
|
|
104
|
+
from pygments.lexers import get_lexer_by_name
|
|
105
|
+
|
|
106
|
+
html = highlight('drop("Hello, {name}!")', get_lexer_by_name("plum"), HtmlFormatter())
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`from pygments_plum import PlumLexer` works too.
|
|
110
|
+
|
|
111
|
+
## Development
|
|
112
|
+
|
|
113
|
+
```sh
|
|
114
|
+
python -m venv .venv
|
|
115
|
+
.venv/bin/pip install -e '.[test]'
|
|
116
|
+
.venv/bin/pytest
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
The tests lex every program in `tests/examples/` (a copy of Plumlang's
|
|
120
|
+
examples and language tests), checking that no `Error` token appears and
|
|
121
|
+
that the tokens put back together give the input unchanged, then check the
|
|
122
|
+
tokens of keywords, strings, interpolation, numbers and comments one by one,
|
|
123
|
+
and that Pygments finds the lexer through its entry point. To run the first
|
|
124
|
+
test over a full Plumlang checkout as well, point `PLUM_SOURCE` at it:
|
|
125
|
+
|
|
126
|
+
```sh
|
|
127
|
+
PLUM_SOURCE=../plumlang .venv/bin/pytest
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Links
|
|
131
|
+
|
|
132
|
+
- Plumlang: <https://plum.elixpo.com>
|
|
133
|
+
- Docs: <https://plum.elixpo.com/docs/>
|
|
134
|
+
- Language specification: <https://github.com/plumlang/plumlang/blob/main/docs/spec.md>
|
|
135
|
+
- Tree-sitter grammar: <https://github.com/plumlang/tree-sitter-plum>
|
|
136
|
+
- Writing Pygments plugins: <https://pygments.org/docs/plugins/>
|
|
137
|
+
|
|
138
|
+
## Licence
|
|
139
|
+
|
|
140
|
+
The code in this repository is under the [MIT licence](LICENSE). The
|
|
141
|
+
Plumlang name and logo are trademarks of Elixpo and are not licensed by it;
|
|
142
|
+
see [NOTICE](NOTICE).
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"""
|
|
2
|
+
pygments_plum
|
|
3
|
+
~~~~~~~~~~~~~
|
|
4
|
+
|
|
5
|
+
A Pygments lexer for Plumlang (https://plum.elixpo.com).
|
|
6
|
+
|
|
7
|
+
The rules follow the reference lexer in plumlang/plumlang
|
|
8
|
+
(src/lexer/lexer.c): its keyword table, number forms, strings with
|
|
9
|
+
``{...}`` interpolation and ``:format`` specs, ``\"\"\"`` strings that
|
|
10
|
+
span lines, and ``#`` line comments.
|
|
11
|
+
|
|
12
|
+
Where the compiler reports an error (``&&``, ``;``, ``'single'``
|
|
13
|
+
quotes, a bad escape) the lexer still highlights the text sensibly
|
|
14
|
+
and never emits ``Token.Error``: diagnostics are the compiler's job.
|
|
15
|
+
|
|
16
|
+
:copyright: Copyright 2026 Elixpo and the Plumlang contributors.
|
|
17
|
+
:license: MIT, see LICENSE for details.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from pygments.lexer import RegexLexer, bygroups, default, include, words
|
|
21
|
+
from pygments.token import (
|
|
22
|
+
Comment,
|
|
23
|
+
Keyword,
|
|
24
|
+
Name,
|
|
25
|
+
Number,
|
|
26
|
+
Operator,
|
|
27
|
+
Punctuation,
|
|
28
|
+
String,
|
|
29
|
+
Text,
|
|
30
|
+
Whitespace,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
__version__ = "1.0.0"
|
|
34
|
+
__all__ = ["PlumLexer"]
|
|
35
|
+
|
|
36
|
+
IDENT = r"[A-Za-z_][A-Za-z0-9_]*"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class PlumLexer(RegexLexer):
|
|
40
|
+
"""
|
|
41
|
+
For Plumlang source code.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
name = "Plumlang"
|
|
45
|
+
url = "https://plum.elixpo.com"
|
|
46
|
+
aliases = ["plum", "plumlang"]
|
|
47
|
+
filenames = ["*.plum"]
|
|
48
|
+
mimetypes = ["text/x-plum"]
|
|
49
|
+
|
|
50
|
+
# Statements that are mostly control flow.
|
|
51
|
+
keywords = (
|
|
52
|
+
"if", "else", "match", "for", "while", "break", "continue", "return",
|
|
53
|
+
"try", "catch", "finally", "throw", "spawn", "weak",
|
|
54
|
+
)
|
|
55
|
+
# `true`/`false` are accepted spellings of `good`/`bad`.
|
|
56
|
+
constants = ("good", "bad", "true", "false", "none")
|
|
57
|
+
word_operators = ("and", "or", "not", "in", "is", "as")
|
|
58
|
+
# Built-in functions (spec section 7): always available, no `seed`.
|
|
59
|
+
builtin_functions = ("drop", "ask", "len", "type_of", "assert", "exit")
|
|
60
|
+
# Built-in types; the scalar ones double as conversion functions.
|
|
61
|
+
builtin_types = ("int", "float", "bool", "str", "byte", "list", "map", "set",
|
|
62
|
+
"Channel", "Json")
|
|
63
|
+
conversions = ("int", "float", "str", "byte", "set")
|
|
64
|
+
# Built-in error trees.
|
|
65
|
+
errors = (
|
|
66
|
+
"Error", "ValueError", "ParseError", "IndexError", "KeyError",
|
|
67
|
+
"OverflowError", "ZeroDivisionError", "IOError", "NetError",
|
|
68
|
+
"AssertError",
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
tokens = {
|
|
72
|
+
"root": [
|
|
73
|
+
include("expr"),
|
|
74
|
+
],
|
|
75
|
+
"expr": [
|
|
76
|
+
(r"\s+", Whitespace),
|
|
77
|
+
(r"#[^\n]*", Comment.Single),
|
|
78
|
+
|
|
79
|
+
# Strings. `"""` first, so it isn't read as an empty string.
|
|
80
|
+
(r'"""', String.Double, "tdqs"),
|
|
81
|
+
(r'"', String.Double, "dqs"),
|
|
82
|
+
# Single quotes are an error in Plumlang, but the compiler still
|
|
83
|
+
# reads them as a string up to the end of the line.
|
|
84
|
+
(r"'[^'\n]*'?", String.Single),
|
|
85
|
+
|
|
86
|
+
# A member after `.` or `?.`: a field or method, never a
|
|
87
|
+
# keyword or built-in (`s.len()`, `e.message`).
|
|
88
|
+
(r"(\?\.)(" + IDENT + r")", bygroups(Operator, Name.Attribute)),
|
|
89
|
+
(r"(\.)(" + IDENT + r")", bygroups(Punctuation, Name.Attribute)),
|
|
90
|
+
|
|
91
|
+
# Declarations.
|
|
92
|
+
(r"(seed)\b", Keyword.Namespace, "seed"),
|
|
93
|
+
(r"(branch)([ \t]+)(" + IDENT + r")",
|
|
94
|
+
bygroups(Keyword.Declaration, Whitespace, Name.Function)),
|
|
95
|
+
(r"(tree|trait|kind)([ \t]+)(" + IDENT + r")",
|
|
96
|
+
bygroups(Keyword.Declaration, Whitespace, Name.Class)),
|
|
97
|
+
(r"(root)([ \t]+)(" + IDENT + r")",
|
|
98
|
+
bygroups(Keyword.Declaration, Whitespace, Name.Constant)),
|
|
99
|
+
(r"(plant)([ \t]+)(" + IDENT + r")",
|
|
100
|
+
bygroups(Keyword.Declaration, Whitespace, Name.Variable)),
|
|
101
|
+
(words(("plant", "root", "branch", "tree", "trait", "kind"),
|
|
102
|
+
suffix=r"\b"), Keyword.Declaration),
|
|
103
|
+
|
|
104
|
+
# Keywords.
|
|
105
|
+
(words(constants, suffix=r"\b"), Keyword.Constant),
|
|
106
|
+
(words(word_operators, suffix=r"\b"), Operator.Word),
|
|
107
|
+
(words(keywords, suffix=r"\b"), Keyword),
|
|
108
|
+
(words(("self", "super"), suffix=r"\b"), Name.Builtin.Pseudo),
|
|
109
|
+
(r"_\b", Keyword.Pseudo),
|
|
110
|
+
|
|
111
|
+
# Numbers. A fraction needs a digit after the point: `1..5`
|
|
112
|
+
# is a range and `1.max()` a method call.
|
|
113
|
+
(r"0[xX][0-9a-fA-F_]*", Number.Hex),
|
|
114
|
+
(r"0[oO][0-7_]*", Number.Oct),
|
|
115
|
+
(r"0[bB][01_]*", Number.Bin),
|
|
116
|
+
(r"[0-9][0-9_]*(\.[0-9][0-9_]*)?[eE][+-]?[0-9_]*", Number.Float),
|
|
117
|
+
(r"[0-9][0-9_]*\.[0-9][0-9_]*", Number.Float),
|
|
118
|
+
(r"[0-9][0-9_]*", Number.Integer),
|
|
119
|
+
|
|
120
|
+
# Names.
|
|
121
|
+
(words(builtin_functions, suffix=r"\b"), Name.Builtin),
|
|
122
|
+
(words(conversions, suffix=r"\b(?=\s*\()"), Name.Builtin),
|
|
123
|
+
(words(builtin_types, suffix=r"\b"), Keyword.Type),
|
|
124
|
+
(words(errors, suffix=r"\b"), Name.Exception),
|
|
125
|
+
(r"_*[A-Z][A-Z0-9_]*\b", Name.Constant),
|
|
126
|
+
(r"_*[A-Z][A-Za-z0-9_]*", Name.Class),
|
|
127
|
+
(IDENT, Name),
|
|
128
|
+
|
|
129
|
+
# Operators, longest first. `&&`, `||`, `++`, `--` and `!` are
|
|
130
|
+
# errors the compiler explains; they still look like operators.
|
|
131
|
+
(r"//=|\*\*=|<<=|>>=|\.\.=|\.\.|->|=>|\?\.|\?\?|//|\*\*|<<|>>"
|
|
132
|
+
r"|[=!<>+\-*/%&|^]=|&&|\|\||\+\+|--|[-+*/%&|^~<>=?!]", Operator),
|
|
133
|
+
(r"[()\[\]{},:.;]", Punctuation),
|
|
134
|
+
|
|
135
|
+
# Anything else (stray or non-ASCII characters outside strings).
|
|
136
|
+
(r".", Text),
|
|
137
|
+
],
|
|
138
|
+
"seed": [
|
|
139
|
+
(r"[ \t]+", Whitespace),
|
|
140
|
+
(r"as\b", Keyword.Namespace),
|
|
141
|
+
(r"\.{1,2}/[A-Za-z0-9_./-]*", Name.Namespace),
|
|
142
|
+
(IDENT + r"(?:\." + IDENT + r")*", Name.Namespace),
|
|
143
|
+
default("#pop"),
|
|
144
|
+
],
|
|
145
|
+
"escapes": [
|
|
146
|
+
(r'\\(?:[ntr\\"{}0]|u\{[0-9a-fA-F]{1,6}\})', String.Escape),
|
|
147
|
+
# An unknown escape: an error the compiler reports.
|
|
148
|
+
(r"\\", String.Double),
|
|
149
|
+
],
|
|
150
|
+
"dqs": [
|
|
151
|
+
(r'"', String.Double, "#pop"),
|
|
152
|
+
# A newline ends an unclosed string, as in the compiler.
|
|
153
|
+
(r"\n", Whitespace, "#pop"),
|
|
154
|
+
include("escapes"),
|
|
155
|
+
(r"\{", String.Interpol, "interp"),
|
|
156
|
+
(r'[^"\\{\n]+', String.Double),
|
|
157
|
+
],
|
|
158
|
+
"tdqs": [
|
|
159
|
+
(r'"""', String.Double, "#pop"),
|
|
160
|
+
include("escapes"),
|
|
161
|
+
(r"\{", String.Interpol, "interp"),
|
|
162
|
+
(r'[^"\\{]+', String.Double),
|
|
163
|
+
(r'"', String.Double),
|
|
164
|
+
],
|
|
165
|
+
# Inside `{...}` in a string: an ordinary expression. A `:` at the
|
|
166
|
+
# top level of the interpolation starts a format spec, which runs
|
|
167
|
+
# to the `}` (or a quote or newline): "{x:>5}", "{total:.2}".
|
|
168
|
+
"interp": [
|
|
169
|
+
(r"\}", String.Interpol, "#pop"),
|
|
170
|
+
(r':[^}"\n]*', String.Interpol),
|
|
171
|
+
(r"[(\[{]", Punctuation, "interp-nested"),
|
|
172
|
+
include("expr"),
|
|
173
|
+
],
|
|
174
|
+
# Brackets inside an interpolation; here `:` and `}` are ordinary.
|
|
175
|
+
"interp-nested": [
|
|
176
|
+
(r"[)\]}]", Punctuation, "#pop"),
|
|
177
|
+
(r"[(\[{]", Punctuation, "#push"),
|
|
178
|
+
include("expr"),
|
|
179
|
+
],
|
|
180
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pygments-plum"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Plumlang lexer plugin for Pygments: highlighting in Sphinx, MkDocs and anything else that uses Pygments"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
authors = [{ name = "Elixpo and the Plumlang contributors", email = "hello@elixpo.com" }]
|
|
14
|
+
keywords = ["pygments", "lexer", "syntax highlighting", "plumlang", "plum"]
|
|
15
|
+
# 2.13 is the first Pygments that finds plugins with importlib.metadata;
|
|
16
|
+
# 2.12 needs pkg_resources, which current setuptools and Python no longer ship.
|
|
17
|
+
dependencies = ["pygments>=2.13"]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Development Status :: 4 - Beta",
|
|
20
|
+
"Environment :: Plugins",
|
|
21
|
+
"Framework :: Sphinx :: Extension",
|
|
22
|
+
"Intended Audience :: Developers",
|
|
23
|
+
"Operating System :: OS Independent",
|
|
24
|
+
"Programming Language :: Python :: 3",
|
|
25
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
26
|
+
"Programming Language :: Python :: 3.10",
|
|
27
|
+
"Programming Language :: Python :: 3.11",
|
|
28
|
+
"Programming Language :: Python :: 3.12",
|
|
29
|
+
"Programming Language :: Python :: 3.13",
|
|
30
|
+
"Programming Language :: Python :: 3.14",
|
|
31
|
+
"Topic :: Documentation",
|
|
32
|
+
"Topic :: Software Development :: Documentation",
|
|
33
|
+
"Topic :: Text Processing :: Filters",
|
|
34
|
+
"Topic :: Text Processing :: Markup",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
Homepage = "https://plum.elixpo.com"
|
|
39
|
+
Source = "https://github.com/plumlang/pygments-plum"
|
|
40
|
+
Issues = "https://github.com/plumlang/pygments-plum/issues"
|
|
41
|
+
Plumlang = "https://github.com/plumlang/plumlang"
|
|
42
|
+
|
|
43
|
+
[project.optional-dependencies]
|
|
44
|
+
test = ["pytest>=7"]
|
|
45
|
+
|
|
46
|
+
# Pygments finds the lexer through this entry point: `pygmentize -l plum`,
|
|
47
|
+
# `get_lexer_by_name("plum")`, Sphinx and MkDocs all use it.
|
|
48
|
+
[project.entry-points."pygments.lexers"]
|
|
49
|
+
plum = "pygments_plum:PlumLexer"
|
|
50
|
+
|
|
51
|
+
[tool.hatch.version]
|
|
52
|
+
path = "pygments_plum/__init__.py"
|
|
53
|
+
|
|
54
|
+
[tool.hatch.build.targets.sdist]
|
|
55
|
+
include = ["pygments_plum", "tests", "LICENSE", "NOTICE", "README.md"]
|
|
56
|
+
|
|
57
|
+
[tool.pytest.ini_options]
|
|
58
|
+
testpaths = ["tests"]
|