parser

package
v3.0.0-alpha.9 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 21 Imported by: 0

README

Parser

This package contains the static analyser used for parsing Wails projects so that we may:

  • Generate the bindings for the frontend
  • Generate Typescript definitions for the structs used by the bindings

Implemented

  • Bound types

    • Struct Literal Pointer
    • Variable
      • Assignment
        • Struct Literal Pointer
        • Function
          • Same package
          • Different package
    • Function
  • Parsing of bound methods

    • Method names
    • Method parameters
      • Zero parameters
      • Single input parameter
      • Single output parameter
      • Multiple input parameters
      • Multiple output parameters
      • Named output parameters
      • int/8/16/32/64
        • Pointer
      • uint/8/16/32/64
        • Pointer
      • float
        • Pointer
      • string
        • Pointer
      • bool
        • Pointer
      • Struct
        • Pointer
      • Slices
        • Pointer
      • Maps
        • Pointer
  • Model Parsing

    • In same package
    • In different package
    • Multiple named fields, e.g. one,two,three string
    • Scalars
    • Arrays
    • Maps
    • Structs
      • Recursive
      • Anonymous
  • Generation of models

    • Scalars
    • Arrays
    • Maps
    • Structs
  • Generation of bindings

    • Classes
    • Interfaces
    • Enums

Limitations

There are many ways to write a Go program so there are many program structures that we would need to support. This is a work in progress and will be improved over time. The current limitations are:

  • The call to application.New() must be in the main package
  • Bound structs must be declared as struct literals

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoBindingsFound = errors.New("no bound structs found")

ErrNoBindingsFound is returned when no bound structs are found

Functions

func CommentGroupToText

func CommentGroupToText(comments *ast.CommentGroup) []string

func GenerateConstants

func GenerateConstants(goData []byte) (string, error)

func TrimSlice

func TrimSlice(comments []string) []string

Types

type BoundMethod

type BoundMethod struct {
	Package    string
	PackageDir string
	Name       string
	DocComment string
	Inputs     []*Parameter
	Outputs    []*Parameter
	ID         uint32
	Alias      *uint32
}

func (BoundMethod) IDAsString

func (m BoundMethod) IDAsString() string

type ConstDef

type ConstDef struct {
	Name        string
	DocComments []string
	Value       string
}

type EnumDef

type EnumDef struct {
	Name        string
	Filename    string
	DocComments []string
	Values      []*EnumValue
}

type EnumValue

type EnumValue struct {
	Name        string
	Value       string
	DocComments []string
}

type ExternalStruct

type ExternalStruct struct {
	Package string
	Name    string
}

type Field

type Field struct {
	Name    string
	Type    *ParameterType
	Project *Project
}

func (*Field) DefaultValue

func (f *Field) DefaultValue() string

func (*Field) JSDef

func (f *Field) JSDef(pkg string) string

func (*Field) JSDocType

func (f *Field) JSDocType(pkg string) string

func (*Field) JSName

func (f *Field) JSName() string

func (*Field) TSBuild

func (f *Field) TSBuild(pkg string) string

TSBuild contains the typescript to build a field for a JS object via assignment for simple types or constructors for structs

type ImportDef

type ImportDef struct {
	Name        string
	Path        string
	VarName     string
	PackageName string
}

type Model

type Model struct {
	Package string
}

type ModelDefinitions

type ModelDefinitions struct {
	Package string
	Models  map[string]*StructDef
	Enums   map[string]*TypeDef
	Imports []*ImportDef
}

type Parameter

type Parameter struct {
	Name string
	Type *ParameterType
	// contains filtered or unexported fields
}

func (*Parameter) JSType

func (p *Parameter) JSType(pkgName string) string

func (*Parameter) NamespacedStructType

func (p *Parameter) NamespacedStructType(pkgName string) string

func (*Parameter) NamespacedStructVariable

func (p *Parameter) NamespacedStructVariable(pkgName string) string

type ParameterType

type ParameterType struct {
	Name      string
	IsStruct  bool
	IsSlice   bool
	IsPointer bool
	IsEnum    bool
	MapKey    *ParameterType
	MapValue  *ParameterType
	Package   string
}

type ParsedPackage

type ParsedPackage struct {
	Pkg         *ast.Package
	Name        string
	Path        string
	Dir         string
	StructCache map[structName]*StructDef
	TypeCache   map[string]*TypeDef
}

type Project

type Project struct {
	Path         string
	BoundMethods map[packagePath]map[structName][]*BoundMethod
	Models       map[packagePath]map[structName]*StructDef
	Types        map[packagePath]map[structName]*TypeDef

	Stats Stats
	// contains filtered or unexported fields
}

func GenerateBindingsAndModels

func GenerateBindingsAndModels(options *flags.GenerateBindingsOptions) (*Project, error)

func ParseProject

func ParseProject(projectPath string) (*Project, error)

func (*Project) GenerateBinding

func (p *Project) GenerateBinding(thisStructName string, method *BoundMethod, useIDs bool) (string, []string, map[packagePath]map[string]*ExternalStruct)

func (*Project) GenerateBindingTypescript

func (p *Project) GenerateBindingTypescript(thisStructName string, method *BoundMethod, useIDs bool) (string, []string, map[packagePath]map[string]*ExternalStruct)

func (*Project) GenerateBindings

func (p *Project) GenerateBindings(bindings map[string]map[string][]*BoundMethod, useIDs bool, useTypescript bool) map[string]map[string]string

func (*Project) GenerateModel

func (p *Project) GenerateModel(wr io.Writer, def *ModelDefinitions, options *flags.GenerateBindingsOptions) error

func (*Project) GenerateModels

func (p *Project) GenerateModels(models map[packagePath]map[structName]*StructDef, enums map[packagePath]map[string]*TypeDef, options *flags.GenerateBindingsOptions) (map[packagePath]string, error)

func (*Project) RelativeBindingsDir

func (p *Project) RelativeBindingsDir(dir *ParsedPackage, dir2 *ParsedPackage) string

func (*Project) RelativePackageDir

func (p *Project) RelativePackageDir(path string) string

type Stats

type Stats struct {
	NumPackages int
	NumStructs  int
	NumMethods  int
	NumEnums    int
	NumModels   int
	StartTime   time.Time
	EndTime     time.Time
}

type StructDef

type StructDef struct {
	Name        string
	DocComments []string
	Fields      []*Field
}

func (*StructDef) DefaultValueList

func (s *StructDef) DefaultValueList() string

type TypeDef

type TypeDef struct {
	Name           string
	DocComments    []string
	Type           string
	Consts         []*ConstDef
	ShouldGenerate bool
}

func (*TypeDef) GeneratedName

func (t *TypeDef) GeneratedName() string

Jump to

Keyboard shortcuts

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