tree-sitter-pgn 1.0.6__tar.gz → 1.0.13__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.
Potentially problematic release.
This version of tree-sitter-pgn might be problematic. Click here for more details.
- {tree_sitter_pgn-1.0.6 → tree_sitter_pgn-1.0.13}/PKG-INFO +42 -2
- tree_sitter_pgn-1.0.13/README.md +61 -0
- {tree_sitter_pgn-1.0.6 → tree_sitter_pgn-1.0.13}/bindings/python/tree_sitter_pgn.egg-info/PKG-INFO +42 -2
- {tree_sitter_pgn-1.0.6 → tree_sitter_pgn-1.0.13}/bindings/python/tree_sitter_pgn.egg-info/SOURCES.txt +1 -0
- {tree_sitter_pgn-1.0.6 → tree_sitter_pgn-1.0.13}/pyproject.toml +1 -1
- tree_sitter_pgn-1.0.13/src/scanner.c +38 -0
- tree_sitter_pgn-1.0.6/README.md +0 -21
- {tree_sitter_pgn-1.0.6 → tree_sitter_pgn-1.0.13}/LICENSE +0 -0
- {tree_sitter_pgn-1.0.6 → tree_sitter_pgn-1.0.13}/bindings/python/tree_sitter_pgn/__init__.py +0 -0
- {tree_sitter_pgn-1.0.6 → tree_sitter_pgn-1.0.13}/bindings/python/tree_sitter_pgn/__init__.pyi +0 -0
- {tree_sitter_pgn-1.0.6 → tree_sitter_pgn-1.0.13}/bindings/python/tree_sitter_pgn/binding.c +0 -0
- {tree_sitter_pgn-1.0.6 → tree_sitter_pgn-1.0.13}/bindings/python/tree_sitter_pgn/py.typed +0 -0
- {tree_sitter_pgn-1.0.6 → tree_sitter_pgn-1.0.13}/bindings/python/tree_sitter_pgn.egg-info/dependency_links.txt +0 -0
- {tree_sitter_pgn-1.0.6 → tree_sitter_pgn-1.0.13}/bindings/python/tree_sitter_pgn.egg-info/not-zip-safe +0 -0
- {tree_sitter_pgn-1.0.6 → tree_sitter_pgn-1.0.13}/bindings/python/tree_sitter_pgn.egg-info/requires.txt +0 -0
- {tree_sitter_pgn-1.0.6 → tree_sitter_pgn-1.0.13}/bindings/python/tree_sitter_pgn.egg-info/top_level.txt +0 -0
- {tree_sitter_pgn-1.0.6 → tree_sitter_pgn-1.0.13}/setup.cfg +0 -0
- {tree_sitter_pgn-1.0.6 → tree_sitter_pgn-1.0.13}/setup.py +0 -0
- {tree_sitter_pgn-1.0.6 → tree_sitter_pgn-1.0.13}/src/parser.c +0 -0
- {tree_sitter_pgn-1.0.6 → tree_sitter_pgn-1.0.13}/src/tree_sitter/alloc.h +0 -0
- {tree_sitter_pgn-1.0.6 → tree_sitter_pgn-1.0.13}/src/tree_sitter/array.h +0 -0
- {tree_sitter_pgn-1.0.6 → tree_sitter_pgn-1.0.13}/src/tree_sitter/parser.h +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: tree-sitter-pgn
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.13
|
|
4
4
|
Summary: PGN grammar for tree-sitter
|
|
5
5
|
License: BSD
|
|
6
6
|
Project-URL: Homepage, https://github.com/rolandwalker/tree-sitter-pgn
|
|
@@ -26,12 +26,52 @@ Chess Portable Game Notation (PGN) grammar for [tree-sitter](https://github.com/
|
|
|
26
26
|
|
|
27
27
|
* [Emacs pygn-mode](https://github.com/dwcoates/pygn-mode)
|
|
28
28
|
|
|
29
|
-
## Example
|
|
29
|
+
## Highlighting Example
|
|
30
30
|
|
|
31
31
|
<a href="/doc/images/pgn_syntax_highlight.png">
|
|
32
32
|
<img src="/doc/images/pgn_syntax_highlight.png" width=500/>
|
|
33
33
|
</a>
|
|
34
34
|
|
|
35
|
+
## Python Example
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
import more_itertools
|
|
39
|
+
from tree_sitter import Language, Parser
|
|
40
|
+
import tree_sitter_pgn as ts_pgn
|
|
41
|
+
|
|
42
|
+
PGN_LANGUAGE = Language(ts_pgn.language())
|
|
43
|
+
parser = Parser(PGN_LANGUAGE)
|
|
44
|
+
|
|
45
|
+
query = PGN_LANGUAGE.query(
|
|
46
|
+
'''
|
|
47
|
+
(series_of_games
|
|
48
|
+
game: (game) @game)
|
|
49
|
+
|
|
50
|
+
(movetext
|
|
51
|
+
san_move: (san_move) @san_move)
|
|
52
|
+
''')
|
|
53
|
+
|
|
54
|
+
with open('input_file.pgn', 'rb') as file:
|
|
55
|
+
content = b''.join(file.readlines())
|
|
56
|
+
tree = parser.parse(content)
|
|
57
|
+
|
|
58
|
+
matches = query.captures(tree.root_node)
|
|
59
|
+
|
|
60
|
+
merged_nodes = [
|
|
61
|
+
*matches.get('game', []),
|
|
62
|
+
*matches.get('san_move', []),
|
|
63
|
+
]
|
|
64
|
+
merged_nodes = sorted(merged_nodes, key=lambda elt: elt.start_byte)
|
|
65
|
+
|
|
66
|
+
for game in more_itertools.split_before(merged_nodes, lambda node: node.type == 'game'):
|
|
67
|
+
san = []
|
|
68
|
+
for node in game:
|
|
69
|
+
if node.type == 'san_move' and node.text is not None:
|
|
70
|
+
san.append(node.text.decode().strip())
|
|
71
|
+
continue
|
|
72
|
+
print(' '.join(san))
|
|
73
|
+
```
|
|
74
|
+
|
|
35
75
|
## References
|
|
36
76
|
|
|
37
77
|
* [PGN specification](http://www.saremba.de/chessgml/standards/pgn/pgn-complete.htm)
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
import more_itertools
|
|
21
|
+
from tree_sitter import Language, Parser
|
|
22
|
+
import tree_sitter_pgn as ts_pgn
|
|
23
|
+
|
|
24
|
+
PGN_LANGUAGE = Language(ts_pgn.language())
|
|
25
|
+
parser = Parser(PGN_LANGUAGE)
|
|
26
|
+
|
|
27
|
+
query = PGN_LANGUAGE.query(
|
|
28
|
+
'''
|
|
29
|
+
(series_of_games
|
|
30
|
+
game: (game) @game)
|
|
31
|
+
|
|
32
|
+
(movetext
|
|
33
|
+
san_move: (san_move) @san_move)
|
|
34
|
+
''')
|
|
35
|
+
|
|
36
|
+
with open('input_file.pgn', 'rb') as file:
|
|
37
|
+
content = b''.join(file.readlines())
|
|
38
|
+
tree = parser.parse(content)
|
|
39
|
+
|
|
40
|
+
matches = query.captures(tree.root_node)
|
|
41
|
+
|
|
42
|
+
merged_nodes = [
|
|
43
|
+
*matches.get('game', []),
|
|
44
|
+
*matches.get('san_move', []),
|
|
45
|
+
]
|
|
46
|
+
merged_nodes = sorted(merged_nodes, key=lambda elt: elt.start_byte)
|
|
47
|
+
|
|
48
|
+
for game in more_itertools.split_before(merged_nodes, lambda node: node.type == 'game'):
|
|
49
|
+
san = []
|
|
50
|
+
for node in game:
|
|
51
|
+
if node.type == 'san_move' and node.text is not None:
|
|
52
|
+
san.append(node.text.decode().strip())
|
|
53
|
+
continue
|
|
54
|
+
print(' '.join(san))
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## References
|
|
58
|
+
|
|
59
|
+
* [PGN specification](http://www.saremba.de/chessgml/standards/pgn/pgn-complete.htm)
|
|
60
|
+
* [Commonly-used extensions](https://www.enpassant.dk/chess/palview/enhancedpgn.htm)
|
|
61
|
+
* [Commonly-used annotation glyphs](https://en.wikipedia.org/wiki/Numeric_Annotation_Glyphs)
|
{tree_sitter_pgn-1.0.6 → tree_sitter_pgn-1.0.13}/bindings/python/tree_sitter_pgn.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: tree-sitter-pgn
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.13
|
|
4
4
|
Summary: PGN grammar for tree-sitter
|
|
5
5
|
License: BSD
|
|
6
6
|
Project-URL: Homepage, https://github.com/rolandwalker/tree-sitter-pgn
|
|
@@ -26,12 +26,52 @@ Chess Portable Game Notation (PGN) grammar for [tree-sitter](https://github.com/
|
|
|
26
26
|
|
|
27
27
|
* [Emacs pygn-mode](https://github.com/dwcoates/pygn-mode)
|
|
28
28
|
|
|
29
|
-
## Example
|
|
29
|
+
## Highlighting Example
|
|
30
30
|
|
|
31
31
|
<a href="/doc/images/pgn_syntax_highlight.png">
|
|
32
32
|
<img src="/doc/images/pgn_syntax_highlight.png" width=500/>
|
|
33
33
|
</a>
|
|
34
34
|
|
|
35
|
+
## Python Example
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
import more_itertools
|
|
39
|
+
from tree_sitter import Language, Parser
|
|
40
|
+
import tree_sitter_pgn as ts_pgn
|
|
41
|
+
|
|
42
|
+
PGN_LANGUAGE = Language(ts_pgn.language())
|
|
43
|
+
parser = Parser(PGN_LANGUAGE)
|
|
44
|
+
|
|
45
|
+
query = PGN_LANGUAGE.query(
|
|
46
|
+
'''
|
|
47
|
+
(series_of_games
|
|
48
|
+
game: (game) @game)
|
|
49
|
+
|
|
50
|
+
(movetext
|
|
51
|
+
san_move: (san_move) @san_move)
|
|
52
|
+
''')
|
|
53
|
+
|
|
54
|
+
with open('input_file.pgn', 'rb') as file:
|
|
55
|
+
content = b''.join(file.readlines())
|
|
56
|
+
tree = parser.parse(content)
|
|
57
|
+
|
|
58
|
+
matches = query.captures(tree.root_node)
|
|
59
|
+
|
|
60
|
+
merged_nodes = [
|
|
61
|
+
*matches.get('game', []),
|
|
62
|
+
*matches.get('san_move', []),
|
|
63
|
+
]
|
|
64
|
+
merged_nodes = sorted(merged_nodes, key=lambda elt: elt.start_byte)
|
|
65
|
+
|
|
66
|
+
for game in more_itertools.split_before(merged_nodes, lambda node: node.type == 'game'):
|
|
67
|
+
san = []
|
|
68
|
+
for node in game:
|
|
69
|
+
if node.type == 'san_move' and node.text is not None:
|
|
70
|
+
san.append(node.text.decode().strip())
|
|
71
|
+
continue
|
|
72
|
+
print(' '.join(san))
|
|
73
|
+
```
|
|
74
|
+
|
|
35
75
|
## References
|
|
36
76
|
|
|
37
77
|
* [PGN specification](http://www.saremba.de/chessgml/standards/pgn/pgn-complete.htm)
|
|
@@ -13,6 +13,7 @@ bindings/python/tree_sitter_pgn.egg-info/not-zip-safe
|
|
|
13
13
|
bindings/python/tree_sitter_pgn.egg-info/requires.txt
|
|
14
14
|
bindings/python/tree_sitter_pgn.egg-info/top_level.txt
|
|
15
15
|
src/parser.c
|
|
16
|
+
src/scanner.c
|
|
16
17
|
src/tree_sitter/alloc.h
|
|
17
18
|
src/tree_sitter/array.h
|
|
18
19
|
src/tree_sitter/parser.h
|
|
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "tree-sitter-pgn"
|
|
7
7
|
description = "PGN grammar for tree-sitter"
|
|
8
|
-
version = "1.0.
|
|
8
|
+
version = "1.0.13"
|
|
9
9
|
keywords = ["incremental", "parsing", "tree-sitter", "PGN", "chess"]
|
|
10
10
|
classifiers = [
|
|
11
11
|
"Intended Audience :: Developers",
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#include "tree_sitter/parser.h"
|
|
2
|
+
|
|
3
|
+
enum TokenType {
|
|
4
|
+
FULL_LINE_COMMENT_DELIMITER_BOL_ASSERTION,
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
void *tree_sitter_pgn_external_scanner_create(void) {
|
|
8
|
+
return NULL;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
void tree_sitter_pgn_external_scanner_destroy(void *payload) {
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
unsigned tree_sitter_pgn_external_scanner_serialize(void *payload, char *buffer) {
|
|
15
|
+
return 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
void tree_sitter_pgn_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) {
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
bool tree_sitter_pgn_external_scanner_scan(
|
|
22
|
+
void *payload,
|
|
23
|
+
TSLexer *lexer,
|
|
24
|
+
const bool *valid_symbols
|
|
25
|
+
) {
|
|
26
|
+
if (valid_symbols[FULL_LINE_COMMENT_DELIMITER_BOL_ASSERTION]) {
|
|
27
|
+
// it's not really clear why we have to advance over newlines, but we do
|
|
28
|
+
// eof not really needed in this form
|
|
29
|
+
while (!lexer->eof(lexer) && (lexer->lookahead == '\n' || lexer->lookahead == '\r')) {
|
|
30
|
+
lexer->advance(lexer, true);
|
|
31
|
+
}
|
|
32
|
+
if (lexer->lookahead == '%' && lexer->get_column(lexer) == 0) {
|
|
33
|
+
lexer->result_symbol = FULL_LINE_COMMENT_DELIMITER_BOL_ASSERTION;
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
tree_sitter_pgn-1.0.6/README.md
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
## 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
|
-
## References
|
|
18
|
-
|
|
19
|
-
* [PGN specification](http://www.saremba.de/chessgml/standards/pgn/pgn-complete.htm)
|
|
20
|
-
* [Commonly-used extensions](https://www.enpassant.dk/chess/palview/enhancedpgn.htm)
|
|
21
|
-
* [Commonly-used annotation glyphs](https://en.wikipedia.org/wiki/Numeric_Annotation_Glyphs)
|
|
File without changes
|
{tree_sitter_pgn-1.0.6 → tree_sitter_pgn-1.0.13}/bindings/python/tree_sitter_pgn/__init__.py
RENAMED
|
File without changes
|
{tree_sitter_pgn-1.0.6 → tree_sitter_pgn-1.0.13}/bindings/python/tree_sitter_pgn/__init__.pyi
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|