@konomanoasa/tree-sitter-posix-awk 0.16.0 → 0.18.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 CHANGED
@@ -1,10 +1,23 @@
1
1
  [package]
2
- name = "tree-sitter-posix-awk"
3
- version = "0.16.0"
2
+ name = "konomanoasa-tree-sitter-posix-awk"
3
+ version = "0.18.0"
4
4
  edition = "2024"
5
+ description = "Tree-sitter grammar for POSIX awk."
6
+ readme = "README.md"
7
+ repository = "https://github.com/konomanoasa/tree-sitter-posix-awk"
8
+ license = "MIT"
5
9
  build = "bindings/rust/build.rs"
6
10
  links = "tree-sitter-posix-awk"
7
- publish = false
11
+ include = [
12
+ "/LICENSE",
13
+ "/README.md",
14
+ "/bindings/rust/*.rs",
15
+ "/queries/*.scm",
16
+ "/src/*.c",
17
+ "/src/node-types.json",
18
+ "/src/tree_sitter/*.h",
19
+ "/test/bindings.test.rs",
20
+ ]
8
21
 
9
22
  [lib]
10
23
  path = "bindings/rust/lib.rs"
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # tree-sitter-posix-awk
2
2
 
3
3
  [![CI](https://github.com/konomanoasa/tree-sitter-posix-awk/actions/workflows/ci.yaml/badge.svg)](https://github.com/konomanoasa/tree-sitter-posix-awk/actions/workflows/ci.yaml)
4
+ [![crates.io](https://img.shields.io/crates/v/konomanoasa-tree-sitter-posix-awk)](https://crates.io/crates/konomanoasa-tree-sitter-posix-awk)
4
5
  [![npm](https://img.shields.io/npm/v/@konomanoasa/tree-sitter-posix-awk)](https://www.npmjs.com/package/@konomanoasa/tree-sitter-posix-awk)
5
6
 
6
7
  [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) grammar for
@@ -12,15 +13,9 @@ POSIX.1-2024 AWK.
12
13
  npm install @konomanoasa/tree-sitter-posix-awk
13
14
  ```
14
15
 
15
- ## Grammar
16
-
17
- | Grammar | Description | Rust constant |
18
- | --- | --- | --- |
19
- | `posix_awk` | POSIX.1-2024 AWK | `LANGUAGE` |
20
-
21
16
  ## Development
22
17
 
23
- Development requires Node.js 24.2.0 or later.
18
+ Development uses Node.js 24 or later.
24
19
 
25
20
  ```sh
26
21
  npm install
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konomanoasa/tree-sitter-posix-awk",
3
- "version": "0.16.0",
3
+ "version": "0.18.0",
4
4
  "type": "module",
5
5
  "description": "Tree-sitter grammar for POSIX awk.",
6
6
  "license": "MIT",
package/src/parser.c CHANGED
@@ -170539,7 +170539,7 @@ TS_PUBLIC const TSLanguage *tree_sitter_posix_awk(void) {
170539
170539
  .max_reserved_word_set_size = 0,
170540
170540
  .metadata = {
170541
170541
  .major_version = 0,
170542
- .minor_version = 16,
170542
+ .minor_version = 18,
170543
170543
  .patch_version = 0,
170544
170544
  },
170545
170545
  };
@@ -1,9 +1,9 @@
1
1
  use std::ops::Range;
2
2
 
3
+ use konomanoasa_tree_sitter_posix_awk as grammar;
3
4
  use tree_sitter::{
4
5
  InputEdit, Node, Parser, Point, Query, QueryCursor, StreamingIterator, Tree,
5
6
  };
6
- use tree_sitter_posix_awk as grammar;
7
7
 
8
8
  struct EreCase {
9
9
  name: &'static str,
@@ -338,38 +338,58 @@ fn collect_leaves<'tree>(node: Node<'tree>, leaves: &mut Vec<Node<'tree>>) {
338
338
  }
339
339
 
340
340
  fn assert_same_cst(actual: Node<'_>, expected: Node<'_>, context: &str) {
341
- assert_eq!(actual.kind(), expected.kind(), "{context}");
342
- assert_eq!(actual.range(), expected.range(), "{context}");
343
- assert_eq!(actual.is_named(), expected.is_named(), "{context}");
344
- assert_eq!(actual.is_extra(), expected.is_extra(), "{context}");
345
- assert_eq!(actual.is_error(), expected.is_error(), "{context}");
346
- assert_eq!(actual.is_missing(), expected.is_missing(), "{context}");
347
- assert_eq!(actual.has_error(), expected.has_error(), "{context}");
348
- assert_eq!(actual.child_count(), expected.child_count(), "{context}");
349
- for index in 0..actual.child_count() {
350
- assert_eq!(
351
- actual.field_name_for_child(index),
352
- expected.field_name_for_child(index),
353
- "{context}",
354
- );
355
- assert_same_cst(
356
- actual.child(index).unwrap(),
357
- expected.child(index).unwrap(),
358
- context,
359
- );
341
+ let mut pending = vec![(actual, expected)];
342
+ while let Some((actual, expected)) = pending.pop() {
343
+ assert_eq!(actual.kind(), expected.kind(), "{context}");
344
+ assert_eq!(actual.range(), expected.range(), "{context}");
345
+ assert_eq!(actual.is_named(), expected.is_named(), "{context}");
346
+ assert_eq!(actual.is_extra(), expected.is_extra(), "{context}");
347
+ assert_eq!(actual.is_error(), expected.is_error(), "{context}");
348
+ assert_eq!(actual.is_missing(), expected.is_missing(), "{context}");
349
+ assert_eq!(actual.has_error(), expected.has_error(), "{context}");
350
+ assert_eq!(actual.child_count(), expected.child_count(), "{context}");
351
+ for index in 0..actual.child_count() {
352
+ assert_eq!(
353
+ actual.field_name_for_child(index),
354
+ expected.field_name_for_child(index),
355
+ "{context}",
356
+ );
357
+ pending
358
+ .push((actual.child(index).unwrap(), expected.child(index).unwrap()));
359
+ }
360
+ }
361
+ }
362
+
363
+ fn assert_fresh_cst(
364
+ reused: &mut Parser,
365
+ source: &[u8],
366
+ expected: &Tree,
367
+ context: &str,
368
+ ) {
369
+ for _ in 0..2 {
370
+ let actual = reused.parse(source, None).unwrap();
371
+ assert_same_cst(actual.root_node(), expected.root_node(), context);
360
372
  }
373
+ reused.reset();
374
+ let actual = reused.parse(source, None).unwrap();
375
+ assert_same_cst(actual.root_node(), expected.root_node(), context);
376
+ let independent = parser().parse(source, None).unwrap();
377
+ assert_same_cst(independent.root_node(), expected.root_node(), context);
361
378
  }
362
379
 
363
380
  #[test]
364
381
  fn parses_valid_source() {
365
382
  let source = "BEGIN { print 1 }\n";
383
+ let language = grammar::LANGUAGE.into();
366
384
  let mut parser = Parser::new();
367
- parser.set_language(&grammar::LANGUAGE.into()).unwrap();
385
+ parser.set_language(&language).unwrap();
368
386
  let tree = parser.parse(source, None).unwrap();
369
387
  let root = tree.root_node();
370
388
  assert_eq!(root.kind(), "program");
371
389
  assert_eq!(root.byte_range(), 0..source.len());
372
390
  assert!(!root.has_error());
391
+ assert!(grammar::NODE_TYPES.contains("\"program\""));
392
+ Query::new(&language, grammar::HIGHLIGHTS_QUERY).unwrap();
373
393
  }
374
394
 
375
395
  #[test]
@@ -786,6 +806,15 @@ fn fresh_parses_ignore_previous_recovery_and_edit_history() {
786
806
  ("unfinished equivalence class", "/[[=a", true),
787
807
  ("unfinished character class", "/[[:alpha", true),
788
808
  ("unfinished interval", "/a{1,", true),
809
+ ("unfinished group alternation", "/(a|", true),
810
+ ("unfinished negative bracket", "/[^]", true),
811
+ ("unfinished compound closing", "/[[.a.", true),
812
+ ("unfinished class closing", "/[[:alpha:", true),
813
+ ("raw newline in ERE", "/[a\nb]/", true),
814
+ ("raw newline in string", "\"a\nb\"", true),
815
+ ("carriage return before newline", "{ x\r\n}", true),
816
+ ("BOM before unfinished string", "\u{feff}\"a\\", true),
817
+ ("BOM inside expression", "{ x\u{feff}+ }", true),
789
818
  ("stray backslash", "{}\\", true),
790
819
  ("continued missing operand", "{ x +\\\n", true),
791
820
  ("invalid continuation", "{ x\\ \n}", true),
@@ -823,15 +852,101 @@ fn fresh_parses_ignore_previous_recovery_and_edit_history() {
823
852
  let mut previous = reused.parse(&text, None).unwrap();
824
853
  edit(&mut previous, &mut text, 0, 0, "[\\\n");
825
854
  let _edited = reused.parse(&text, Some(&previous)).unwrap();
826
- for _ in 0..3 {
827
- let actual = reused.parse(source, None).unwrap();
828
- assert_same_cst(actual.root_node(), expected.root_node(), &context);
829
- let independent = parser().parse(source, None).unwrap();
830
- assert_same_cst(
831
- independent.root_node(),
832
- expected.root_node(),
833
- &context,
834
- );
855
+ assert_fresh_cst(&mut reused, source.as_bytes(), &expected, &context);
856
+ }
857
+ }
858
+ }
859
+
860
+ #[test]
861
+ fn fresh_parses_of_truncated_and_mutated_tokens_are_repeatable() {
862
+ let cases = [
863
+ (
864
+ "conditionals, calls and updates",
865
+ "function f(a,b) { if (a) return a[b]++; else return $-f(b) }\n",
866
+ ),
867
+ (
868
+ "loop and output redirection",
869
+ "BEGIN { for (i in a) printf \"%s\", a[i] >> file; do i--; while(i) }\n",
870
+ ),
871
+ (
872
+ "input target and pipe ambiguity",
873
+ "{ x = getline a + b++; command | getline a[i]; getline $-x < file }\n",
874
+ ),
875
+ (
876
+ "division, assignment and ERE boundaries",
877
+ "{ x /= 2; x / 2 ~ /^(ab|c){1,3}?$/; print /[]a-z-]/ }\n",
878
+ ),
879
+ (
880
+ "collating symbol, equivalence class and character class",
881
+ "/[[.é.][=犬=][:alpha:]\\141\\/]/\n",
882
+ ),
883
+ (
884
+ "escaped Unicode string and octal escape",
885
+ "{ print \"é犬🙂\\n\\141\\\"\" }\n",
886
+ ),
887
+ (
888
+ "BOM, continued names and comment backslash",
889
+ "\u{feff}BEGIN\\\n{ fo\\\no; x\\\n++ } # \\\n",
890
+ ),
891
+ (
892
+ "number suffix and exponent boundaries",
893
+ "{ a = 1.2e-3F + .5L; a += 2E+3; a *= 7; a %= 2; a ^= 3 }\n",
894
+ ),
895
+ ];
896
+ let mut reused = parser();
897
+ let mut previous = b"/[[:".to_vec();
898
+ let mut malformed = 0;
899
+ for (name, source) in cases {
900
+ parse(source, name);
901
+ for end in 0..=source.len() {
902
+ let mut mutations = vec![source.as_bytes()[..end].to_vec()];
903
+ if end < source.len() {
904
+ let mut deleted = source.as_bytes().to_vec();
905
+ deleted.remove(end);
906
+ mutations.push(deleted);
907
+ for inserted in [b"\0".as_slice(), b"\\\n", b"\r\n", b"[", b"\""] {
908
+ let mut mutated = source.as_bytes().to_vec();
909
+ mutated.splice(end..end, inserted.iter().copied());
910
+ mutations.push(mutated);
911
+ }
912
+ }
913
+ for (mutation, text) in mutations.into_iter().enumerate() {
914
+ let context =
915
+ format!("{name}, byte {end}, mutation {mutation}: {text:?}");
916
+ let expected = parser().parse(&text, None).unwrap();
917
+ malformed += usize::from(expected.root_node().has_error());
918
+ let _previous = reused.parse(&previous, None).unwrap();
919
+ assert_fresh_cst(&mut reused, &text, &expected, &context);
920
+ previous = text;
921
+ }
922
+ }
923
+ }
924
+ assert!(
925
+ malformed > 1_000,
926
+ "must exercise malformed and incomplete input"
927
+ );
928
+ }
929
+
930
+ #[test]
931
+ fn fresh_parses_remain_repeatable_after_long_unterminated_constructs() {
932
+ let mut reused = parser();
933
+ for length in [255, 256, 1_023, 1_024, 1_025] {
934
+ for (name, opening, content, closing) in [
935
+ ("string", "{ print \"", "é", "\" }\n"),
936
+ ("ERE", "/", "a", "/\n"),
937
+ ("collating symbol", "/[[.", "a", ".]]/\n"),
938
+ ("equivalence class", "/[[=", "a", "=]]/\n"),
939
+ ("word", "{ ", "a", " }\n"),
940
+ ("comment", "{ #", "a", "\n}\n"),
941
+ ("nested unary fields", "{ ", "$+", "a }\n"),
942
+ ] {
943
+ let unfinished = format!("{opening}{}", content.repeat(length));
944
+ let complete = format!("{unfinished}{closing}");
945
+ for source in [unfinished, complete] {
946
+ let context =
947
+ format!("{name}, length {length}, {} bytes", source.len());
948
+ let expected = parser().parse(&source, None).unwrap();
949
+ assert_fresh_cst(&mut reused, source.as_bytes(), &expected, &context);
835
950
  }
836
951
  }
837
952
  }
@@ -940,6 +1055,7 @@ fn fixed_seed_getline_edit_histories_match_fresh_parses_after_recovery() {
940
1055
  "", "[", "]", "(", ")", "++", "--", "x", " ", ";", "\n", "+", "?", "~",
941
1056
  "<", "\\\n",
942
1057
  ];
1058
+ let mut independent = parser();
943
1059
  for history in 0..5_000 {
944
1060
  let source = seeds[history % seeds.len()];
945
1061
  let mut parser = parser();
@@ -966,11 +1082,13 @@ fn fixed_seed_getline_edit_histories_match_fresh_parses_after_recovery() {
966
1082
  edit(&mut tree, &mut text, start, deleted, &inserted);
967
1083
  tree = parser.parse(&text, Some(&tree)).unwrap();
968
1084
  let fresh = parser.parse(&text, None).unwrap();
1085
+ let expected = independent.parse(&text, None).unwrap();
1086
+ let context = format!(
1087
+ "history {history}, step {step}, source {source:?}, edits {steps:?}, final {:?}",
1088
+ String::from_utf8_lossy(&text)
1089
+ );
1090
+ assert_same_cst(fresh.root_node(), expected.root_node(), &context);
969
1091
  if !fresh.root_node().has_error() {
970
- let context = format!(
971
- "history {history}, step {step}, source {source:?}, edits {steps:?}, final {:?}",
972
- String::from_utf8_lossy(&text)
973
- );
974
1092
  assert_same_cst(tree.root_node(), fresh.root_node(), &context);
975
1093
  }
976
1094
  }
package/tree-sitter.json CHANGED
@@ -12,7 +12,7 @@
12
12
  }
13
13
  ],
14
14
  "metadata": {
15
- "version": "0.16.0",
15
+ "version": "0.18.0",
16
16
  "license": "MIT",
17
17
  "description": "Tree-sitter grammar for POSIX awk.",
18
18
  "links": {