parser

package
v3.0.0-...-c98e9ca Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2023 License: MIT Imports: 17 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

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

This section is empty.

Functions

func GenerateBinding

func GenerateBinding(structName string, method *BoundMethod) (string, []string)

func GenerateBindings

func GenerateBindings(bindings map[string]map[string][]*BoundMethod) map[string]string

func GenerateBindingsAndModels

func GenerateBindingsAndModels(projectDir string, outputDir string) error

func GenerateHelper

func GenerateHelper(packageName, structName string) string

func GenerateModel

func GenerateModel(wr io.Writer, def *ModelDefinitions) error

func GenerateModels

func GenerateModels(models map[packagePath]map[structName]*StructDef) (string, error)

Types

type BoundMethod

type BoundMethod struct {
	Name       string
	DocComment string
	Inputs     []*Parameter
	Outputs    []*Parameter
}

type Field

type Field struct {
	Name string
	Type *ParameterType
}

func (*Field) JSDef

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

func (*Field) JSName

func (f *Field) JSName() string

type ModelDefinitions

type ModelDefinitions struct {
	Package string
	Models  map[string]*StructDef
}

type Parameter

type Parameter struct {
	Name string
	Type *ParameterType
}

func (*Parameter) JSType

func (p *Parameter) JSType() string

type ParameterType

type ParameterType struct {
	Name      string
	IsStruct  bool
	IsSlice   bool
	IsPointer 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
}

type Project

type Project struct {
	Path         string
	BoundMethods map[packagePath]map[structName][]*BoundMethod
	Models       map[packagePath]map[structName]*StructDef
	// contains filtered or unexported fields
}

func ParseProject

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

type StructDef

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

Jump to

Keyboard shortcuts

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