golang AST matcher

goastch (GO AST matCH)

Introduction

Inspired by ast matcher. There are four different basic categories of matchers:

  • Node Matchers: Matchers that match a specific type of AST node.
  • Attributive Matchers: Matchers that match attributes on AST nodes.
  • Logical Matchers: Matchers that allow logic between matchers.
  • Traversal Matchers: Matchers that allow traversal between AST nodes.

Using as a lib

Find ‘ShortVarDecl’ from a file, and binding these to ‘bindID’.

package main

import (
	"fmt"
	"go/parser"
	"go/printer"
	"go/token"
	"log"
	"os"

	"github.com/helloyi/goastch"
	. "github.com/helloyi/goastch/goastcher"
)

func main() {
	g := HasDescendant(ShortVarDecl(Anything()).Bind("bindID"))

	src := `package foo
	func bar() {
    a := []int{}
    var b []int
    c := []string{}
	}`

	fset := token.NewFileSet()
	file, _ := parser.ParseFile(fset, "example", src, 0)
	bindings, err := goastch.Find(file, nil, g)
	if err != nil {
		log.Fatalln(err)
	}
	for key, list := range bindings {
		for _, node := range list {
			fmt.Printf("%s: ", key)
			_ = printer.Fprint(os.Stdout, fset, node)
			fmt.Println()
		}
	}
}
Similar Resources

Arbitrary expression evaluation for golang

govaluate Provides support for evaluating arbitrary C-like artithmetic/string expressions. Why can't you just write these expressions in code? Sometim

Jan 2, 2023

hotbuild - a cross platform hot compilation tool for golang

hotbuild - a cross platform hot compilation tool for golang

hotbuild A cross platform hot compilation tool By monitoring the modification of the project directory file, the recompilation and running are automat

Dec 12, 2022

The golang tool of the zig compiler automatically compiles different targets according to the GOOS GOARCH environment variable. You need to install zig.

The golang tool of the zig compiler automatically compiles different targets according to the GOOS GOARCH environment variable. You need to install zig.

Nov 18, 2022

Tgo - Test Helpers for Standard Golang Packages

Test Helpers for Standard Golang Packages see example_test.go go test --- FAIL:

Apr 26, 2022

Logexp - Logical expression compiler for golang

Logical Expression Compiler Functions: - Compile(exp string) - Match(text string

Jan 24, 2022

Runcmd - just golang binary that runs commands from url or local file and logs output

runcmd just golang binary that runs commands from url or local file and logs out

Feb 2, 2022

A compiler for the ReCT programming language written in Golang

ReCT-Go-Compiler A compiler for the ReCT programming language written in Golang

Nov 30, 2022

A GoLang fuzzy string matcher

fuzzy-matcher A fast golang fuzzy string matcher // New matcher creates a new matcher to be used for matching // Note that this operation takes the mo

Nov 30, 2021

A powerful HTTP router and URL matcher for building Go web servers with 🦍

gorilla/mux https://www.gorillatoolkit.org/pkg/mux Package gorilla/mux implements a request router and dispatcher for matching incoming requests to th

Jan 9, 2023

grobotstxt is a native Go port of Google's robots.txt parser and matcher library.

grobotstxt grobotstxt is a native Go port of Google's robots.txt parser and matcher C++ library. Direct function-for-function conversion/port Preserve

Dec 27, 2022

Golang AST visualizer

Golang AST visualizer

GoAst Viewer Golang AST visualizer. Demo GoAst Viewer Demo Usage You just need to run a http server and open your browser to index.html Installation T

Dec 29, 2022

Convert Go values to their AST

valast - convert Go values to their AST Valast converts Go values at runtime into their go/ast equivalent,

Dec 21, 2022

Transform Go code into it's AST

Welcome to go2ast 👋 Transform Go code into it's AST Usage echo "a := 1" | go run main.go Example output []ast.Stmt { &ast.AssignStmt {

Dec 13, 2022

go2cpp : convert go to cpp using go ast

px_golang2cpp convert go to cpp convert map to std::unordered_map convert array to vector convert 'var test bool' to 'bool test{}' convert 'var test =

Oct 30, 2022

A multi-pass compiler written in Go comprised of scanner, recursive-descent parser, generation of AST, intermediate representation (ILOC), and code generation (Armv8).

GoLite Project - Go Huskies! This is a project conducted and led in the course MPCS 51300 Compilers at the University of Chicago. In a group of two, w

Jan 10, 2022

Using NFP (Number Format Parser) you can get an Abstract Syntax Tree (AST) from Excel number format expression

NFP (Number Format Parser) Using NFP (Number Format Parser) you can get an Abstract Syntax Tree (AST) from Excel number format expression. Installatio

Feb 4, 2022

Generate Equal() methods from AST

Generate Equal() methods from AST

Nov 25, 2022

Interpreted Programming Language built in Go. Lexer, Parser, AST, VM.

Gago | Programming Language Built in Go if you are looking for the docs, go here Gago is a interpreted programming language. It is fully written in Go

May 6, 2022

[Crawler/Scraper for Golang]🕷A lightweight distributed friendly Golang crawler framework.一个轻量的分布式友好的 Golang 爬虫框架。

Goribot 一个分布式友好的轻量的 Golang 爬虫框架。 完整文档 | Document !! Warning !! Goribot 已经被迁移到 Gospider|github.com/zhshch2002/gospider。修复了一些调度问题并分离了网络请求部分到另一个仓库。此仓库会继续

Oct 29, 2022
go2cpp : convert go to cpp using go ast

px_golang2cpp convert go to cpp convert map to std::unordered_map convert array to vector convert 'var test bool' to 'bool test{}' convert 'var test =

Oct 30, 2022
Transpiling fortran code to golang code

f4go Example of use > # Install golang > # Compile f4go > go get -u github.com/Konstantin8105/f4go > cd $GOPATH/src/github.com/Konstantin8105/f4go > g

Sep 26, 2022
Golang->Haxe->CPP/CSharp/Java/JavaScript transpiler

TARDIS Go -> Haxe transpiler Haxe -> C++ / C# / Java / JavaScript Project status: a non-working curiosity, development currently on-ice The advent of

Dec 30, 2022
A JavaScript interpreter in Go (golang)

otto -- import "github.com/robertkrimen/otto" Package otto is a JavaScript parser and interpreter written natively in Go. http://godoc.org/github.com/

Jan 2, 2023
A BASIC interpreter written in golang.
A BASIC interpreter written in golang.

05 PRINT "Index" 10 PRINT "GOBASIC!" 20 PRINT "Limitations" Arrays Line Numbers IF Statement DATA / READ Statements Builtin Functions Types 30 PRINT "

Dec 24, 2022
PHP bindings for the Go programming language (Golang)

PHP bindings for Go This package implements support for executing PHP scripts, exporting Go variables for use in PHP contexts, attaching Go method rec

Jan 1, 2023
High-performance PHP-to-Golang IPC bridge

High-performance PHP-to-Golang IPC bridge Goridge is high performance PHP-to-Golang codec library which works over native PHP sockets and Golang net/r

Dec 28, 2022
High-performance PHP application server, load-balancer and process manager written in Golang
High-performance PHP application server, load-balancer and process manager written in Golang

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a serv

Dec 30, 2022
Expression evaluation in golang
Expression evaluation in golang

Gval Gval (Go eVALuate) provides support for evaluating arbitrary expressions, in particular Go-like expressions. Evaluate Gval can evaluate expressio

Dec 27, 2022
Scriptable interpreter written in golang
Scriptable interpreter written in golang

Anko Anko is a scriptable interpreter written in Go. (Picture licensed under CC BY-SA 3.0, photo by Ocdp) Usage Example - Embedded package main impor

Dec 23, 2022