tree-sitter-pgn 1.3.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.
- tree_sitter_pgn-1.3.0/PKG-INFO +93 -0
- tree_sitter_pgn-1.3.0/README.md +77 -0
- tree_sitter_pgn-1.3.0/bindings/python/tree_sitter_pgn/__init__.py +5 -0
- tree_sitter_pgn-1.3.0/bindings/python/tree_sitter_pgn/__init__.pyi +1 -0
- tree_sitter_pgn-1.3.0/bindings/python/tree_sitter_pgn/binding.c +27 -0
- tree_sitter_pgn-1.3.0/bindings/python/tree_sitter_pgn/py.typed +0 -0
- tree_sitter_pgn-1.3.0/bindings/python/tree_sitter_pgn.egg-info/PKG-INFO +93 -0
- tree_sitter_pgn-1.3.0/bindings/python/tree_sitter_pgn.egg-info/SOURCES.txt +19 -0
- tree_sitter_pgn-1.3.0/bindings/python/tree_sitter_pgn.egg-info/dependency_links.txt +1 -0
- tree_sitter_pgn-1.3.0/bindings/python/tree_sitter_pgn.egg-info/not-zip-safe +1 -0
- tree_sitter_pgn-1.3.0/bindings/python/tree_sitter_pgn.egg-info/requires.txt +3 -0
- tree_sitter_pgn-1.3.0/bindings/python/tree_sitter_pgn.egg-info/top_level.txt +2 -0
- tree_sitter_pgn-1.3.0/pyproject.toml +43 -0
- tree_sitter_pgn-1.3.0/setup.cfg +4 -0
- tree_sitter_pgn-1.3.0/setup.py +60 -0
- tree_sitter_pgn-1.3.0/src/parser.c +29076 -0
- tree_sitter_pgn-1.3.0/src/scanner.c +42 -0
- tree_sitter_pgn-1.3.0/src/tree_sitter/alloc.h +54 -0
- tree_sitter_pgn-1.3.0/src/tree_sitter/array.h +291 -0
- tree_sitter_pgn-1.3.0/src/tree_sitter/parser.h +286 -0
- tree_sitter_pgn-1.3.0/tree-sitter.json +36 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tree-sitter-pgn
|
|
3
|
+
Version: 1.3.0
|
|
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.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
Provides-Extra: core
|
|
15
|
+
Requires-Dist: tree-sitter~=0.25.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
|
+
from tree_sitter import Language, Parser, Query, QueryCursor
|
|
37
|
+
import tree_sitter_pgn as ts_pgn
|
|
38
|
+
|
|
39
|
+
PGN_LANGUAGE = Language(ts_pgn.language())
|
|
40
|
+
|
|
41
|
+
PARSER = Parser(PGN_LANGUAGE)
|
|
42
|
+
|
|
43
|
+
# Query for game boundaries and main-line moves.
|
|
44
|
+
# Ignore all headers, comments, variations, and result codes.
|
|
45
|
+
QUERY = Query(
|
|
46
|
+
PGN_LANGUAGE,
|
|
47
|
+
"""
|
|
48
|
+
(series_of_games
|
|
49
|
+
game: (game) @game)
|
|
50
|
+
|
|
51
|
+
(game
|
|
52
|
+
(movetext
|
|
53
|
+
san_move: (san_move) @san_move))
|
|
54
|
+
""",
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def emit_output(main_line: list[bytes | None]) -> None:
|
|
59
|
+
if not main_line:
|
|
60
|
+
return
|
|
61
|
+
# eg: d4 d5 c4 c6 Nc3 Nf6 Nf3 e6 e3 Nbd7 Bd3 dc4
|
|
62
|
+
print(' '.join(x.decode().strip() for x in main_line if x is not None))
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def main() -> None:
|
|
66
|
+
with open('multi_game.pgn', 'rb') as file:
|
|
67
|
+
tree = PARSER.parse(file.read())
|
|
68
|
+
|
|
69
|
+
query_cursor = QueryCursor(QUERY)
|
|
70
|
+
matches = query_cursor.matches(tree.root_node)
|
|
71
|
+
|
|
72
|
+
main_line: list[bytes | None] = []
|
|
73
|
+
for item in matches:
|
|
74
|
+
if item[1].get('game'):
|
|
75
|
+
emit_output(main_line)
|
|
76
|
+
main_line = []
|
|
77
|
+
continue
|
|
78
|
+
if nodes := item[1].get('san_move'):
|
|
79
|
+
main_line.append(nodes[0].text)
|
|
80
|
+
continue
|
|
81
|
+
|
|
82
|
+
emit_output(main_line)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
if __name__ == '__main__':
|
|
86
|
+
main()
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## References
|
|
90
|
+
|
|
91
|
+
* [PGN specification](http://www.saremba.de/chessgml/standards/pgn/pgn-complete.htm)
|
|
92
|
+
* [Commonly-used extensions](https://www.enpassant.dk/chess/palview/enhancedpgn.htm)
|
|
93
|
+
* [Commonly-used annotation glyphs](https://en.wikipedia.org/wiki/Numeric_Annotation_Glyphs)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# tree-sitter-pgn
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Chess Portable Game Notation (PGN) grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter).
|
|
6
|
+
|
|
7
|
+
## Used in
|
|
8
|
+
|
|
9
|
+
* [Emacs pygn-mode](https://github.com/dwcoates/pygn-mode)
|
|
10
|
+
|
|
11
|
+
## Highlighting Example
|
|
12
|
+
|
|
13
|
+
<a href="/doc/images/pgn_syntax_highlight.png">
|
|
14
|
+
<img src="/doc/images/pgn_syntax_highlight.png" width=500/>
|
|
15
|
+
</a>
|
|
16
|
+
|
|
17
|
+
## Python Example
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from tree_sitter import Language, Parser, Query, QueryCursor
|
|
21
|
+
import tree_sitter_pgn as ts_pgn
|
|
22
|
+
|
|
23
|
+
PGN_LANGUAGE = Language(ts_pgn.language())
|
|
24
|
+
|
|
25
|
+
PARSER = Parser(PGN_LANGUAGE)
|
|
26
|
+
|
|
27
|
+
# Query for game boundaries and main-line moves.
|
|
28
|
+
# Ignore all headers, comments, variations, and result codes.
|
|
29
|
+
QUERY = Query(
|
|
30
|
+
PGN_LANGUAGE,
|
|
31
|
+
"""
|
|
32
|
+
(series_of_games
|
|
33
|
+
game: (game) @game)
|
|
34
|
+
|
|
35
|
+
(game
|
|
36
|
+
(movetext
|
|
37
|
+
san_move: (san_move) @san_move))
|
|
38
|
+
""",
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def emit_output(main_line: list[bytes | None]) -> None:
|
|
43
|
+
if not main_line:
|
|
44
|
+
return
|
|
45
|
+
# eg: d4 d5 c4 c6 Nc3 Nf6 Nf3 e6 e3 Nbd7 Bd3 dc4
|
|
46
|
+
print(' '.join(x.decode().strip() for x in main_line if x is not None))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def main() -> None:
|
|
50
|
+
with open('multi_game.pgn', 'rb') as file:
|
|
51
|
+
tree = PARSER.parse(file.read())
|
|
52
|
+
|
|
53
|
+
query_cursor = QueryCursor(QUERY)
|
|
54
|
+
matches = query_cursor.matches(tree.root_node)
|
|
55
|
+
|
|
56
|
+
main_line: list[bytes | None] = []
|
|
57
|
+
for item in matches:
|
|
58
|
+
if item[1].get('game'):
|
|
59
|
+
emit_output(main_line)
|
|
60
|
+
main_line = []
|
|
61
|
+
continue
|
|
62
|
+
if nodes := item[1].get('san_move'):
|
|
63
|
+
main_line.append(nodes[0].text)
|
|
64
|
+
continue
|
|
65
|
+
|
|
66
|
+
emit_output(main_line)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
if __name__ == '__main__':
|
|
70
|
+
main()
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## References
|
|
74
|
+
|
|
75
|
+
* [PGN specification](http://www.saremba.de/chessgml/standards/pgn/pgn-complete.htm)
|
|
76
|
+
* [Commonly-used extensions](https://www.enpassant.dk/chess/palview/enhancedpgn.htm)
|
|
77
|
+
* [Commonly-used annotation glyphs](https://en.wikipedia.org/wiki/Numeric_Annotation_Glyphs)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
def language() -> int: ...
|
|
@@ -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
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tree-sitter-pgn
|
|
3
|
+
Version: 1.3.0
|
|
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.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
Provides-Extra: core
|
|
15
|
+
Requires-Dist: tree-sitter~=0.25.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
|
+
from tree_sitter import Language, Parser, Query, QueryCursor
|
|
37
|
+
import tree_sitter_pgn as ts_pgn
|
|
38
|
+
|
|
39
|
+
PGN_LANGUAGE = Language(ts_pgn.language())
|
|
40
|
+
|
|
41
|
+
PARSER = Parser(PGN_LANGUAGE)
|
|
42
|
+
|
|
43
|
+
# Query for game boundaries and main-line moves.
|
|
44
|
+
# Ignore all headers, comments, variations, and result codes.
|
|
45
|
+
QUERY = Query(
|
|
46
|
+
PGN_LANGUAGE,
|
|
47
|
+
"""
|
|
48
|
+
(series_of_games
|
|
49
|
+
game: (game) @game)
|
|
50
|
+
|
|
51
|
+
(game
|
|
52
|
+
(movetext
|
|
53
|
+
san_move: (san_move) @san_move))
|
|
54
|
+
""",
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def emit_output(main_line: list[bytes | None]) -> None:
|
|
59
|
+
if not main_line:
|
|
60
|
+
return
|
|
61
|
+
# eg: d4 d5 c4 c6 Nc3 Nf6 Nf3 e6 e3 Nbd7 Bd3 dc4
|
|
62
|
+
print(' '.join(x.decode().strip() for x in main_line if x is not None))
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def main() -> None:
|
|
66
|
+
with open('multi_game.pgn', 'rb') as file:
|
|
67
|
+
tree = PARSER.parse(file.read())
|
|
68
|
+
|
|
69
|
+
query_cursor = QueryCursor(QUERY)
|
|
70
|
+
matches = query_cursor.matches(tree.root_node)
|
|
71
|
+
|
|
72
|
+
main_line: list[bytes | None] = []
|
|
73
|
+
for item in matches:
|
|
74
|
+
if item[1].get('game'):
|
|
75
|
+
emit_output(main_line)
|
|
76
|
+
main_line = []
|
|
77
|
+
continue
|
|
78
|
+
if nodes := item[1].get('san_move'):
|
|
79
|
+
main_line.append(nodes[0].text)
|
|
80
|
+
continue
|
|
81
|
+
|
|
82
|
+
emit_output(main_line)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
if __name__ == '__main__':
|
|
86
|
+
main()
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## References
|
|
90
|
+
|
|
91
|
+
* [PGN specification](http://www.saremba.de/chessgml/standards/pgn/pgn-complete.htm)
|
|
92
|
+
* [Commonly-used extensions](https://www.enpassant.dk/chess/palview/enhancedpgn.htm)
|
|
93
|
+
* [Commonly-used annotation glyphs](https://en.wikipedia.org/wiki/Numeric_Annotation_Glyphs)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
setup.py
|
|
4
|
+
tree-sitter.json
|
|
5
|
+
bindings/python/tree_sitter_pgn/__init__.py
|
|
6
|
+
bindings/python/tree_sitter_pgn/__init__.pyi
|
|
7
|
+
bindings/python/tree_sitter_pgn/binding.c
|
|
8
|
+
bindings/python/tree_sitter_pgn/py.typed
|
|
9
|
+
bindings/python/tree_sitter_pgn.egg-info/PKG-INFO
|
|
10
|
+
bindings/python/tree_sitter_pgn.egg-info/SOURCES.txt
|
|
11
|
+
bindings/python/tree_sitter_pgn.egg-info/dependency_links.txt
|
|
12
|
+
bindings/python/tree_sitter_pgn.egg-info/not-zip-safe
|
|
13
|
+
bindings/python/tree_sitter_pgn.egg-info/requires.txt
|
|
14
|
+
bindings/python/tree_sitter_pgn.egg-info/top_level.txt
|
|
15
|
+
src/parser.c
|
|
16
|
+
src/scanner.c
|
|
17
|
+
src/tree_sitter/alloc.h
|
|
18
|
+
src/tree_sitter/array.h
|
|
19
|
+
src/tree_sitter/parser.h
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=42", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tree-sitter-pgn"
|
|
7
|
+
description = "PGN grammar for tree-sitter"
|
|
8
|
+
version = "1.3.0"
|
|
9
|
+
keywords = ["incremental", "parsing", "tree-sitter", "PGN", "chess"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Intended Audience :: Developers",
|
|
12
|
+
"Topic :: Software Development :: Compilers",
|
|
13
|
+
"Topic :: Text Processing :: Linguistic",
|
|
14
|
+
"Typing :: Typed"
|
|
15
|
+
]
|
|
16
|
+
requires-python = ">=3.10"
|
|
17
|
+
license.text = "BSD-2-Clause"
|
|
18
|
+
readme = "README.md"
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
Homepage = "https://github.com/rolandwalker/tree-sitter-pgn"
|
|
22
|
+
|
|
23
|
+
[project.optional-dependencies]
|
|
24
|
+
core = ["tree-sitter~=0.25.0"]
|
|
25
|
+
|
|
26
|
+
[tool.cibuildwheel]
|
|
27
|
+
build = [
|
|
28
|
+
"cp310-*",
|
|
29
|
+
"cp311-*",
|
|
30
|
+
"cp312-*",
|
|
31
|
+
"cp313-*",
|
|
32
|
+
"cp314-*",
|
|
33
|
+
]
|
|
34
|
+
skip = [
|
|
35
|
+
"cp38-*",
|
|
36
|
+
"cp39-*",
|
|
37
|
+
"cp314t-*",
|
|
38
|
+
"*-android*",
|
|
39
|
+
"*-ios*",
|
|
40
|
+
"*_ppc64le",
|
|
41
|
+
"*_s390x",
|
|
42
|
+
]
|
|
43
|
+
build-frontend = "build"
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
from os.path import isdir, join
|
|
2
|
+
from platform import system
|
|
3
|
+
|
|
4
|
+
from setuptools import Extension, find_packages, setup
|
|
5
|
+
from setuptools.command.build import build
|
|
6
|
+
from wheel.bdist_wheel import bdist_wheel
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Build(build):
|
|
10
|
+
def run(self):
|
|
11
|
+
if isdir("queries"):
|
|
12
|
+
dest = join(self.build_lib, "tree_sitter_pgn", "queries")
|
|
13
|
+
self.copy_tree("queries", dest)
|
|
14
|
+
super().run()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class BdistWheel(bdist_wheel):
|
|
18
|
+
def get_tag(self):
|
|
19
|
+
python, abi, platform = super().get_tag()
|
|
20
|
+
if python.startswith("cp"):
|
|
21
|
+
python, abi = "cp39", "abi3"
|
|
22
|
+
return python, abi, platform
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
setup(
|
|
26
|
+
packages=find_packages("bindings/python"),
|
|
27
|
+
package_dir={"": "bindings/python"},
|
|
28
|
+
package_data={
|
|
29
|
+
"tree_sitter_pgn": ["*.pyi", "py.typed"],
|
|
30
|
+
"tree_sitter_pgn.queries": ["*.scm"],
|
|
31
|
+
},
|
|
32
|
+
ext_package="tree_sitter_pgn",
|
|
33
|
+
ext_modules=[
|
|
34
|
+
Extension(
|
|
35
|
+
name="_binding",
|
|
36
|
+
sources=[
|
|
37
|
+
"bindings/python/tree_sitter_pgn/binding.c",
|
|
38
|
+
"src/parser.c",
|
|
39
|
+
"src/scanner.c",
|
|
40
|
+
],
|
|
41
|
+
extra_compile_args=[
|
|
42
|
+
"-std=c11",
|
|
43
|
+
] if system() != "Windows" else [
|
|
44
|
+
"/std:c11",
|
|
45
|
+
"/utf-8",
|
|
46
|
+
],
|
|
47
|
+
define_macros=[
|
|
48
|
+
("Py_LIMITED_API", "0x03090000"),
|
|
49
|
+
("PY_SSIZE_T_CLEAN", None)
|
|
50
|
+
],
|
|
51
|
+
include_dirs=["src"],
|
|
52
|
+
py_limited_api=True,
|
|
53
|
+
)
|
|
54
|
+
],
|
|
55
|
+
cmdclass={
|
|
56
|
+
"build": Build,
|
|
57
|
+
"bdist_wheel": BdistWheel
|
|
58
|
+
},
|
|
59
|
+
zip_safe=False
|
|
60
|
+
)
|