Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

triple quotes memory leak -> fix #3

Merged
merged 14 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
cmake_minimum_required(VERSION 3.13)

project(tree-sitter-idris
VERSION "0.0.1"
DESCRIPTION "Idris grammar for tree-sitter"
HOMEPAGE_URL "https://github.com/tree-sitter/tree-sitter-idris"
LANGUAGES C)

option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
option(TREE_SITTER_REUSE_ALLOCATOR "Reuse the library allocator" OFF)

set(TREE_SITTER_ABI_VERSION 14 CACHE STRING "Tree-sitter ABI version")
if(NOT ${TREE_SITTER_ABI_VERSION} MATCHES "^[0-9]+$")
unset(TREE_SITTER_ABI_VERSION CACHE)
message(FATAL_ERROR "TREE_SITTER_ABI_VERSION must be an integer")
endif()

find_program(TREE_SITTER_CLI tree-sitter DOC "Tree-sitter CLI")

add_custom_command(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/src/parser.c"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/grammar.json"
COMMAND "${TREE_SITTER_CLI}" generate src/grammar.json
--abi=${TREE_SITTER_ABI_VERSION}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Generating parser.c")

add_library(tree-sitter-idris src/parser.c)
if(EXISTS src/scanner.c)
target_sources(tree-sitter-idris PRIVATE src/scanner.c)
endif()
target_include_directories(tree-sitter-idris PRIVATE src)

target_compile_definitions(tree-sitter-idris PRIVATE
$<$<BOOL:${TREE_SITTER_REUSE_ALLOCATOR}>:TREE_SITTER_REUSE_ALLOCATOR>
$<$<CONFIG:Debug>:TREE_SITTER_DEBUG>)

set_target_properties(tree-sitter-idris
PROPERTIES
C_STANDARD 11
POSITION_INDEPENDENT_CODE ON
SOVERSION "${TREE_SITTER_ABI_VERSION}.${PROJECT_VERSION_MAJOR}"
DEFINE_SYMBOL "")

configure_file(bindings/c/tree-sitter-idris.pc.in
"${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-idris.pc" @ONLY)

include(GNUInstallDirs)

install(FILES bindings/c/tree-sitter-idris.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tree_sitter")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-idris.pc"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig")
install(TARGETS tree-sitter-idris
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")

add_custom_target(test "${TREE_SITTER_CLI}" test
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "tree-sitter test")

# vim:ft=cmake:
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]
path = "bindings/rust/lib.rs"

[dependencies]
tree-sitter = ">=0.22.5"
tree-sitter-language = "0.1.0"

[build-dependencies]
cc = "1.0.87"
2 changes: 1 addition & 1 deletion Package.swift

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

2 changes: 1 addition & 1 deletion binding.gyp

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

3 changes: 2 additions & 1 deletion bindings/go/binding.go

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

4 changes: 2 additions & 2 deletions bindings/go/binding_test.go

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

5 changes: 0 additions & 5 deletions bindings/go/go.mod

This file was deleted.

9 changes: 9 additions & 0 deletions bindings/node/binding_test.cjs

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

2 changes: 1 addition & 1 deletion bindings/node/index.js → bindings/node/index.cjs

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

11 changes: 11 additions & 0 deletions bindings/python/tests/test_binding.py

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

4 changes: 2 additions & 2 deletions bindings/python/tree_sitter_idris/binding.c

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

23 changes: 11 additions & 12 deletions bindings/rust/lib.rs

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

12 changes: 12 additions & 0 deletions bindings/swift/TreeSitterIdrisTests/TreeSitterIdrisTests.swift

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

7 changes: 3 additions & 4 deletions flake.lock

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

41 changes: 24 additions & 17 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/24.05";
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = inputs:
outputs =
inputs:
let
overlay = final: prev:
{
app-env = prev.buildEnv {
name = "app-env";
paths = with final; [
nodejs-18_x
yarn
python3
tree-sitter
clang-tools # clangd
graphviz # dot
];
};
overlay = final: prev: {
app-env = prev.buildEnv {
name = "app-env";
paths = with final; [
nodejs_22
yarn
python3
clang-tools # clangd
graphviz # dot
];
};
};

perSystem = system:
perSystem =
system:
let
pkgs = import inputs.nixpkgs { inherit system; overlays = [ overlay ]; };
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ overlay ];
};
in
{
devShell = pkgs.mkShell {
shellHook = ''
export PATH=$PWD/node_modules/.bin:$PATH
'';

buildInputs = with pkgs; [
app-env

Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/tree-sitter/tree-sitter-idris

go 1.23

require github.com/tree-sitter/go-tree-sitter v0.23
35 changes: 19 additions & 16 deletions grammar.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
const basic = require('./grammar/basic.js')
const id = require('./grammar/id.js')
const record = require('./grammar/record.js')
const type = require('./grammar/type.js')
const exp = require('./grammar/exp.js')
const pat = require('./grammar/pat.js')
const import_ = require('./grammar/import.js')
const module_ = require('./grammar/module.js')
const data = require('./grammar/data.js')
const interface = require('./grammar/interface.js')
const decl = require('./grammar/decl.js')
const pragma = require('./grammar/pragma.js')

module.exports = grammar({
import basic from './grammar/basic.js'
import id from './grammar/id.js'
import record from './grammar/record.js'
import type_ from './grammar/type.js'
import exp from './grammar/exp.js'
import pat from './grammar/pat.js'
import import_ from './grammar/import.js'
import module_ from './grammar/module.js'
import data from './grammar/data.js'
import interface_ from './grammar/interface.js'
import decl from './grammar/decl.js'
import pragma from './grammar/pragma.js'
import { terminated } from './grammar/util.js';


export default grammar({
name: 'idris',

/**
Expand Down Expand Up @@ -170,18 +172,19 @@ module.exports = grammar({
$._pragma_global,
$._pragma_internal,
$._pragma_reflection,
$._lcarrow, // fixes https://github.com/nvim-treesitter/nvim-treesitter/pull/7274#issuecomment-2435421390
),

...basic,
...id,
...record,
...type,
...type_,
...exp,
...pat,
...import_,
...module_,
...data,
...interface,
...interface_,
...decl,
...pragma,
}
Expand Down
Loading