annotation

package module
v0.0.0-...-5850118 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

README

ast-annotation

In some scenarios, we may want the "annotation" feature, specially for code generation scenario.

So we come up with the general annotation solution, including:

  • how to define the annotation in your source code;
  • some enhancement API for Go AST SDK which allows users to read the annotation from source code.

Annotation Specification

An annotation must follow these two principles:

  • The annotation must be part of the document of the specific AST node
  • The annotation must follow one of these two patterns:
    • // @annotation_name annotation_value
    • /* @annotation_name annotation_value */

For example:

package main
type (
  // MyType is test type
  // @description my test type
  /* @multi_line first line
     second line
  */
  MyType struct {

  }
)

There are two annotations:

  • description => my test type
  • multi_line => first line \n second line

if you want to add annotation for type definitions, you cannot use the syntax "type A xxx"

Q & A

Why not fork the AST code and make the enhancement?

It's not worthy doing that.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Annotation

type Annotation struct {
	Key   string
	Value string
}

type Field

type Field struct {
	// contains filtered or unexported fields
}

type File

type File struct {
	Types []Type
	// contains filtered or unexported fields
}

type SingleFileEntryVisitor

type SingleFileEntryVisitor struct {
	// contains filtered or unexported fields
}

func (*SingleFileEntryVisitor) Get

func (s *SingleFileEntryVisitor) Get() File

func (*SingleFileEntryVisitor) Visit

func (s *SingleFileEntryVisitor) Visit(node ast.Node) ast.Visitor

type Type

type Type struct {
	Fields []Field
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL