@konomanoasa/tree-sitter-posix-awk 0.7.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/CMakeLists.txt ADDED
@@ -0,0 +1,90 @@
1
+ cmake_minimum_required(VERSION 3.13)
2
+
3
+ project(
4
+ tree-sitter-posix-awk
5
+ VERSION 0.7.0
6
+ DESCRIPTION "Tree-sitter grammar for POSIX awk."
7
+ HOMEPAGE_URL "https://github.com/konomanoasa/tree-sitter-posix-awk"
8
+ LANGUAGES C
9
+ )
10
+
11
+ option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
12
+ option(TREE_SITTER_REUSE_ALLOCATOR "Reuse the Tree-sitter allocator" OFF)
13
+
14
+ file(
15
+ STRINGS src/parser.c
16
+ TREE_SITTER_ABI_DEFINITION
17
+ REGEX "^#define LANGUAGE_VERSION [0-9]+$"
18
+ )
19
+ if(NOT TREE_SITTER_ABI_DEFINITION MATCHES "^#define LANGUAGE_VERSION [0-9]+$")
20
+ message(FATAL_ERROR "The parser must define one LANGUAGE_VERSION")
21
+ endif()
22
+ string(
23
+ REGEX REPLACE "^#define LANGUAGE_VERSION " ""
24
+ TREE_SITTER_ABI_VERSION
25
+ "${TREE_SITTER_ABI_DEFINITION}"
26
+ )
27
+
28
+ include(GNUInstallDirs)
29
+ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
30
+ include(CTest)
31
+ endif()
32
+
33
+ add_library(tree-sitter-posix-awk src/parser.c src/scanner.c)
34
+ target_include_directories(
35
+ tree-sitter-posix-awk
36
+ INTERFACE
37
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/bindings/c>
38
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
39
+ )
40
+ target_compile_definitions(
41
+ tree-sitter-posix-awk
42
+ PRIVATE
43
+ $<$<BOOL:${TREE_SITTER_REUSE_ALLOCATOR}>:TREE_SITTER_REUSE_ALLOCATOR>
44
+ $<$<CONFIG:Debug>:TREE_SITTER_DEBUG>
45
+ )
46
+ set_target_properties(
47
+ tree-sitter-posix-awk
48
+ PROPERTIES
49
+ C_STANDARD 11
50
+ C_STANDARD_REQUIRED ON
51
+ DEFINE_SYMBOL ""
52
+ POSITION_INDEPENDENT_CODE ON
53
+ SOVERSION "${TREE_SITTER_ABI_VERSION}.${PROJECT_VERSION_MAJOR}"
54
+ )
55
+
56
+ if(BUILD_TESTING AND CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
57
+ add_executable(tree-sitter-posix-awk-binding-test test/binding.test.c)
58
+ target_link_libraries(tree-sitter-posix-awk-binding-test PRIVATE tree-sitter-posix-awk)
59
+ add_test(
60
+ NAME tree-sitter-posix-awk-binding
61
+ COMMAND tree-sitter-posix-awk-binding-test
62
+ )
63
+ endif()
64
+
65
+ configure_file(
66
+ bindings/c/tree-sitter-posix-awk.pc.in
67
+ "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-posix-awk.pc"
68
+ @ONLY
69
+ )
70
+
71
+ install(
72
+ TARGETS tree-sitter-posix-awk
73
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
74
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
75
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
76
+ )
77
+ install(
78
+ DIRECTORY bindings/c/tree_sitter
79
+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
80
+ FILES_MATCHING PATTERN "*.h"
81
+ )
82
+ install(
83
+ FILES "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-posix-awk.pc"
84
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
85
+ )
86
+ install(
87
+ DIRECTORY queries/
88
+ DESTINATION "${CMAKE_INSTALL_DATADIR}/tree-sitter/queries/posix_awk"
89
+ FILES_MATCHING PATTERN "*.scm"
90
+ )
package/Cargo.toml ADDED
@@ -0,0 +1,27 @@
1
+ [package]
2
+ authors = [ "konomanoasa" ]
3
+ autoexamples = false
4
+ categories = [ "parser-implementations", "parsing", "text-editors" ]
5
+ description = "Tree-sitter grammar for POSIX awk."
6
+ edition = "2024"
7
+ keywords = [ "incremental", "parsing", "tree-sitter", "awk" ]
8
+ license = "MIT"
9
+ name = "tree-sitter-posix-awk"
10
+ readme = "README.md"
11
+ repository = "https://github.com/konomanoasa/tree-sitter-posix-awk"
12
+ version = "0.7.0"
13
+
14
+ build = "bindings/rust/build.rs"
15
+ include = [ "bindings/rust/*", "grammar.js", "queries/*", "src/*", "tree-sitter.json", "/LICENSE" ]
16
+
17
+ [lib]
18
+ path = "bindings/rust/lib.rs"
19
+
20
+ [dependencies]
21
+ tree-sitter-language = "0.1"
22
+
23
+ [build-dependencies]
24
+ cc = "1.2"
25
+
26
+ [dev-dependencies]
27
+ tree-sitter = "0.27.0"
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 konomanoasa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/Makefile ADDED
@@ -0,0 +1,131 @@
1
+ LANGUAGE_NAME := tree-sitter-posix-awk
2
+ HOMEPAGE_URL := https://github.com/konomanoasa/tree-sitter-posix-awk
3
+ VERSION := 0.7.0
4
+ DESCRIPTION := Tree-sitter grammar for POSIX awk.
5
+
6
+ PREFIX ?= /usr/local
7
+ DATADIR ?= $(PREFIX)/share
8
+ INCLUDEDIR ?= $(PREFIX)/include
9
+ LIBDIR ?= $(PREFIX)/lib
10
+ BINDIR ?= $(PREFIX)/bin
11
+ PCLIBDIR ?= $(LIBDIR)/pkgconfig
12
+
13
+ SOURCES := src/parser.c src/scanner.c
14
+ OBJECTS := $(SOURCES:.c=.o)
15
+ MAKE_BUILD_DIR := build/make
16
+ STATIC_LIBRARY := lib$(LANGUAGE_NAME).a
17
+ PKG_CONFIG := $(LANGUAGE_NAME).pc
18
+ TEST := $(MAKE_BUILD_DIR)/binding.test
19
+
20
+ ARFLAGS := rcs
21
+ override CFLAGS += -std=c11 -fPIC
22
+
23
+ SONAME_MAJOR := $(shell sed -n 's/\#define LANGUAGE_VERSION //p' src/parser.c)
24
+ SONAME_MINOR := $(word 1,$(subst ., ,$(VERSION)))
25
+
26
+ ifeq ($(SONAME_MAJOR),)
27
+ $(error The parser must define LANGUAGE_VERSION)
28
+ endif
29
+
30
+ MACHINE := $(shell $(CC) -dumpmachine)
31
+
32
+ ifneq ($(findstring darwin,$(MACHINE)),)
33
+ SOEXT := dylib
34
+ SOEXTVER_MAJOR := $(SONAME_MAJOR).$(SOEXT)
35
+ SOEXTVER := $(SONAME_MAJOR).$(SONAME_MINOR).$(SOEXT)
36
+ LINKSHARED := -dynamiclib -Wl,-install_name,$(LIBDIR)/lib$(LANGUAGE_NAME).$(SOEXTVER)
37
+ else ifneq ($(findstring mingw32,$(MACHINE)),)
38
+ SOEXT := dll
39
+ LINKSHARED := -s -shared -Wl,--out-implib,lib$(LANGUAGE_NAME).dll.a
40
+ TEST := $(MAKE_BUILD_DIR)/binding.test.exe
41
+ else
42
+ SOEXT := so
43
+ SOEXTVER_MAJOR := $(SOEXT).$(SONAME_MAJOR)
44
+ SOEXTVER := $(SOEXT).$(SONAME_MAJOR).$(SONAME_MINOR)
45
+ LINKSHARED := -shared -Wl,-soname,lib$(LANGUAGE_NAME).$(SOEXTVER)
46
+ ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),)
47
+ PCLIBDIR := $(PREFIX)/libdata/pkgconfig
48
+ endif
49
+ endif
50
+
51
+ SHARED_LIBRARY := lib$(LANGUAGE_NAME).$(SOEXT)
52
+
53
+ all: $(STATIC_LIBRARY) $(SHARED_LIBRARY) $(PKG_CONFIG)
54
+
55
+ $(STATIC_LIBRARY): $(OBJECTS)
56
+ $(AR) $(ARFLAGS) $@ $^
57
+
58
+ $(SHARED_LIBRARY): $(OBJECTS)
59
+ $(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@
60
+ ifneq ($(STRIP),)
61
+ $(STRIP) $@
62
+ endif
63
+
64
+ $(PKG_CONFIG): bindings/c/$(LANGUAGE_NAME).pc.in FORCE
65
+ sed -e 's|@PROJECT_VERSION@|$(VERSION)|' \
66
+ -e 's|@CMAKE_INSTALL_LIBDIR@|$(LIBDIR:$(PREFIX)/%=%)|' \
67
+ -e 's|@CMAKE_INSTALL_INCLUDEDIR@|$(INCLUDEDIR:$(PREFIX)/%=%)|' \
68
+ -e 's|@PROJECT_DESCRIPTION@|$(DESCRIPTION)|' \
69
+ -e 's|@PROJECT_HOMEPAGE_URL@|$(HOMEPAGE_URL)|' \
70
+ -e 's|@CMAKE_INSTALL_PREFIX@|$(PREFIX)|' $< > $@
71
+
72
+ src/parser.o: src/tree_sitter/parser.h
73
+ src/scanner.o: src/tree_sitter/alloc.h src/tree_sitter/parser.h
74
+
75
+ $(MAKE_BUILD_DIR):
76
+ mkdir -p $@
77
+
78
+ $(TEST): test/binding.test.c $(STATIC_LIBRARY) | $(MAKE_BUILD_DIR)
79
+ $(CC) $(CPPFLAGS) $(CFLAGS) -Ibindings/c $< $(STATIC_LIBRARY) $(LDFLAGS) $(LDLIBS) -o $@
80
+
81
+ test: $(TEST)
82
+ ./$(TEST)
83
+
84
+ install: all
85
+ install -d '$(DESTDIR)$(DATADIR)'/tree-sitter/queries/posix_awk \
86
+ '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter \
87
+ '$(DESTDIR)$(PCLIBDIR)' \
88
+ '$(DESTDIR)$(LIBDIR)'
89
+ install -m644 bindings/c/tree_sitter/$(LANGUAGE_NAME).h \
90
+ '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h
91
+ install -m644 $(PKG_CONFIG) '$(DESTDIR)$(PCLIBDIR)'/$(PKG_CONFIG)
92
+ install -m644 $(STATIC_LIBRARY) '$(DESTDIR)$(LIBDIR)'/$(STATIC_LIBRARY)
93
+ ifneq ($(findstring mingw32,$(MACHINE)),)
94
+ install -d '$(DESTDIR)$(BINDIR)'
95
+ install -m755 $(SHARED_LIBRARY) '$(DESTDIR)$(BINDIR)'/$(SHARED_LIBRARY)
96
+ install -m644 lib$(LANGUAGE_NAME).dll.a \
97
+ '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).dll.a
98
+ else
99
+ install -m755 $(SHARED_LIBRARY) \
100
+ '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER)
101
+ cd '$(DESTDIR)$(LIBDIR)' && \
102
+ ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER) \
103
+ lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR)
104
+ cd '$(DESTDIR)$(LIBDIR)' && \
105
+ ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) $(SHARED_LIBRARY)
106
+ endif
107
+ install -m644 queries/*.scm \
108
+ '$(DESTDIR)$(DATADIR)'/tree-sitter/queries/posix_awk
109
+
110
+ uninstall:
111
+ $(RM) '$(DESTDIR)$(LIBDIR)'/$(STATIC_LIBRARY) \
112
+ '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h \
113
+ '$(DESTDIR)$(PCLIBDIR)'/$(PKG_CONFIG)
114
+ ifneq ($(findstring mingw32,$(MACHINE)),)
115
+ $(RM) '$(DESTDIR)$(BINDIR)'/$(SHARED_LIBRARY) \
116
+ '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).dll.a
117
+ else
118
+ $(RM) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) \
119
+ '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) \
120
+ '$(DESTDIR)$(LIBDIR)'/$(SHARED_LIBRARY)
121
+ endif
122
+ $(RM) -r '$(DESTDIR)$(DATADIR)'/tree-sitter/queries/posix_awk
123
+
124
+ clean:
125
+ $(RM) $(OBJECTS) $(STATIC_LIBRARY) $(SHARED_LIBRARY) \
126
+ lib$(LANGUAGE_NAME).dll.a $(PKG_CONFIG)
127
+ $(RM) -r $(MAKE_BUILD_DIR)
128
+
129
+ FORCE:
130
+
131
+ .PHONY: all clean FORCE install test uninstall
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # tree-sitter-posix-awk
2
+
3
+ [![CI](https://github.com/konomanoasa/tree-sitter-posix-awk/actions/workflows/ci.yml/badge.svg)](https://github.com/konomanoasa/tree-sitter-posix-awk/actions/workflows/ci.yml)
4
+ [![npm](https://img.shields.io/npm/v/@konomanoasa/tree-sitter-posix-awk)](https://www.npmjs.com/package/@konomanoasa/tree-sitter-posix-awk)
5
+
6
+ [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) grammar for
7
+ POSIX.1-2024 `awk`.
8
+
9
+ ## Installation
10
+
11
+ ```sh
12
+ npm install @konomanoasa/tree-sitter-posix-awk
13
+ ```
14
+
15
+ ## Development
16
+
17
+ ```sh
18
+ npm ci
19
+ npm run tree-sitter -- parse script.awk
20
+ npm run check
21
+ ```
22
+
23
+ ## Specification
24
+
25
+ - [POSIX.1-2024 `awk`](https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/utilities/awk.html)
26
+ - [POSIX.1-2024 extended regular expressions](https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/basedefs/V1_chap09.html#tag_09_04)
27
+
28
+ ## License
29
+
30
+ [MIT](LICENSE)
@@ -0,0 +1,10 @@
1
+ prefix=@CMAKE_INSTALL_PREFIX@
2
+ libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
3
+ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
4
+
5
+ Name: tree-sitter-posix-awk
6
+ Description: @PROJECT_DESCRIPTION@
7
+ URL: @PROJECT_HOMEPAGE_URL@
8
+ Version: @PROJECT_VERSION@
9
+ Libs: -L${libdir} -ltree-sitter-posix-awk
10
+ Cflags: -I${includedir}
@@ -0,0 +1,16 @@
1
+ #ifndef TREE_SITTER_POSIX_AWK_H_
2
+ #define TREE_SITTER_POSIX_AWK_H_
3
+
4
+ typedef struct TSLanguage TSLanguage;
5
+
6
+ #ifdef __cplusplus
7
+ extern "C" {
8
+ #endif
9
+
10
+ const TSLanguage *tree_sitter_posix_awk(void);
11
+
12
+ #ifdef __cplusplus
13
+ }
14
+ #endif
15
+
16
+ #endif
@@ -0,0 +1,46 @@
1
+ fn main() {
2
+ let src_dir = std::path::Path::new("src");
3
+
4
+ let mut c_config = cc::Build::new();
5
+ c_config.std("c11").include(src_dir);
6
+
7
+ #[cfg(target_env = "msvc")]
8
+ c_config.flag("-utf-8");
9
+
10
+ if std::env::var("TARGET").unwrap() == "wasm32-unknown-unknown" {
11
+ let Ok(wasm_headers) = std::env::var("DEP_TREE_SITTER_LANGUAGE_WASM_HEADERS") else {
12
+ panic!("Environment variable DEP_TREE_SITTER_LANGUAGE_WASM_HEADERS must be set by the language crate");
13
+ };
14
+
15
+ c_config.include(&wasm_headers);
16
+ }
17
+
18
+ let parser_path = src_dir.join("parser.c");
19
+ c_config.file(&parser_path);
20
+ println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
21
+
22
+ let scanner_path = src_dir.join("scanner.c");
23
+ if scanner_path.exists() {
24
+ c_config.file(&scanner_path);
25
+ println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
26
+ }
27
+
28
+ c_config.compile("tree-sitter-posix-awk");
29
+
30
+ println!("cargo:rustc-check-cfg=cfg(with_highlights_query)");
31
+ if !"queries/highlights.scm".is_empty() && std::path::Path::new("queries/highlights.scm").exists() {
32
+ println!("cargo:rustc-cfg=with_highlights_query");
33
+ }
34
+ println!("cargo:rustc-check-cfg=cfg(with_injections_query)");
35
+ if !"queries/injections.scm".is_empty() && std::path::Path::new("queries/injections.scm").exists() {
36
+ println!("cargo:rustc-cfg=with_injections_query");
37
+ }
38
+ println!("cargo:rustc-check-cfg=cfg(with_locals_query)");
39
+ if !"queries/locals.scm".is_empty() && std::path::Path::new("queries/locals.scm").exists() {
40
+ println!("cargo:rustc-cfg=with_locals_query");
41
+ }
42
+ println!("cargo:rustc-check-cfg=cfg(with_tags_query)");
43
+ if !"queries/tags.scm".is_empty() && std::path::Path::new("queries/tags.scm").exists() {
44
+ println!("cargo:rustc-cfg=with_tags_query");
45
+ }
46
+ }
@@ -0,0 +1,60 @@
1
+ //! This crate provides POSIX awk language support for the [tree-sitter] parsing library.
2
+ //!
3
+ //! Typically, you will use the [`LANGUAGE`] constant to add this language to a
4
+ //! tree-sitter [`Parser`], and then use the parser to parse some code:
5
+ //!
6
+ //! ```
7
+ //! let code = r#"
8
+ //! "#;
9
+ //! let mut parser = tree_sitter::Parser::new();
10
+ //! let language = tree_sitter_posix_awk::LANGUAGE;
11
+ //! parser
12
+ //! .set_language(&language.into())
13
+ //! .expect("Error loading POSIX awk parser");
14
+ //! let tree = parser.parse(code, None).unwrap();
15
+ //! assert!(!tree.root_node().has_error());
16
+ //! ```
17
+ //!
18
+ //! [`Parser`]: https://docs.rs/tree-sitter/0.27.0/tree_sitter/struct.Parser.html
19
+ //! [tree-sitter]: https://tree-sitter.github.io/
20
+
21
+ use tree_sitter_language::LanguageFn;
22
+
23
+ unsafe extern "C" {
24
+ fn tree_sitter_posix_awk() -> *const ();
25
+ }
26
+
27
+ /// The tree-sitter [`LanguageFn`] for this grammar.
28
+ pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_posix_awk) };
29
+
30
+ /// The content of the [`node-types.json`] file for this grammar.
31
+ ///
32
+ /// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers/6-static-node-types
33
+ pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
34
+
35
+ #[cfg(with_highlights_query)]
36
+ /// The syntax highlighting query for this grammar.
37
+ pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
38
+
39
+ #[cfg(with_injections_query)]
40
+ /// The language injection query for this grammar.
41
+ pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm");
42
+
43
+ #[cfg(with_locals_query)]
44
+ /// The local variable query for this grammar.
45
+ pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm");
46
+
47
+ #[cfg(with_tags_query)]
48
+ /// The symbol tagging query for this grammar.
49
+ pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm");
50
+
51
+ #[cfg(test)]
52
+ mod tests {
53
+ #[test]
54
+ fn test_can_load_grammar() {
55
+ let mut parser = tree_sitter::Parser::new();
56
+ parser
57
+ .set_language(&super::LANGUAGE.into())
58
+ .expect("Error loading POSIX awk parser");
59
+ }
60
+ }