Skip to content

pstuifzand/tree-sitter-printf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tree-sitter-printf

Add to Neovim

Add this to your Neovim config.

lua << EOF
if pcall(require, "nvim-treesitter.parsers") then
  local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
  parser_config.printf = {
    install_info = {
      url = "https://github.com/pstuifzand/tree-sitter-printf",
      files = { "src/parser.c" },
    },
    filetype = "printf",
  }
end

EOF

Injections

~/.config/nvim/after/queries/go/injections.scm

Example of how to inject the printf grammar into the Go grammar.

(call_expression
    function:
        (selector_expression field: (field_identifier) @_method)
        (#match? @_method "^Sprintf|Printf|Fprintf|Fatalf$")
    arguments: (argument_list . (interpreted_string_literal) @printf)
)

~/.config/nvim/after/queries/printf/highlights.scm

Highlight the formats. This will highlight the format with one color.

(format) @printf

Author

Peter Stuifzand

About

Tree-sitter grammar for printf formats

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published