tree-sitter-pgn 1.2.11__cp39-abi3-musllinux_1_2_aarch64.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.
Potentially problematic release.
This version of tree-sitter-pgn might be problematic. Click here for more details.
- tree_sitter_pgn/__init__.py +5 -0
- tree_sitter_pgn/__init__.pyi +1 -0
- tree_sitter_pgn/_binding.abi3.so +0 -0
- tree_sitter_pgn/binding.c +27 -0
- tree_sitter_pgn/py.typed +0 -0
- tree_sitter_pgn/queries/highlights.scm +27 -0
- tree_sitter_pgn-1.2.11.dist-info/METADATA +80 -0
- tree_sitter_pgn-1.2.11.dist-info/RECORD +10 -0
- tree_sitter_pgn-1.2.11.dist-info/WHEEL +5 -0
- tree_sitter_pgn-1.2.11.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
def language() -> int: ...
|
|
Binary file
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#include <Python.h>
|
|
2
|
+
|
|
3
|
+
typedef struct TSLanguage TSLanguage;
|
|
4
|
+
|
|
5
|
+
TSLanguage *tree_sitter_pgn(void);
|
|
6
|
+
|
|
7
|
+
static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) {
|
|
8
|
+
return PyCapsule_New(tree_sitter_pgn(), "tree_sitter.Language", NULL);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static PyMethodDef methods[] = {
|
|
12
|
+
{"language", _binding_language, METH_NOARGS,
|
|
13
|
+
"Get the tree-sitter language for this grammar."},
|
|
14
|
+
{NULL, NULL, 0, NULL}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
static struct PyModuleDef module = {
|
|
18
|
+
.m_base = PyModuleDef_HEAD_INIT,
|
|
19
|
+
.m_name = "_binding",
|
|
20
|
+
.m_doc = NULL,
|
|
21
|
+
.m_size = -1,
|
|
22
|
+
.m_methods = methods
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
PyMODINIT_FUNC PyInit__binding(void) {
|
|
26
|
+
return PyModule_Create(&module);
|
|
27
|
+
}
|
tree_sitter_pgn/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
; highlights.scm
|
|
2
|
+
|
|
3
|
+
[
|
|
4
|
+
(annotation)
|
|
5
|
+
(inline_comment)
|
|
6
|
+
(rest_of_line_comment)
|
|
7
|
+
(old_style_twic_section_comment)
|
|
8
|
+
] @comment
|
|
9
|
+
|
|
10
|
+
(tagpair_delimiter_open) @punctuation.bracket
|
|
11
|
+
(tagpair_delimiter_close) @punctuation.bracket
|
|
12
|
+
(tagpair_key) @type
|
|
13
|
+
(tagpair tagpair_value_delimiter: (double_quote) @string)
|
|
14
|
+
(tagpair_value_contents) @string
|
|
15
|
+
|
|
16
|
+
(movetext (move_number) @function)
|
|
17
|
+
(movetext (san_move) @function)
|
|
18
|
+
(movetext (lan_move) @function)
|
|
19
|
+
|
|
20
|
+
(variation_delimiter_open) @operator
|
|
21
|
+
(variation_delimiter_close) @operator
|
|
22
|
+
(variation_movetext variation_san_move: (san_move) @operator)
|
|
23
|
+
(variation_movetext variation_move_number: (move_number) @operator)
|
|
24
|
+
|
|
25
|
+
(result_code) @variable
|
|
26
|
+
|
|
27
|
+
(ERROR) @property
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tree-sitter-pgn
|
|
3
|
+
Version: 1.2.11
|
|
4
|
+
Summary: PGN grammar for tree-sitter
|
|
5
|
+
License: BSD-2-Clause
|
|
6
|
+
Project-URL: Homepage, https://github.com/rolandwalker/tree-sitter-pgn
|
|
7
|
+
Keywords: incremental,parsing,tree-sitter,PGN,chess
|
|
8
|
+
Classifier: Intended Audience :: Developers
|
|
9
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
10
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
11
|
+
Classifier: Typing :: Typed
|
|
12
|
+
Requires-Python: >=3.9
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
Provides-Extra: core
|
|
15
|
+
Requires-Dist: tree-sitter~=0.23.0; extra == "core"
|
|
16
|
+
|
|
17
|
+
# tree-sitter-pgn
|
|
18
|
+
|
|
19
|
+
## Overview
|
|
20
|
+
|
|
21
|
+
Chess Portable Game Notation (PGN) grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter).
|
|
22
|
+
|
|
23
|
+
## Used in
|
|
24
|
+
|
|
25
|
+
* [Emacs pygn-mode](https://github.com/dwcoates/pygn-mode)
|
|
26
|
+
|
|
27
|
+
## Highlighting Example
|
|
28
|
+
|
|
29
|
+
<a href="/doc/images/pgn_syntax_highlight.png">
|
|
30
|
+
<img src="/doc/images/pgn_syntax_highlight.png" width=500/>
|
|
31
|
+
</a>
|
|
32
|
+
|
|
33
|
+
## Python Example
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
import more_itertools
|
|
37
|
+
from tree_sitter import Language, Parser
|
|
38
|
+
import tree_sitter_pgn as ts_pgn
|
|
39
|
+
|
|
40
|
+
PGN_LANGUAGE = Language(ts_pgn.language())
|
|
41
|
+
parser = Parser(PGN_LANGUAGE)
|
|
42
|
+
|
|
43
|
+
query = PGN_LANGUAGE.query(
|
|
44
|
+
'''
|
|
45
|
+
(series_of_games
|
|
46
|
+
game: (game) @game)
|
|
47
|
+
|
|
48
|
+
(movetext
|
|
49
|
+
san_move: (san_move) @san_move)
|
|
50
|
+
|
|
51
|
+
(movetext
|
|
52
|
+
lan_move: (lan_move) @lan_move)
|
|
53
|
+
''')
|
|
54
|
+
|
|
55
|
+
with open('input_file.pgn', 'rb') as file:
|
|
56
|
+
tree = parser.parse(file.read())
|
|
57
|
+
|
|
58
|
+
matches = query.captures(tree.root_node)
|
|
59
|
+
|
|
60
|
+
merged_nodes = [
|
|
61
|
+
*matches.get('game', []),
|
|
62
|
+
*matches.get('san_move', []),
|
|
63
|
+
*matches.get('lan_move', []),
|
|
64
|
+
]
|
|
65
|
+
merged_nodes = sorted(merged_nodes, key=lambda elt: elt.start_byte)
|
|
66
|
+
|
|
67
|
+
for game in more_itertools.split_before(merged_nodes, lambda node: node.type == 'game'):
|
|
68
|
+
main_line = []
|
|
69
|
+
for node in game:
|
|
70
|
+
if node.type in ['san_move', 'lan_move'] and node.text is not None:
|
|
71
|
+
main_line.append(node.text.decode().strip())
|
|
72
|
+
continue
|
|
73
|
+
print(' '.join(main_line))
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## References
|
|
77
|
+
|
|
78
|
+
* [PGN specification](http://www.saremba.de/chessgml/standards/pgn/pgn-complete.htm)
|
|
79
|
+
* [Commonly-used extensions](https://www.enpassant.dk/chess/palview/enhancedpgn.htm)
|
|
80
|
+
* [Commonly-used annotation glyphs](https://en.wikipedia.org/wiki/Numeric_Annotation_Glyphs)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
tree_sitter_pgn/__init__.py,sha256=ZiLr1Q0znhhSjnr-HOQ9eYQGPl377jelB9rBPHWpUFc,86
|
|
2
|
+
tree_sitter_pgn/__init__.pyi,sha256=8xf7bY1szgDY9HRJ7FJ326So4SFgMiSRfCB4LADkTpU,27
|
|
3
|
+
tree_sitter_pgn/_binding.abi3.so,sha256=ocFcDHfv8erBEoV9ARrJdtbCT6pb_igg16Ky4GSXHrw,484144
|
|
4
|
+
tree_sitter_pgn/binding.c,sha256=f0wnkjshn03m8OnEMcCgHzXlieObCAo50sacARwJ4-Y,677
|
|
5
|
+
tree_sitter_pgn/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
tree_sitter_pgn/queries/highlights.scm,sha256=f0ZNijh1NqOo3M4c2ChC0ra5SjPtFmR0CJg_-gcrSUU,676
|
|
7
|
+
tree_sitter_pgn-1.2.11.dist-info/METADATA,sha256=1CgoVF8jwuum5Uymx0_Oe8pyG1gDYQN43Qk9AUlAkUk,2221
|
|
8
|
+
tree_sitter_pgn-1.2.11.dist-info/WHEEL,sha256=wOOB8EmKygf3LfHW4B__m6mFQ5tZ28wpdI0sU1MRnJQ,111
|
|
9
|
+
tree_sitter_pgn-1.2.11.dist-info/top_level.txt,sha256=GT5VMTItAEXgTjoJj2gP_fQVqZd7tY5TIRpOgyp1zlU,25
|
|
10
|
+
tree_sitter_pgn-1.2.11.dist-info/RECORD,,
|