diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 40d3f09..f4df3fd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,8 +42,6 @@ jobs: uses: tree-sitter/parser-test-action@v1.2 - name: Rebuild with default extensions run: npm run build - env: - EXTENSION_DEFAULT: 1 - name: Verify grammar consistency run: git diff --exit-code -- */src/grammar.json fuzz: diff --git a/Makefile b/Makefile index e399c60..70dfe66 100644 --- a/Makefile +++ b/Makefile @@ -1,99 +1,5 @@ -VERSION := 0.2.0 +all install uninstall clean: + $(MAKE) -C tree-sitter-markdown $@ + $(MAKE) -C tree-sitter-markdown-inline $@ -LANGUAGE_NAME := tree-sitter-markdown - -# repository -PARSER_URL := https://github.com/tree-sitter-grammars/tree-sitter-markdown - -TS ?= tree-sitter - -# ABI versioning -SONAME_MAJOR := $(word 1,$(subst ., ,$(VERSION))) -SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION))) - -# install directory layout -PREFIX ?= /usr/local -INCLUDEDIR ?= $(PREFIX)/include -LIBDIR ?= $(PREFIX)/lib -PCLIBDIR ?= $(LIBDIR)/pkgconfig - -# object files -OBJS := $(patsubst %.c,%.o,$(wildcard */src/*.c)) - -# flags -ARFLAGS := rcs -override CFLAGS += -Itree-sitter-markdown/src -std=c11 -fPIC - -# OS-specific bits -ifeq ($(OS),Windows_NT) - $(error "Windows is not supported") -else ifeq ($(shell uname),Darwin) - SOEXT = dylib - SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib - SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib - LINKSHARED := $(LINKSHARED)-dynamiclib -Wl, - ifneq ($(ADDITIONAL_LIBS),) - LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS), - endif - LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/lib$(LANGUAGE_NAME).$(SONAME_MAJOR).dylib,-rpath,@executable_path/../Frameworks -else - SOEXT = so - SOEXTVER_MAJOR = so.$(SONAME_MAJOR) - SOEXTVER = so.$(SONAME_MAJOR).$(SONAME_MINOR) - LINKSHARED := $(LINKSHARED)-shared -Wl, - ifneq ($(ADDITIONAL_LIBS),) - LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS) - endif - LINKSHARED := $(LINKSHARED)-soname,lib$(LANGUAGE_NAME).so.$(SONAME_MAJOR) -endif -ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),) - PCLIBDIR := $(PREFIX)/libdata/pkgconfig -endif - -all: lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) $(LANGUAGE_NAME).pc - -lib$(LANGUAGE_NAME).a: $(OBJS) - $(AR) $(ARFLAGS) $@ $^ - -lib$(LANGUAGE_NAME).$(SOEXT): $(OBJS) - $(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@ -ifneq ($(STRIP),) - $(STRIP) $@ -endif - -$(LANGUAGE_NAME).pc: bindings/c/$(LANGUAGE_NAME).pc.in - sed -e 's|@URL@|$(PARSER_URL)|' \ - -e 's|@VERSION@|$(VERSION)|' \ - -e 's|@LIBDIR@|$(LIBDIR)|' \ - -e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \ - -e 's|@REQUIRES@|$(REQUIRES)|' \ - -e 's|@ADDITIONAL_LIBS@|$(ADDITIONAL_LIBS)|' \ - -e 's|=$(PREFIX)|=$${prefix}|' \ - -e 's|@PREFIX@|$(PREFIX)|' $< > $@ - -$(SRC_DIR)/parser.c: grammar.js - $(TS) generate --no-bindings - -install: all - install -Dm644 bindings/c/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h - install -Dm644 $(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc - install -Dm755 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a - install -m755 lib$(LANGUAGE_NAME).$(SOEXT) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) - ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) - ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) - -uninstall: - $(RM) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a \ - '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) \ - '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) \ - '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) \ - '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h \ - '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc - -clean: - $(RM) $(OBJS) $(LANGUAGE_NAME).pc lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) - -test: - $(TS) test - -.PHONY: all install uninstall clean test +.PHONY: all install uninstall clean diff --git a/bindings/.gitignore b/bindings/.gitignore new file mode 100644 index 0000000..a045ec8 --- /dev/null +++ b/bindings/.gitignore @@ -0,0 +1,2 @@ +c/ +swift/*/ diff --git a/common/common.mak b/common/common.mak new file mode 100644 index 0000000..d50c3b8 --- /dev/null +++ b/common/common.mak @@ -0,0 +1,107 @@ +VERSION := 0.2.0 + +# repository +SRC_DIR := src + +PARSER_REPO_URL := $(shell git -C $(SRC_DIR) remote get-url origin 2>/dev/null) + +ifeq ($(PARSER_URL),) + PARSER_URL := $(subst .git,,$(PARSER_REPO_URL)) +ifeq ($(shell echo $(PARSER_URL) | grep '^[a-z][-+.0-9a-z]*://'),) + PARSER_URL := $(subst :,/,$(PARSER_URL)) + PARSER_URL := $(subst git@,https://,$(PARSER_URL)) +endif +endif + +TS ?= tree-sitter + +# ABI versioning +SONAME_MAJOR := $(word 1,$(subst ., ,$(VERSION))) +SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION))) + +# install directory layout +PREFIX ?= /usr/local +INCLUDEDIR ?= $(PREFIX)/include +LIBDIR ?= $(PREFIX)/lib +PCLIBDIR ?= $(LIBDIR)/pkgconfig + +# object files +OBJS := $(patsubst %.c,%.o,$(wildcard $(SRC_DIR)/*.c)) + +# flags +ARFLAGS := rcs +override CFLAGS += -I$(SRC_DIR) -std=c11 -fPIC + +# OS-specific bits +ifeq ($(OS),Windows_NT) + $(error "Windows is not supported") +else ifeq ($(shell uname),Darwin) + SOEXT = dylib + SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib + SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib + LINKSHARED := $(LINKSHARED)-dynamiclib -Wl, + ifneq ($(ADDITIONAL_LIBS),) + LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS), + endif + LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/lib$(LANGUAGE_NAME).$(SONAME_MAJOR).dylib,-rpath,@executable_path/../Frameworks +else + SOEXT = so + SOEXTVER_MAJOR = so.$(SONAME_MAJOR) + SOEXTVER = so.$(SONAME_MAJOR).$(SONAME_MINOR) + LINKSHARED := $(LINKSHARED)-shared -Wl, + ifneq ($(ADDITIONAL_LIBS),) + LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS) + endif + LINKSHARED := $(LINKSHARED)-soname,lib$(LANGUAGE_NAME).so.$(SONAME_MAJOR) +endif +ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),) + PCLIBDIR := $(PREFIX)/libdata/pkgconfig +endif + +all: lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) $(LANGUAGE_NAME).pc + +lib$(LANGUAGE_NAME).a: $(OBJS) + $(AR) $(ARFLAGS) $@ $^ + +lib$(LANGUAGE_NAME).$(SOEXT): $(OBJS) + $(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@ +ifneq ($(STRIP),) + $(STRIP) $@ +endif + +$(LANGUAGE_NAME).pc: bindings/c/$(LANGUAGE_NAME).pc.in + sed -e 's|@URL@|$(PARSER_URL)|' \ + -e 's|@VERSION@|$(VERSION)|' \ + -e 's|@LIBDIR@|$(LIBDIR)|' \ + -e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \ + -e 's|@REQUIRES@|$(REQUIRES)|' \ + -e 's|@ADDITIONAL_LIBS@|$(ADDITIONAL_LIBS)|' \ + -e 's|=$(PREFIX)|=$${prefix}|' \ + -e 's|@PREFIX@|$(PREFIX)|' $< > $@ + +$(SRC_DIR)/parser.c: grammar.js + $(TS) generate --no-bindings + +install: all + install -Dm644 bindings/c/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h + install -Dm644 $(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc + install -Dm755 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a + install -m755 lib$(LANGUAGE_NAME).$(SOEXT) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) + ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) + ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) + +uninstall: + $(RM) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a \ + '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) \ + '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) \ + '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) \ + '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h \ + '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc + +clean: + $(RM) $(OBJS) $(LANGUAGE_NAME).pc lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) + +test: + $(TS) test + +.PHONY: all install uninstall clean test diff --git a/tree-sitter-markdown-inline/Makefile b/tree-sitter-markdown-inline/Makefile new file mode 100644 index 0000000..f84b8cc --- /dev/null +++ b/tree-sitter-markdown-inline/Makefile @@ -0,0 +1,3 @@ +LANGUAGE_NAME := tree-sitter-markdown-inline + +include ../common/common.mak diff --git a/tree-sitter-markdown-inline/bindings/c/tree-sitter-markdown-inline.h b/tree-sitter-markdown-inline/bindings/c/tree-sitter-markdown-inline.h new file mode 100644 index 0000000..66df323 --- /dev/null +++ b/tree-sitter-markdown-inline/bindings/c/tree-sitter-markdown-inline.h @@ -0,0 +1,16 @@ +#ifndef TREE_SITTER_MARKDOWN_INLINE_H_ +#define TREE_SITTER_MARKDOWN_INLINE_H_ + +typedef struct TSLanguage TSLanguage; + +#ifdef __cplusplus +extern "C" { +#endif + +const TSLanguage *tree_sitter_markdown_inline(void); + +#ifdef __cplusplus +} +#endif + +#endif // TREE_SITTER_MARKDOWN_INLINE_H_ diff --git a/tree-sitter-markdown-inline/bindings/c/tree-sitter-markdown-inline.pc.in b/tree-sitter-markdown-inline/bindings/c/tree-sitter-markdown-inline.pc.in new file mode 100644 index 0000000..3302561 --- /dev/null +++ b/tree-sitter-markdown-inline/bindings/c/tree-sitter-markdown-inline.pc.in @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ + +Name: tree-sitter-markdown-inline +Description: Markdown grammar for tree-sitter (inline) +URL: @URL@ +Version: @VERSION@ +Requires: @REQUIRES@ +Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-markdown-inline +Cflags: -I${includedir} diff --git a/tree-sitter-markdown/Makefile b/tree-sitter-markdown/Makefile new file mode 100644 index 0000000..57afae2 --- /dev/null +++ b/tree-sitter-markdown/Makefile @@ -0,0 +1,5 @@ +LANGUAGE_NAME := tree-sitter-markdown + +REQUIRES := tree-sitter-markdown-inline + +include ../common/common.mak diff --git a/bindings/c/tree-sitter-markdown.h b/tree-sitter-markdown/bindings/c/tree-sitter-markdown.h similarity index 82% rename from bindings/c/tree-sitter-markdown.h rename to tree-sitter-markdown/bindings/c/tree-sitter-markdown.h index 2ef15f0..83b6170 100644 --- a/bindings/c/tree-sitter-markdown.h +++ b/tree-sitter-markdown/bindings/c/tree-sitter-markdown.h @@ -8,7 +8,6 @@ extern "C" { #endif const TSLanguage *tree_sitter_markdown(void); -const TSLanguage *tree_sitter_markdown_inline(void); #ifdef __cplusplus } diff --git a/bindings/c/tree-sitter-markdown.pc.in b/tree-sitter-markdown/bindings/c/tree-sitter-markdown.pc.in similarity index 80% rename from bindings/c/tree-sitter-markdown.pc.in rename to tree-sitter-markdown/bindings/c/tree-sitter-markdown.pc.in index e1608a4..d249d6e 100644 --- a/bindings/c/tree-sitter-markdown.pc.in +++ b/tree-sitter-markdown/bindings/c/tree-sitter-markdown.pc.in @@ -3,7 +3,7 @@ libdir=@LIBDIR@ includedir=@INCLUDEDIR@ Name: tree-sitter-markdown -Description: Markdown grammar for tree-sitter +Description: Markdown grammar for tree-sitter (block) URL: @URL@ Version: @VERSION@ Requires: @REQUIRES@