Comments (17)
in general, you can use injections to defer to a different grammar, by putting this into $VIMCONFIG/queries/haskell/injections.scm
:
(string) @grammar-with-escape-highlights
And I can look into parsing strings directly in the grammar.
from tree-sitter-haskell.
so, the other grammar would need to be specifically parsing only the string
from tree-sitter-haskell.
Got it working after I realized you didn't mean to literally add @grammar-with-escape-highlights
, LOL. Thank you!!
from tree-sitter-haskell.
oh really, which grammar did you use?
from tree-sitter-haskell.
I just tried a couple at random and went with Rust because it picked up \" and \n without giving me problems in the project I'm working on
from tree-sitter-haskell.
oh heh. you could create a minimal grammar that only parses strings tho
from tree-sitter-haskell.
I'm not really familiar with treesitter internals (or parsing in general really) to know how to go about that.. would reading https://tree-sitter.github.io/tree-sitter/creating-parsers get me started, or is there other documentation you would also recommend?
from tree-sitter-haskell.
I did a similar thing for quasiquotes here: https://github.com/tek/vim-bundle-conf/tree/master/tree-sitter/exon
it's bare bones, you'll just have to modify grammar.js
, it should be fairly intuitive, using that page you linked.
then you'll have to add it in you vim config in a plugin/foo.vim
:
lua <<EOF
local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.string_grammar_name = {
install_info = {
url = "/path/to/string/grammar/",
files = {"src/parser.c"}
}
}
EOF
and you can refer to it in an injection with @string_grammar_name
after :TSInstall string_grammar_name
from tree-sitter-haskell.
Thank you, that example was very helpful. I ended up giving it a shot. I set up a minimal grammar named "porcupine" which only parses strings into two nodes, "string_fragment" or "escape_sequence". I inject it into haskell with (string) @porcupine
in injections.scm
, it installs successfully with :TSInstall porcupine
and is applied in the right places when I look at a source file with TSPlayground:
However I can't seem to get the capture groups set up for them. In the minimal grammar, I have a queries/highlights.scm containing:
(string_fragment) @string
(escape_sequence) @escape
and a corresponding "escape" custom capture group set up in my vim config.
But those don't seem to get picked up:
I'm sure I'm missing something on how capture groups work, so I'll try to figure it out, but let me know if anything obvious jumps out that I'm missing.
from tree-sitter-haskell.
by "in the minimal grammar", do you mean that the highlights file is in the porcupine/queries
directory? because that won't get picked up by nvim I think.
from tree-sitter-haskell.
Yeah, I had tried adding those highlights in the haskell queries directory in the fork of nvim-treesitter that my config is hooked up to and treesitter exploded with an error referencing an "invalid node". If I included a porcupine
highlight group it got picked up, though. Anyways I should probably find time to figure out how tree-sitter actually works before trying to hack something together :^) my attempt is here
from tree-sitter-haskell.
well, for nvim, you have to put all the queries and injections into the nvim config. so either your nvim-treesitter fork or your local ~/.config/nvim
.
and the injection has to be in queries/haskell/injections.scm
, while the highlighting for porcupine has to be in queries/porcupine/highlights.scm
.
from tree-sitter-haskell.
@jpe90 can this be closed?
from tree-sitter-haskell.
Sure, thanks for trying to help.
from tree-sitter-haskell.
@jpe90 oh, were you no able to implement your goal?
from tree-sitter-haskell.
No, I got stuck getting highlights/injections recognized and felt a little out of my depth. I wanted to make more of an effort to understand how they work before I kept bugging for help. I'll give it another shot when I'm feeling brave :^)
from tree-sitter-haskell.
gotcha, feel free to continue here when you need more input!
from tree-sitter-haskell.
Related Issues (20)
- Combining characters in identifiers are not parsed correctly HOT 1
- Include . from qualified modules and variables HOT 6
- Segfault on large files (in Neovim) HOT 1
- How do I build this outside of nvim-tree-sitter? HOT 16
- WASM build fails with error HOT 6
- Native and WASM parsers behave differently HOT 11
- How do I generate a valid WASM file HOT 9
- Grammar defines trailing whitespace as part of lambda case statement HOT 4
- Parse errors when using DerivingVia HOT 4
- infixr and infixl not respected HOT 4
- Crashing (possibly while editing markdown) HOT 7
- Comments following function included in function pattern HOT 6
- Update to latest tree-sitter version
- Outermost function when using $ operator isn't parsed as a function HOT 8
- Instance with associated type, following TH top level splice, misparsed as function HOT 2
- Misparse of explicit-braced code
- UnicodeSyntax support HOT 10
- "undefined symbol: tree_sitter_haskell_external_scanner_create" when running "tree-sitter test" HOT 7
- Support `OverloadedRecordDot` HOT 8
- I added three more symbols for built-in syntax.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tree-sitter-haskell.