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: reintroduce raw-strings #117

Merged
merged 61 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
ba78ff2
feat: reintroduce changes
mrdgo Sep 25, 2024
c6c753c
tmp: point to current parser and scanner
mrdgo Sep 25, 2024
5ed23d2
chore: declare scanner in necessary places
mrdgo Sep 25, 2024
f57e8e5
chore: do what fdncred did
mrdgo Sep 25, 2024
1963437
ci: I don't know what I am doing
mrdgo Sep 25, 2024
1fb1416
merge
mrdgo Sep 25, 2024
3861ad1
ci: experiments
mrdgo Sep 26, 2024
94d2877
ci: remove make
mrdgo Sep 27, 2024
532d46e
ci: provide init.lua
mrdgo Sep 27, 2024
bd9a128
ci: update lazy synchronosly
mrdgo Sep 30, 2024
443b241
ci: npm update
mrdgo Sep 30, 2024
dd33553
ci: npm update, again
mrdgo Oct 2, 2024
161aeec
ci: use . for tree-sitter-nu
mrdgo Oct 2, 2024
7b7cc09
ci: still try to repro bug
mrdgo Oct 4, 2024
88d2016
ci: add latest release
mrdgo Oct 4, 2024
3999d31
ci: synchronously install ts-nu
mrdgo Oct 4, 2024
0591a27
ci: desperate experiment to repro
mrdgo Oct 4, 2024
b238630
ci: try to fix path
mrdgo Oct 10, 2024
2895807
ci: change sed delimiters to path-proof '#'
mrdgo Oct 10, 2024
aee0cb1
ci: update, not sync
mrdgo Oct 10, 2024
70909bd
ci: + -> -c
mrdgo Oct 11, 2024
73a92e8
ci: force reinstall (no prompt)
mrdgo Oct 11, 2024
43e22df
ci: sed needs input.
mrdgo Oct 11, 2024
ccd0a5b
nvim: revert path
mrdgo Oct 11, 2024
2079cb1
ci: more assertion that local parser is used
mrdgo Oct 11, 2024
2bcaf9e
ci: terminate sed's 's' command
mrdgo Oct 11, 2024
68af951
ci: maybe TSInstall is unneeded
mrdgo Oct 11, 2024
a3cef41
ci: even less interaction with plugins
mrdgo Oct 11, 2024
a474565
ci: experiment
mrdgo Oct 11, 2024
c7b8dfb
scanner: fix logic precedence
mrdgo Oct 11, 2024
da3c7b9
scanner: rename lua module
mrdgo Oct 31, 2024
bb51a54
revert: rename init.lua
mrdgo Oct 31, 2024
6e4b9e0
Merge remote-tracking branch 'upstream' into raw-strings-pt2
mrdgo Nov 15, 2024
e028629
scanner: remove unneeded import
mrdgo Nov 15, 2024
049cb78
Merge branch 'main' into raw-strings-pt2
mrdgo Nov 19, 2024
99836fb
merge main, tree-sitter generate
mrdgo Nov 19, 2024
b9bdeb3
Delete src/grammar_BACKUP_35023.json
mrdgo Nov 20, 2024
21b96f0
Delete src/grammar_BASE_35023.json
mrdgo Nov 20, 2024
d8ec5d2
Delete src/grammar_LOCAL_35023.json
mrdgo Nov 20, 2024
3c50ee4
Delete src/grammar_REMOTE_35023.json
mrdgo Nov 20, 2024
1da0a4b
debug: cleanup ts config
mrdgo Nov 21, 2024
678b6fa
Merge branch 'main' into raw-strings-pt2
mrdgo Nov 21, 2024
6048c84
Delete tree-sitter.json
mrdgo Nov 21, 2024
a2cf7d0
fix: remove unused emitted_content
mrdgo Nov 21, 2024
22a2c0e
Merge branch 'raw-strings-pt2' of github.com:mrdgo/tree-sitter-nu int…
mrdgo Nov 21, 2024
eaf34d3
feat: allow empty raw strings, add test with empty string
mrdgo Nov 21, 2024
6e206de
fix: replace precondition for begin
mrdgo Nov 21, 2024
85d8a3f
ci: drop v0.9.x support (analogous to nvim-treesitter)
mrdgo Nov 21, 2024
f3ecc01
Merge branch 'main' into raw-strings-pt2
mrdgo Nov 21, 2024
6b1a0b2
chore: simplify detection of ending delimiter
mrdgo Nov 21, 2024
0cecb06
chore: convert perverted for loop to while loop
mrdgo Nov 21, 2024
8aead58
chore: move raw-strings from decl to expr
mrdgo Nov 21, 2024
9e1c2b2
ci: remove unrelated, non-helpful actions
mrdgo Nov 21, 2024
aae7804
Delete example-file.nu
mrdgo Nov 21, 2024
36a63ab
fix: add tree-sitter section
mrdgo Nov 21, 2024
cf8100b
Merge branch 'raw-strings-pt2' of github.com:mrdgo/tree-sitter-nu int…
mrdgo Nov 21, 2024
5cf30dc
chore: migrate to new tree-sitter.json
mrdgo Nov 21, 2024
f9a2eaf
chore: remove unnecessary checks
mrdgo Nov 21, 2024
4906a08
fix: remove unneeded highlights
mrdgo Nov 22, 2024
4305155
Merge branch 'main' of github.com:nushell/tree-sitter-nu
mrdgo Nov 22, 2024
e063b90
Merge branch 'main' into raw-strings-pt2
mrdgo Nov 22, 2024
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
37 changes: 37 additions & 0 deletions .github/neovim/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
-- Bootstrap lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
mrdgo marked this conversation as resolved.
Show resolved Hide resolved
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
if vim.v.shell_error ~= 0 then
vim.api.nvim_echo({
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
{ out, "WarningMsg" },
{ "\nPress any key to exit..." },
}, true, {})
vim.fn.getchar()
os.exit(1)
end
end
vim.opt.rtp:prepend(lazypath)

vim.g.mapleader = " "
vim.g.maplocalleader = "\\"

-- Setup lazy.nvim
require("lazy").setup({
spec = {
{
"nvim-treesitter/nvim-treesitter",
config = function()
require("nvim-treesitter.configs").setup({
highlight = { enable = true },
})
end,
dependencies = {
{ dir = "TS_NU_PATH", build = ":TSUpdate nu" },
},
build = ":TSUpdate",
},
},
})
8 changes: 7 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- main
jobs:
main:
name: install
name: setup, lint, test

runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -30,3 +30,9 @@ jobs:

- name: test
run: npx tree-sitter test

tests:
uses: ./.github/workflows/nvim-tests.yml
with:
neovim_versions: |
[ "nightly", "v0.10.2", "v0.10.1", "v0.9.5" ]
mrdgo marked this conversation as resolved.
Show resolved Hide resolved
39 changes: 39 additions & 0 deletions .github/workflows/nvim-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Run tests

on:
workflow_call:
inputs:
neovim_versions:
required: true
type: string

jobs:
tests:
name: unit tests
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
rev: ${{ fromJson(inputs.neovim_versions) }}
steps:
- uses: actions/checkout@v3
- run: date +%F > todays-date
- name: Restore cache for Neovim
uses: actions/cache@v3
with:
path: .ci/neovim
key: ${{ matrix.rev }}-${{ hashFiles('todays-date') }}
- name: Prepare
run: |
test -d .ci/neovim || {
mkdir -p .ci/neovim
curl -sL "https://github.com/neovim/neovim/releases/download/${{ matrix.rev }}/nvim-linux64.tar.gz" | tar xzf - --strip-components=1 -C "${PWD}/.ci/neovim"
}

- name: Run tests
run: |
export PATH="${PWD}/.ci/neovim/bin:${PATH}"
export VIM="${PWD}/.ci/neovim/share/nvim/runtime"
sed "s#TS_NU_PATH#${PWD}#" .github/neovim/init.lua > .ci/init.lua
sed -i "s#https://github.com/nushell/tree-sitter-nu#${PWD}#" ${PWD}/plugin/init.lua
nvim --headless -c "sleep | q" -u .ci/init.lua ts.nu
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let package = Package(
],
sources: [
"src/parser.c",
// NOTE: if your language has an external scanner, add it here.
"src/scanner.c",
],
resources: [
.copy("queries")
Expand Down
2 changes: 1 addition & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"sources": [
"bindings/node/binding.cc",
"src/parser.c",
# NOTE: if your language has an external scanner, add it here.
"src/scanner.c",
],
"conditions": [
["OS!='win'", {
Expand Down
2 changes: 1 addition & 1 deletion bindings/go/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package tree_sitter_nu

// #cgo CFLAGS: -std=c11 -fPIC
// #include "../../src/parser.c"
// // NOTE: if your language has an external scanner, add it here.
// #include "../../src/scanner.c"
import "C"

import "unsafe"
Expand Down
2 changes: 0 additions & 2 deletions bindings/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ fn main() {
// If your language uses an external scanner written in C,
// then include this block of code:

/*
let scanner_path = src_dir.join("scanner.c");
c_config.file(&scanner_path);
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
*/

c_config.compile("parser");
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
Expand Down
1 change: 1 addition & 0 deletions example-file.nu
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ let somevar = 4

def somecommand [x: int] {
echo $x
let bla = r#'blub'#
}
17 changes: 14 additions & 3 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ module.exports = grammar({
$._terminator,
],

// externals: $ => [
// ],
externals: ($) => [
$.raw_string_begin,
$.raw_string_content,
$.raw_string_end,
],

conflicts: ($) => [
[$._binary_predicate_parenthesized],
Expand Down Expand Up @@ -987,7 +990,15 @@ module.exports = grammar({
),

val_string: ($) =>
choice($._str_double_quotes, $._str_single_quotes, $._str_back_ticks),
choice(
$._str_double_quotes,
$._str_single_quotes,
$._str_back_ticks,
$._raw_str,
),

_raw_str: ($) =>
seq($.raw_string_begin, $.raw_string_content, $.raw_string_end),

_str_double_quotes: ($) =>
seq(
Expand Down
4 changes: 3 additions & 1 deletion installation/neovim.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
parser_config.nu = {
install_info = {
url = "https://github.com/nushell/tree-sitter-nu",
files = { "src/parser.c" },
files = { "src/parser.c", "src/scanner.c" },
branch = "main",
},
filetype = "nu",
Expand Down Expand Up @@ -68,6 +68,8 @@ mkdir $local
http get ([$remote $file] | str join "/") | save --force ($local | path join $file)
```

You need to run this snippet whenever the highlights change and `:TSUpdate nu` whenever there is a new version of the parser.

[tree-sitter]: https://tree-sitter.github.io/tree-sitter/
[nvim-treesitter]: https://github.com/nvim-treesitter/nvim-treesitter
[nvim-treesitter/playground]: https://github.com/nvim-treesitter/playground
Expand Down
53 changes: 28 additions & 25 deletions package-lock.json

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

20 changes: 5 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"author": "The Nushell Contributors",
"license": "MIT",
"dependencies": {
"node-addon-api": "^8.0.0",
"node-gyp-build": "^4.8.0"
"node-addon-api": "^8.1.0",
"node-gyp-build": "^4.8.2"
},
"peerDependencies": {
"tree-sitter": "^0.21.0"
Expand All @@ -25,20 +25,10 @@
}
},
"devDependencies": {
"prettier": "3.2.5",
"tree-sitter-cli": "^0.22.5",
"prettier": "3.3.3",
"tree-sitter-cli": "^0.23.0",
"prebuildify": "^6.0.0"
},
"tree-sitter": [
{
"scope": "source.nu",
"file-types": [
"nu"
],
"highlights": "queries/nu/highlights.scm",
"injections": "queries/nu/injections.scm"
}
],
"files": [
"grammar.js",
"binding.gyp",
Expand All @@ -47,4 +37,4 @@
"queries/*",
"src/**"
]
}
}
18 changes: 10 additions & 8 deletions plugin/init.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
vim.filetype.add({ extension = { nu = "nu" }, filename = { ["nurfile"] = "nu" } })

vim.api.nvim_create_autocmd("FileType", {
pattern = "nu",
callback = function(event) vim.bo[event.buf].commentstring = "# %s" end,
pattern = "nu",
callback = function(event)
vim.bo[event.buf].commentstring = "# %s"
end,
})

require("nvim-treesitter.parsers").get_parser_configs().nu = {
install_info = {
url = "https://github.com/nushell/tree-sitter-nu",
files = { "src/parser.c" },
branch = "main",
},
filetype = "nu",
install_info = {
url = "https://github.com/nushell/tree-sitter-nu",
files = { "src/parser.c", "src/scanner.c" },
branch = "main",
},
filetype = "nu",
}
4 changes: 4 additions & 0 deletions queries/nu/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ file_path: (val_string) @variable.parameter
(escaped_interpolated_content) @string
(expr_interpolated ["(" ")"] @variable.parameter)

(raw_string_begin) @string
mrdgo marked this conversation as resolved.
Show resolved Hide resolved
(raw_string_content) @string
(raw_string_end) @string

;;; ---
;;; operators
(expr_binary [
Expand Down
Loading
Loading