-
Notifications
You must be signed in to change notification settings - Fork 1
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
Highligths and queries #2
Comments
Yeah, when I first started this I was just implementing what I was using. I know that a lot is still missing. :) The provided query files are not perfect. I was trying to mimic html tag highlighting. If you find something that you can improve, don't hesitate to open a pr :) |
I tried to look at blade and twig and maybe liquid. But sadly I didn't spot a liquid tree-sitter. It's interesting since the syntax is so similar. Edit: I guess there is a liquid one. But it's missing queries. Which is the interesting bit |
I chattede with ChatGPT because I wasn't close to a PC this week. This is just a minor note: module.exports = grammar({
name: 'smarty',
extras: $ => [/\s/],
rules: {
// Control Structures
if_statement: $ => seq(
'{if',
$.expression,
'}',
$.body,
optional($.else_clause),
'{/if}'
),
elseif_clause: $ => seq(
'{elseif',
$.expression,
'}'
),
else_clause: $ => '{else}',
// Assignments and Variable Usage
assignment: $ => seq(
'{assign',
$.variable,
$.expression,
'}'
),
variable: $ => /[a-zA-Z_][a-zA-Z0-9_]*/,
hash_marked_variable: $ => seq(
'{#',
choice('$', ''),
$.variable,
repeat(seq('.', $.variable)),
'#}'
),
variable_usage: $ => choice(
$.variable,
$.hash_marked_variable,
// Add other variations if needed
),
// Function Calls
function_call: $ => seq(
'{call',
$.function_name,
repeat($.function_argument),
'}'
),
function_argument: $ => choice(
$.variable,
$.string,
$.number
),
function_name: $ => /[a-zA-Z_][a-zA-Z0-9_]*/,
// Comments
comment: $ => seq(
'{*',
/[^*]*\*+([^/*][^*]*\*+)*/,
'*}'
),
// Includes and Extensions
include: $ => seq(
'{include',
$.file_path,
'}'
),
extends: $ => seq(
'{extends',
$.file_path,
'}'
),
// Loops
foreach_statement: $ => seq(
'{foreach',
$.variable,
'as',
$.key,
'=>',
$.value,
'}',
$.body,
'{/foreach}'
),
for_statement: $ => seq(
'{for',
$.init_expression,
$.condition,
$.loop_expression,
'}',
$.body,
'{/for}'
),
// File Path
file_path: $ => /"[^"]*"/,
// Expressions
expression: $ => /[^\n{}]+/,
body: $ => repeat(choice($.expression, $.if_statement, $.comment, $.function_call, $.include, $.extends, $.foreach_statement, $.for_statement)),
}
}); |
Hi I don't know if you are still using this. What is still missing:
So if you like you can test that out and let me know how you like the changes. |
I'm using it daily. Ill try out the dev branch during next week |
How did you add the smarty parser to nvim-treesitter? |
return {
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
event = { "LazyFile", "VeryLazy" },
config = function(_, opts)
if type(opts.ensure_installed) == "table" then
---@type table<string, boolean>
local added = {}
opts.ensure_installed = vim.tbl_filter(function(lang)
if added[lang] then
return false
end
added[lang] = true
return true
end, opts.ensure_installed)
end
require("nvim-treesitter.parsers").get_parser_configs().smarty = {
install_info = {
url = "https://github.com/Kibadda/tree-sitter-smarty",
files = { "src/parser.c" },
branch = "main",
},
filetype = "smarty", -- if filetype does not match the parser name
}
require("nvim-treesitter.parsers").get_parser_configs().sql = {
install_info = {
url = "https://github.com/DerekStride/tree-sitter-sql",
files = { "src/parser.c" },
branch = "main", -- default branch in case of git repo if different from master
generate_requires_npm = false, -- if stand-alone parser without npm dependencies
requires_generate_from_grammar = false, -- if folder contains pre-generated src/parser.c
},
filetype = "sql", -- if filetype does not match the parser name
}
require("nvim-treesitter.configs").setup(opts)
end,
opts = function(_, opts)
vim.list_extend(opts.ensure_installed, {
"smarty",
"sql",
"php",
"phpdoc",
"fish",
"scss",
"css",
"toml",
"git_config",
})
opts.highlight = {
enable = true,
additional_vim_regex_highlighting = false,
}
end,
} |
You need to update the parser config as shown in the README.md of the require("nvim-treesitter.parsers").get_parser_configs().smarty = {
install_info = {
url = "https://github.com/Kibadda/tree-sitter-smarty",
files = { "src/parser.c", "src/scanner.c" },
branch = "dev",
},
} |
Sorry, yes. I did that. I copied the wrong code since I reverted back to "master" to avoid getting spammed with errors while working. |
To clarify ... I used the correct branch and the new queries. But I was still experiencing the error. |
I'm still getting an error when using your snippet vs my own. Are there any kind of dependencies I need or I it setup with playground something of that kind. I've even tried resetting nvim completely by moving/ deleting cache and state. |
Honestly I have no idea why this does not compile. I just tried with a minimal reproduction on my computer and I could install this parser without any issues. |
The only dependencies you need, are the ones listed in the nvim-treesitter repository. |
I finally did more of a general system update. Updated tree-sitter (v0.21.0 now) and updated system build tools in general (Sonoma 14.3.1). That seemed to fix the build issue. With the default queries. I'm not certain the new one is better. I'll have to play more with custom queries or different color schemes. |
I can see why. Non builtin functions like {CheckoutPaymentMethods} are not supported. For reference this is how it looks with my colorscheme I tried to mimic the html highlights. |
Which if fair. Its a smarty component built with smarty plugins. But there are also smarty functions, that can be called with |
Hi, first of all thanks for the work on this! I'm getting errors with some of the queries from the queries folder. Are they all still valid for the dev branch or has treesitter query syntax changed in the meanwhile or what could be the problem? For example the in highlights the stuff marked as @tag doesn't seem to work for me / gives me errors. |
OK, so after playing around with treesitter and smarty I got highlights and injections working pretty well, but I can't get indents to work. Do they work for you two? If yes, then how? 😁 |
Sorry for the late response. Unfortunately they do not work for me either. To be honest I could not find out why. |
That's a pity. Does indenting work for you, @danjessen ? |
I took a different approach. I'm using https://github.com/shadowwa/smarty.vim |
I'm just adding this as a note. I haven't played with tree-sitter and tree-sitter queries yet. But I might see if I can find time to pitch in. I love the effort put in. But there is still some things to improve.
Remarks:
Built-in Functions - Essential
{assign}
{block}
,{/block}
{call}
{capture}
,{/capture}
{debug}
{extends}
{for}
,{forelse}
,{/for}
{foreach}
,{foreachelse}
,{/foreach}
{function}
,{/function}
{if}
,{elseif}
,{else}
,{/if}
{include}
{literal}
,{/literal}
{nocache}
,{/nocache}
{strip}
,{/strip}
{while}
,{/while}
Built-in Functions - Non-essentials
{insert}
{ldelim}
,{rdelim}
{section}
,{sectionelse}
,{/section}
{setfilter}
,{/setfilter}
Built-in Config Files (Non-essentials?)
{config_load}
{#hashmarks#}
*.conf
Built-in Basics
Custom Smarty Tags
{menu}
{script}
,{/script}
{date}
Injections (Self-maintained?)
The text was updated successfully, but these errors were encountered: