@konomanoasa/tree-sitter-gitattributes 0.4.2 → 0.6.0
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.
- package/Cargo.toml +3 -3
- package/README.md +0 -4
- package/bindings/python/__init__.py +9 -0
- package/bindings/python/binding.c +34 -0
- package/bindings/python/binding.pyi +3 -0
- package/bindings/python/py.typed +0 -0
- package/grammar.js +3 -2
- package/package.json +10 -8
- package/pyproject.toml +60 -0
- package/setup.py +28 -0
- package/src/grammar.json +25 -4
- package/src/parser.c +2078 -1541
- package/src/scanner.c +27 -4
- package/test/bindings.test.rs +23 -2
- package/tree-sitter.json +2 -2
package/src/scanner.c
CHANGED
|
@@ -9,6 +9,7 @@ enum Token {
|
|
|
9
9
|
RULE_START,
|
|
10
10
|
MACRO_START,
|
|
11
11
|
END_OF_FILE,
|
|
12
|
+
LINE_ENDING,
|
|
12
13
|
LAYOUT,
|
|
13
14
|
SEPARATOR,
|
|
14
15
|
ATTRIBUTE_START,
|
|
@@ -648,6 +649,21 @@ static bool prepare_attribute(Scanner *s, TSLexer *lexer, const bool *valid) {
|
|
|
648
649
|
return emit(lexer, valid, ATTRIBUTE_START);
|
|
649
650
|
}
|
|
650
651
|
|
|
652
|
+
static bool end_line(Scanner *s, TSLexer *lexer, const bool *valid) {
|
|
653
|
+
enum Token token = END_OF_FILE;
|
|
654
|
+
if (!lexer->eof(lexer)) {
|
|
655
|
+
if (!valid[LINE_ENDING]) return false;
|
|
656
|
+
if (lexer->lookahead == '\r') advance(s, lexer);
|
|
657
|
+
if (lexer->lookahead != '\n') return false;
|
|
658
|
+
advance(s, lexer);
|
|
659
|
+
token = LINE_ENDING;
|
|
660
|
+
}
|
|
661
|
+
lexer->mark_end(lexer);
|
|
662
|
+
if (!emit(lexer, valid, token)) return false;
|
|
663
|
+
*s = (Scanner){0};
|
|
664
|
+
return true;
|
|
665
|
+
}
|
|
666
|
+
|
|
651
667
|
static bool scan(Scanner *s, TSLexer *lexer, const bool *valid) {
|
|
652
668
|
if (valid[ERROR_SENTINEL]) return false;
|
|
653
669
|
if (valid[LINE_START]) return start_line(s, lexer, valid);
|
|
@@ -685,7 +701,10 @@ static bool scan(Scanner *s, TSLexer *lexer, const bool *valid) {
|
|
|
685
701
|
return emit(lexer, valid, VALUE_START);
|
|
686
702
|
if (valid[VALUE_END] && s->position == s->token_end)
|
|
687
703
|
return emit(lexer, valid, VALUE_END);
|
|
688
|
-
if (
|
|
704
|
+
if (
|
|
705
|
+
(valid[MISSING_ATTRIBUTE_NAME] || valid[INCOMPLETE_ATTRIBUTE_NAME]) &&
|
|
706
|
+
s->position == s->name_end
|
|
707
|
+
)
|
|
689
708
|
return emit(
|
|
690
709
|
lexer,
|
|
691
710
|
valid,
|
|
@@ -707,7 +726,9 @@ static bool scan(Scanner *s, TSLexer *lexer, const bool *valid) {
|
|
|
707
726
|
if (valid[ASSIGNMENT_OPERATOR] && lexer->lookahead == '=')
|
|
708
727
|
return take(s, lexer, valid, ASSIGNMENT_OPERATOR);
|
|
709
728
|
if (
|
|
710
|
-
(valid[QUOTE_CLOSE] ||
|
|
729
|
+
(valid[QUOTE_CLOSE] ||
|
|
730
|
+
valid[MISSING_QUOTE_CLOSE] ||
|
|
731
|
+
valid[INCOMPLETE_QUOTE_CLOSE]) &&
|
|
711
732
|
s->quoted &&
|
|
712
733
|
s->position == s->content_end
|
|
713
734
|
) {
|
|
@@ -720,8 +741,7 @@ static bool scan(Scanner *s, TSLexer *lexer, const bool *valid) {
|
|
|
720
741
|
}
|
|
721
742
|
if (valid[PATTERN_END] && s->position >= s->content_end)
|
|
722
743
|
return emit(lexer, valid, PATTERN_END);
|
|
723
|
-
if (s->position >= s->line_end)
|
|
724
|
-
return lexer->eof(lexer) && emit(lexer, valid, END_OF_FILE);
|
|
744
|
+
if (s->position >= s->line_end) return end_line(s, lexer, valid);
|
|
725
745
|
if (s->kind == COMMENT_START) {
|
|
726
746
|
if (s->position == s->leading) return take(s, lexer, valid, COMMENT_MARKER);
|
|
727
747
|
return text_run(s, lexer, valid, COMMENT_TEXT, s->line_end);
|
|
@@ -770,6 +790,7 @@ unsigned tree_sitter_gitattributes_external_scanner_serialize(
|
|
|
770
790
|
void *payload,
|
|
771
791
|
char *buffer
|
|
772
792
|
) {
|
|
793
|
+
if (payload == NULL) return 0;
|
|
773
794
|
memcpy(buffer, payload, sizeof(Scanner));
|
|
774
795
|
return sizeof(Scanner);
|
|
775
796
|
}
|
|
@@ -779,6 +800,7 @@ void tree_sitter_gitattributes_external_scanner_deserialize(
|
|
|
779
800
|
const char *buffer,
|
|
780
801
|
unsigned length
|
|
781
802
|
) {
|
|
803
|
+
if (payload == NULL) return;
|
|
782
804
|
memset(payload, 0, sizeof(Scanner));
|
|
783
805
|
if (length == sizeof(Scanner)) memcpy(payload, buffer, length);
|
|
784
806
|
}
|
|
@@ -788,6 +810,7 @@ bool tree_sitter_gitattributes_external_scanner_scan(
|
|
|
788
810
|
TSLexer *lexer,
|
|
789
811
|
const bool *valid
|
|
790
812
|
) {
|
|
813
|
+
if (payload == NULL) return false;
|
|
791
814
|
Scanner next = *(Scanner *)payload;
|
|
792
815
|
if (!scan(&next, lexer, valid)) return false;
|
|
793
816
|
*(Scanner *)payload = next;
|
package/test/bindings.test.rs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
use konomanoasa_tree_sitter_gitattributes as grammar;
|
|
2
|
-
use tree_sitter::{Parser, Query};
|
|
2
|
+
use tree_sitter::{Parser, Query, QueryCursor, StreamingIterator};
|
|
3
3
|
|
|
4
4
|
#[test]
|
|
5
5
|
fn parses_valid_source() {
|
|
@@ -13,5 +13,26 @@ fn parses_valid_source() {
|
|
|
13
13
|
assert_eq!(root.byte_range(), 0..source.len());
|
|
14
14
|
assert!(!root.has_error());
|
|
15
15
|
assert!(grammar::NODE_TYPES.contains("\"document\""));
|
|
16
|
-
Query::new(&language, grammar::HIGHLIGHTS_QUERY).unwrap();
|
|
16
|
+
let query = Query::new(&language, grammar::HIGHLIGHTS_QUERY).unwrap();
|
|
17
|
+
let mut cursor = QueryCursor::new();
|
|
18
|
+
let mut captures = cursor.captures(&query, root, source.as_bytes());
|
|
19
|
+
let mut actual = Vec::new();
|
|
20
|
+
while let Some((matched, index)) = captures.next() {
|
|
21
|
+
let capture = matched.captures()[*index];
|
|
22
|
+
actual.push((
|
|
23
|
+
query.capture_names()[capture.index as usize],
|
|
24
|
+
capture.node.utf8_text(source.as_bytes()).unwrap(),
|
|
25
|
+
));
|
|
26
|
+
}
|
|
27
|
+
assert_eq!(
|
|
28
|
+
actual,
|
|
29
|
+
[
|
|
30
|
+
("character.special", "*"),
|
|
31
|
+
("string.special.path", ".txt"),
|
|
32
|
+
("attribute", "text"),
|
|
33
|
+
("attribute", "eol"),
|
|
34
|
+
("operator", "="),
|
|
35
|
+
("string", "lf")
|
|
36
|
+
]
|
|
37
|
+
);
|
|
17
38
|
}
|
package/tree-sitter.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
}
|
|
13
13
|
],
|
|
14
14
|
"metadata": {
|
|
15
|
-
"version": "0.
|
|
15
|
+
"version": "0.6.0",
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"description": "Tree-sitter grammar for gitattributes.",
|
|
18
18
|
"links": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"c": false,
|
|
24
24
|
"go": false,
|
|
25
25
|
"node": false,
|
|
26
|
-
"python":
|
|
26
|
+
"python": true,
|
|
27
27
|
"rust": true,
|
|
28
28
|
"swift": false
|
|
29
29
|
}
|