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

feat!: signature file grammar #86

Merged
merged 14 commits into from
Aug 31, 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
150 changes: 119 additions & 31 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,157 @@ name: CI
on:
push:
branches: ["main"]
paths:
- .github/**
- grammar.js
- src/**
- test/**
- bindings/**
- binding.gyp
pull_request:

concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true

jobs:
test:
test-parsers:
name: Test parser
runs-on: ${{matrix.os}}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-14]
language: [fsharp, fsharp_signature]
steps:
- uses: actions/checkout@v4
with:
submodules: ${{runner.os == 'Linux'}}
- uses: tree-sitter/setup-action/cli@v1
- uses: tree-sitter/parser-test-action@v2
- name: test language
uses: tree-sitter/parser-test-action@v2
with:
test-parser-cmd: cd ${{matrix.language}} && tree-sitter test
parse-examples:
name: Parse examples
runs-on: ${{matrix.os}}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-14]
steps:
- uses: actions/checkout@v4
with:
generate: false # ${{runner.os == 'Linux'}}
submodules: true
- uses: tree-sitter/setup-action/cli@v1
- name: Parse sample files
uses: tree-sitter/parse-action@v4
id: parse-files
continue-on-error: true
with:
files: |-
examples/Giraffe/**/*.fs
examples/FSharp.Data/**/*.fs
examples/FSharp.Compiler/tests/**/*.fs
invalid-files: |-
examples/FSharp.Compiler/tests/**/E_*.fs
examples/FSharp.Compiler/tests/**/neg*.fs
files-list: test/files.txt
invalid-files-list: test/invalid-files.txt
- name: Upload failures artifact
uses: actions/upload-artifact@v4
if: "!cancelled() && steps.parse-files.outcome == 'failure'"
with:
name: failures-${{runner.os}}
path: ${{steps.parse-files.outputs.failures}}

test-go:
name: Test Go binding
runs-on: ${{matrix.os}}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
cache-dependency-path: bindings/go/go.mod
- name: Get dependencies
working-directory: bindings/go
run: go get -t .
- name: Test
working-directory: bindings/go
run: go test -v

test-node:
name: Test Node binding
runs-on: ${{matrix.os}}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
- name: Install dependencies
run: npm install
- name: Test
run: npm run test-binding

test-python:
name: Test Python binding
runs-on: ${{matrix.os}}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
cache: pip
python-version: 3.12
cache-dependency-path: pyproject.toml
- name: Build
run: pip install -e .[core]
- name: Test
run: python -munittest discover -v -s bindings/python/tests

test-rust:
name: Test Rust binding
runs-on: ${{matrix.os}}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Build
run: cargo build -v
- name: Test
run: cargo test -v

# test-swift:
# name: Test Swift binding
# runs-on: ${{matrix.os}}
# strategy:
# fail-fast: false
# matrix:
# os: [ubuntu-latest, macos-latest]
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# - name: Build
# run: swift build
# - name: Test
# run: swift test

fuzz:
name: Fuzz parser
name: Fuzz fsharp
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
language: [fsharp, fsharp_signature]
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Check for scanner changes
id: scanner-changes
run: |-
if git diff --quiet HEAD^ -- src/scanner.c; then
printf 'changed=false\n' >> "$GITHUB_OUTPUT"
else
printf 'changed=true\n' >> "$GITHUB_OUTPUT"
fi
- name: Fuzz parser
uses: tree-sitter/fuzz-action@v4
if: steps.scanner-changes.outputs.changed == 'true'
with:
directory: ${{matrix.language}}
19 changes: 19 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Publish packages

on:
push:
tags: ["*"]

concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true

jobs:
npm:
uses: tree-sitter/workflows/.github/workflows/package-npm.yml@main
secrets:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
crates:
uses: tree-sitter/workflows/.github/workflows/package-crates.yml@main
secrets:
CARGO_REGISTRY_TOKEN: ${{secrets.CARGO_REGISTRY_TOKEN}}
11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ description = "fsharp grammar for the tree-sitter parsing library"
version = "0.0.1"
keywords = ["incremental", "parsing", "fsharp"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/nsidorenco/tree-sitter-fsharp"
repository = "https://github.com/ionide/tree-sitter-fsharp"
edition = "2021"
license = "MIT"

build = "bindings/rust/build.rs"
include = [
"bindings/rust/*",
"grammar.js",
"queries/*",
"src/*",
"common",
"fsharp/grammar.js",
"fsharp/src",
"fsharp_signature/grammar.js",
"fsharp_signature/src",
"queries"
]

[lib]
Expand Down
22 changes: 13 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ VERSION := 0.0.1
LANGUAGE_NAME := tree-sitter-fsharp

# repository
SRC_DIR := src
FSHARP_DIR := fsharp
SIGNATURE_DIR := fsharp_signature
SRC_DIR := fsharp/src

PARSER_REPO_URL := $(shell git -C $(SRC_DIR) remote get-url origin 2>/dev/null)
PARSER_REPO_URL := $(shell git remote get-url origin 2>/dev/null)

ifeq ($(PARSER_URL),)
PARSER_URL := $(subst .git,,$(PARSER_REPO_URL))
Expand All @@ -28,7 +30,7 @@ LIBDIR ?= $(PREFIX)/lib
PCLIBDIR ?= $(LIBDIR)/pkgconfig

# object files
OBJS := $(patsubst %.c,%.o,$(wildcard $(SRC_DIR)/*.c))
OBJS := $(patsubst %.c,%.o,$(wildcard grammars/*/src/*.c))

# flags
ARFLAGS := rcs
Expand Down Expand Up @@ -81,14 +83,16 @@ $(LANGUAGE_NAME).pc: bindings/c/$(LANGUAGE_NAME).pc.in
-e 's|=$(PREFIX)|=$${prefix}|' \
-e 's|@PREFIX@|$(PREFIX)|' $< > $@

$(SRC_DIR)/parser.c: grammar.js
$(TS) generate --no-bindings
$(FSHARP_DIR)/src/parser.c: $(FSHARP_DIR)/grammar.js
cd $(FSHARP_DIR) && $(TS) generate --no-bindings

$(SIGNATURE_DIR)/src/parser.c: $(FSHARP_DIR)/grammar.js $(SIGNATURE_DIR)/grammar.js
cd $(SIGNATURE_DIR) && $(TS) generate --no-bindings

install: all
install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter '$(DESTDIR)$(PCLIBDIR)' '$(DESTDIR)$(LIBDIR)'
install -m644 bindings/c/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h
install -m644 $(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc
install -m644 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a
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)
Expand Down
68 changes: 30 additions & 38 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,39 @@
import PackageDescription

let package = Package(
name: "TreeSitterFsharp",
platforms: [.macOS(.v10_13), .iOS(.v11)],
name: "TreeSitterFSharp",
products: [
.library(name: "TreeSitterFsharp", targets: ["TreeSitterFsharp"]),
.library(name: "TreeSitterFSharp", targets: ["TreeSitterFSharp"]),
],
dependencies: [
.package(url: "https://github.com/ChimeHQ/SwiftTreeSitter", from: "0.8.0"),
],
dependencies: [],
targets: [
.target(name: "TreeSitterFsharp",
path: ".",
exclude: [
"Cargo.toml",
"Makefile",
"binding.gyp",
"bindings/c",
"bindings/go",
"bindings/node",
"bindings/python",
"bindings/rust",
"prebuilds",
"grammar.js",
"package.json",
"package-lock.json",
"pyproject.toml",
"setup.py",
"test",
"examples",
".editorconfig",
".github",
".gitignore",
".gitattributes",
".gitmodules",
],
sources: [
"src/parser.c",
// NOTE: if your language has an external scanner, add it here.
],
resources: [
.copy("queries")
],
publicHeadersPath: "bindings/swift",
cSettings: [.headerSearchPath("src")])
.target(
name: "TreeSitterFSharp",
dependencies: [],
path: ".",
sources: [
"fsharp/src/parser.c",
"fsharp/src/scanner.c",
"fsharp_signature/src/parser.c",
"fsharp_signature/src/scanner.c",
],
resources: [
.copy("queries")
],
publicHeadersPath: "bindings/swift",
cSettings: [.headerSearchPath("fsharp/src")]
),
.testTarget(
name: "TreeSitterFSharpTests",
dependencies: [
"SwiftTreeSitter",
"TreeSitterFSharp",
],
path: "bindings/swift/TreeSitterFSharpTests"
)
],
cLanguageStandard: .c11
)

Loading
Loading