Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
itsaky committed Sep 25, 2023
2 parents 5d422b5 + 06a2f6e commit cf989bb
Show file tree
Hide file tree
Showing 18 changed files with 534,941 additions and 505,850 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ on:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '12'
cache: 'npm'
node-version: '18'
- name: Install dependencies
run: npm install
- name: Generate parser
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/deploy-to-crates-io.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '12'
cache: 'npm'
node-version: '18'
- name: Install dependencies
run: npm install
- name: Compile grammar
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/deploy-to-github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '12'
cache: 'npm'
node-version: '18'
- name: Install dependencies
run: npm install
- name: Compile grammar
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/deploy-to-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '12'
node-version: '18'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Compile grammar
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/regenerate-parser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Regenerate Parser

on:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Configure Git user
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm install
- name: Generate parser
run: npm run generate
- name: Commit the updated parser
run: |
git add src
git commit -m "Regenerate the parser ($(git rev-parse --short HEAD))"
git push
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ node_modules

# Rust build artifacts
target

# C
/*.a
/*.dylib
/*.so*
*.o
/bindings/c/*.h
/bindings/c/tree-sitter-*.pc
114 changes: 114 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
VERSION := 0.2.11

# Repository
SRC_DIR := src

PARSER_REPO_URL := $(shell git -C $(SRC_DIR) remote get-url origin )

ifeq (, $(PARSER_NAME))
PARSER_NAME := $(shell basename $(PARSER_REPO_URL))
PARSER_NAME := $(subst tree-sitter-,,$(PARSER_NAME))
PARSER_NAME := $(subst .git,,$(PARSER_NAME))
endif

ifeq (, $(PARSER_URL))
PARSER_URL := $(subst :,/,$(PARSER_REPO_URL))
PARSER_URL := $(subst git@,https://,$(PARSER_URL))
PARSER_URL := $(subst .git,,$(PARSER_URL))
endif

UPPER_PARSER_NAME := $(shell echo $(PARSER_NAME) | tr a-z A-Z )

# install directory layout
PREFIX ?= /usr/local
INCLUDEDIR ?= $(PREFIX)/include
LIBDIR ?= $(PREFIX)/lib
PCLIBDIR ?= $(LIBDIR)/pkgconfig

# collect C++ sources, and link if necessary
CPPSRC := $(wildcard $(SRC_DIR)/*.cc)

ifeq (, $(CPPSRC))
ADDITIONALLIBS :=
else
ADDITIONALLIBS := -lc++
endif

# collect sources
SRC := $(wildcard $(SRC_DIR)/*.c)
SRC += $(CPPSRC)
OBJ := $(addsuffix .o,$(basename $(SRC)))

# ABI versioning
SONAME_MAJOR := 0
SONAME_MINOR := 0

CFLAGS ?= -O3 -Wall -Wextra -I$(SRC_DIR)
CXXFLAGS ?= -O3 -Wall -Wextra -I$(SRC_DIR)
override CFLAGS += -std=gnu99 -fPIC
override CXXFLAGS += -fPIC

# OS-specific bits
ifeq ($(shell uname),Darwin)
SOEXT = dylib
SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib
SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib
LINKSHARED := $(LINKSHARED)-dynamiclib -Wl,
ifneq ($(ADDITIONALLIBS),)
LINKSHARED := $(LINKSHARED)$(ADDITIONALLIBS),
endif
LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/libtree-sitter-$(PARSER_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 ($(ADDITIONALLIBS),)
LINKSHARED := $(LINKSHARED)$(ADDITIONALLIBS),
endif
LINKSHARED := $(LINKSHARED)-soname,libtree-sitter-$(PARSER_NAME).so.$(SONAME_MAJOR)
endif
ifneq (,$(filter $(shell uname),FreeBSD NetBSD DragonFly))
PCLIBDIR := $(PREFIX)/libdata/pkgconfig
endif

all: libtree-sitter-$(PARSER_NAME).a libtree-sitter-$(PARSER_NAME).$(SOEXTVER) bindings/c/$(PARSER_NAME).h bindings/c/tree-sitter-$(PARSER_NAME).pc

libtree-sitter-$(PARSER_NAME).a: $(OBJ)
$(AR) rcs $@ $^

libtree-sitter-$(PARSER_NAME).$(SOEXTVER): $(OBJ)
$(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@
ln -sf $@ libtree-sitter-$(PARSER_NAME).$(SOEXT)
ln -sf $@ libtree-sitter-$(PARSER_NAME).$(SOEXTVER_MAJOR)

bindings/c/$(PARSER_NAME).h:
sed -e 's|@UPPER_PARSERNAME@|$(UPPER_PARSER_NAME)|' \
-e 's|@PARSERNAME@|$(PARSER_NAME)|' \
bindings/c/tree-sitter.h.in > $@

bindings/c/tree-sitter-$(PARSER_NAME).pc:
sed -e 's|@LIBDIR@|$(LIBDIR)|;s|@INCLUDEDIR@|$(INCLUDEDIR)|;s|@VERSION@|$(VERSION)|' \
-e 's|=$(PREFIX)|=$${prefix}|' \
-e 's|@PREFIX@|$(PREFIX)|' \
-e 's|@ADDITIONALLIBS@|$(ADDITIONALLIBS)|' \
-e 's|@PARSERNAME@|$(PARSER_NAME)|' \
-e 's|@PARSERURL@|$(PARSER_URL)|' \
bindings/c/tree-sitter.pc.in > $@

install: all
install -d '$(DESTDIR)$(LIBDIR)'
install -m755 libtree-sitter-$(PARSER_NAME).a '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(PARSER_NAME).a
install -m755 libtree-sitter-$(PARSER_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(PARSER_NAME).$(SOEXTVER)
ln -sf libtree-sitter-$(PARSER_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(PARSER_NAME).$(SOEXTVER_MAJOR)
ln -sf libtree-sitter-$(PARSER_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(PARSER_NAME).$(SOEXT)
install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter
install -m644 bindings/c/$(PARSER_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/
install -d '$(DESTDIR)$(PCLIBDIR)'
install -m644 bindings/c/tree-sitter-$(PARSER_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/

clean:
rm -f $(OBJ) libtree-sitter-$(PARSER_NAME).a libtree-sitter-$(PARSER_NAME).$(SOEXT) libtree-sitter-$(PARSER_NAME).$(SOEXTVER_MAJOR) libtree-sitter-$(PARSER_NAME).$(SOEXTVER)
rm -f bindings/c/$(PARSER_NAME).h bindings/c/tree-sitter-$(PARSER_NAME).pc

.PHONY: all install clean
16 changes: 16 additions & 0 deletions bindings/c/tree-sitter.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef TREE_SITTER_@UPPER_PARSERNAME@_H_
#define TREE_SITTER_@UPPER_PARSERNAME@_H_

#include <tree_sitter/parser.h>

#ifdef __cplusplus
extern "C" {
#endif

extern TSLanguage *tree_sitter_@PARSERNAME@();

#ifdef __cplusplus
}
#endif

#endif // TREE_SITTER_@UPPER_PARSERNAME@_H_
11 changes: 11 additions & 0 deletions bindings/c/tree-sitter.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix=@PREFIX@
libdir=@LIBDIR@
includedir=@INCLUDEDIR@
additionallibs=@ADDITIONALLIBS@

Name: tree-sitter-@PARSERNAME@
Description: A tree-sitter grammar for the @PARSERNAME@ programming language.
URL: @PARSERURL@
Version: @VERSION@
Libs: -L${libdir} ${additionallibs} -ltree-sitter-@PARSERNAME@
Cflags: -I${includedir}
22 changes: 18 additions & 4 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ module.exports = grammar({

// ambiguity between parameter modifiers in anonymous functions
[$.parameter_modifiers, $._type_modifier],

// ambiguity between type modifiers before an @
[$.type_modifiers],
// ambiguity between associating type modifiers
[$.not_nullable_type],
],

externals: $ => [
Expand Down Expand Up @@ -466,13 +471,22 @@ module.exports = grammar({
$.parenthesized_type,
$.nullable_type,
$._type_reference,
$.function_type
$.function_type,
$.not_nullable_type
)
),

_type_reference: $ => choice(
_type_reference: $ => prec.left(1, choice(
$.user_type,
"dynamic"
)),

not_nullable_type: $ => seq(
optional($.type_modifiers),
choice($.user_type, $.parenthesized_user_type),
'&',
optional($.type_modifiers),
choice($.user_type, $.parenthesized_user_type),
),

nullable_type: $ => seq(
Expand Down Expand Up @@ -705,7 +719,7 @@ module.exports = grammar({
type_arguments: $ => seq("<", sep1($.type_projection, ","), ">"),

value_arguments: $ => seq(
"(",
"(",
optional(
seq(
sep1($.value_argument, ","),
Expand Down Expand Up @@ -1173,7 +1187,7 @@ module.exports = grammar({
$._backtick_identifier,
),

_alpha_identifier: $ => /[a-zA-Z_][a-zA-Z_0-9]*/,
_alpha_identifier: $ => /[\p{L}_][\p{L}_\p{Nd}]*/,

_backtick_identifier: $ => /`[^\r\n`]+`/,

Expand Down
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,15 @@
},
"homepage": "https://github.com/fwcd/tree-sitter-kotlin#readme",
"dependencies": {
"nan": "^2.15.0"
"nan": "^2.17.0"
},
"devDependencies": {
"tree-sitter-cli": "^0.20.7"
"tree-sitter-cli": "^0.20.8"
},
"tree-sitter": [
{
"scope": "source.kt",
"file-types": [
"kt",
"kts"
]
"scope": "source.kotlin",
"file-types": ["kt", "kts"]
}
]
}
Loading

0 comments on commit cf989bb

Please sign in to comment.