All Projects → euclidianAce → ltreesitter

euclidianAce / ltreesitter

Licence: MIT license
Standalone tree sitter bindings for the Lua language

Programming Languages

c
50402 projects - #5 most used programming language
lua
6591 projects
Makefile
30231 projects

Projects that are alternatives of or similar to ltreesitter

tree-hugger
A light-weight, extendable, high level, universal code parser built on top of tree-sitter
Stars: ✭ 96 (+54.84%)
Mutual labels:  tree-sitter, parsing
SwiftTreeSitter
Swift wrappers for the tree-sitter incremental parsing system
Stars: ✭ 116 (+87.1%)
Mutual labels:  tree-sitter, parsing
Tree Sitter
An incremental parsing system for programming tools
Stars: ✭ 7,083 (+11324.19%)
Mutual labels:  tree-sitter, parsing
tree-sitter.el
An Emacs dynamic module exposing tree-sitter.
Stars: ✭ 59 (-4.84%)
Mutual labels:  tree-sitter
masci-tools
Tools, utility, parsers useful in daily material science work
Stars: ✭ 18 (-70.97%)
Mutual labels:  parsing
Fashion-Clothing-Parsing
FCN, U-Net models implementation in TensorFlow for fashion clothing parsing
Stars: ✭ 29 (-53.23%)
Mutual labels:  parsing
tree-sitter-lua
Lua grammar for tree-sitter.
Stars: ✭ 40 (-35.48%)
Mutual labels:  tree-sitter
postcss-jsx
PostCSS syntax for parsing CSS in JS literals
Stars: ✭ 73 (+17.74%)
Mutual labels:  parsing
DrawRacket4Me
DrawRacket4Me draws trees and graphs from your code, making it easier to check if the structure is what you wanted.
Stars: ✭ 43 (-30.65%)
Mutual labels:  parsing
ghakuf
A Rust library for parsing/building SMF (Standard MIDI File).
Stars: ✭ 30 (-51.61%)
Mutual labels:  parsing
Syntax
Write value-driven parsers quickly in Swift with an intuitive SwiftUI-like DSL
Stars: ✭ 134 (+116.13%)
Mutual labels:  parsing
haskell-tree-sitter
Haskell bindings for tree-sitter
Stars: ✭ 123 (+98.39%)
Mutual labels:  tree-sitter
BibleUtilities
Set of utilities to scan, parse, and work with Bible references.
Stars: ✭ 20 (-67.74%)
Mutual labels:  parsing
tree-sitter-rust
Rust grammar for tree-sitter
Stars: ✭ 199 (+220.97%)
Mutual labels:  tree-sitter
reason-tree-sitter
ReasonML bindings for tree-sitter
Stars: ✭ 22 (-64.52%)
Mutual labels:  tree-sitter
yellowpages-scraper
Yellowpages.com Web Scraper written in Python and LXML to extract business details available based on a particular category and location.
Stars: ✭ 56 (-9.68%)
Mutual labels:  parsing
MathExpressions.NET
➗ Library for parsing math expressions with rational numbers, finding their derivatives and compiling an optimal IL code
Stars: ✭ 63 (+1.61%)
Mutual labels:  parsing
swift-tree-sitter
Swift bindings for the tree-sitter parsing library
Stars: ✭ 29 (-53.23%)
Mutual labels:  tree-sitter
NFlags
Simple yet powerfull library to made parsing CLI arguments easy. Library also allow to print usage help "out of box".
Stars: ✭ 44 (-29.03%)
Mutual labels:  parsing
quick-csv-streamer
Quick CSV Parser with Java 8 Streams API
Stars: ✭ 29 (-53.23%)
Mutual labels:  parsing

ltreesitter

test

Tree sitter bindings for Lua

Documentation

Documentation can be found at this repo's github pages (Which are autogenerated using the Teal script scripts/gen.tl)

Installation

ltreesitter is avaliable on luarocks

luarocks install ltreesitter

or the latest main branch

luarocks install --dev ltreesitter

Examples

Looking for a quick start? These snippets should be descriptive enough to get you started. If you need more detail, take a look at the documentation

Setup

Loading parsers you have installed on your system

local ltreesitter = require("ltreesitter")

ltreesitter.require

Assuming you have a compiled c parser named c.so (or c.dll on windows) in ~/.tree-sitter/bin/ or package.cpath

local c_parser = ltreesitter.require("c")

You have a parser.so (or .dll) with the symbol tree_sitter_lua to load the language

local lua_parser = ltreesitter.require("parser", "lua")

ltreesitter.load

load will just directly load from the filename given.

local local_c_parser = ltreesitter.load("./c-parser.so", "c")

Using a path without a path separator may have unintended consequences, so when in doubt, include a leading ./ or use an absolute path.

For more information, look into how dlopen and LoadLibrary find paths.

Basic parsing and usage of trees and nodes

local source_code = [[
#include <stdio.h>

// a function that does stuff
static void stuff_doer(void) {
    printf("I'm doing stuff! :D\n");
}

int main(int argc, char **argv) {
    stuff_doer();
    return 0;
}
]]

local tree = c_parser:parse_string(source_code)
print(tree) -- tostring (which print calls automatically) will return the string of s-expressions of trees and nodes

for child in tree:root():named_children() do -- some iterators over nodes' children are provided
   print(child)
end

Queries

Using the above c_parser and tree

-- Grab the names of all functions
local my_query = c_parser:query[[
    (translation_unit
      (function_definition
        declarator: (function_declarator
                      declarator: (identifier) @name))) ]]

for capture, capture_name in my_query:capture(tree:root()) do -- iterate over captured nodes without caring about order
   -- Node:source() gives the source code that the node comes from
   print(capture:source(), capture_name) -- => "stuff_doer", "name" and "main", "name"
end

for match in my_query:match(tree:root()) do
   print(match.captures["name"]:source()) -- => "stuff_doer" and "main"
end
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].