pygments-plum 1.0.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,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,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,7 @@
1
+ pygments_plum/__init__.py,sha256=NSyTeJsXiY23xl9ph-4sFPVPzVblPlpBZT4AVW038pg,7033
2
+ pygments_plum-1.0.0.dist-info/METADATA,sha256=enpRV1ezqPWi8cNVnbrFJqCPfjg_H6RJVTq2SFG1kcY,5956
3
+ pygments_plum-1.0.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
4
+ pygments_plum-1.0.0.dist-info/entry_points.txt,sha256=ZXvrGVIofMW37vftgjP_a7lhEGQrH3SI9MdHQwIHWKI,49
5
+ pygments_plum-1.0.0.dist-info/licenses/LICENSE,sha256=UjUaBGqop89OVTW136DUXi3G01BeeZqivMuF7mM4LI8,1093
6
+ pygments_plum-1.0.0.dist-info/licenses/NOTICE,sha256=KpiRM8oyPYtjNZDvljPkRXSGfmJyiO3pFEW4Tcf9zrY,1576
7
+ pygments_plum-1.0.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
+ plum = pygments_plum:PlumLexer
@@ -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