parser

package
v0.0.0-...-9a2eab4 Latest Latest
Warning

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

Go to latest
Published: May 1, 2022 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CommentRegexp = regexp.MustCompile(`(?m)^/([\w.-]+:[\w.-]+)(?:\s+([\w.-]+:[\w.-]+))*/(?:\s*\n)?([\s\S]*)$`)

Functions

func GetBnf

func GetBnf() string

func LexFile

func LexFile(path string) ([]lexer.Token, error)

func Lexer

func Lexer() *lexer.StatefulDefinition

func Parser

func Parser() *participle.Parser

Types

type Args

type Args struct {
	Statements Statements `parser:"'(' EOS* (@@ ((EOS|',')+ @@)*)? EOS* ')'" json:"Statements,omitempty"`

	Meta `json:"-"`
}

func (Args) AstNode

func (c Args) AstNode() ([]ast.Node, error)

type BlockImport

type BlockImport struct {
	Imports []Import `parser:"'import' '(' EOS* (@@ EOS)*  @@? EOS* ')'" json:"Imports,omitempty"`

	Meta `json:"-"`
}

func (BlockImport) AstNode

func (c BlockImport) AstNode() []ast.Node

type Bool

type Bool bool

func (*Bool) Capture

func (b *Bool) Capture(values []string) error

type Comment

type Comment struct {
	Tags ast.NodeList `parser:"(  '/' @(Ident:Ident) (' ' @(Ident:Ident))* '/' )?"  json:"Tags,omitempty"`
	Text string       `parser:"" json:"Text,omitempty"`

	Meta `json:"-"`
}

func (Comment) AstNode

func (c Comment) AstNode() *ast.Node

func (*Comment) Capture

func (c *Comment) Capture(values []string) error

type Const

type Const struct {
	String   *string   `parser:"@String" json:"String,omitempty"`
	Bool     *Bool     `parser:"| @Bool" json:"Bool,omitempty"`
	Rational *Rational `parser:"| @Rational" json:"Rational,omitempty"`

	Meta `json:"-"`
}

func (Const) AstType

func (c Const) AstType() (*ast.Type, error)

type File

type File struct {
	Name       string     `parser:"" json:"-"`
	Statements Statements `parser:"EOS* (@@ EOS+)*" json:"Statements,omitempty"`
}

func ParseFile

func ParseFile(path string) (*File, error)

func ParseString

func ParseString(path string, source string) (*File, error)

func (*File) FromYaml

func (f *File) FromYaml(source string) error

func (*File) ToYaml

func (f *File) ToYaml() (string, error)

type Ident

type Ident struct {
	Path string `parser:"@Ident" json:"Path,omitempty"`

	Meta `json:"-"`
}

type IdentWithArgs

type IdentWithArgs struct {
	Ident Ident `parser:"@@" json:"Type,omitempty"`
	Args  Args  `parser:"@@" json:"Args,omitempty"`

	Meta `json:"-"`
}

type IdentWithType

type IdentWithType struct {
	Ident Ident `parser:"@@" json:"Ident,omitempty"`
	Type  Type  `parser:"@@" json:"Type,omitempty"`

	Meta `json:"-"`
}

type Import

type Import struct {
	Name string `parser:"@Ident?" json:"Name,omitempty"`
	URL  string `parser:"@String" json:"URL,omitempty"`

	Meta `json:"-"`
}

func (Import) AstNode

func (c Import) AstNode() *ast.Node

type Meta

type Meta struct {
	Pos    lexer.Position `parser:"" json:"-"`
	EndPos lexer.Position `parser:"" json:"-"`
	Tokens []lexer.Token  `parser:"" json:"-"`
}

type Rational

type Rational struct {
	big.Rat
}

func (*Rational) Capture

func (r *Rational) Capture(values []string) error

func (*Rational) Equal

func (r *Rational) Equal(other *Rational) bool

type SingleImport

type SingleImport struct {
	Import Import `parser:"'import' @@ " json:"Import,omitempty"`

	Meta `json:"-"`
}

func (SingleImport) AstNode

func (c SingleImport) AstNode() *ast.Node

type Statement

type Statement struct {
	Comment      *Comment      `parser:"( @(LineComment | BlockComment+)"  json:"Comment,omitempty"`
	SingleImport *SingleImport `parser:"| @@" json:"SingleImport,omitempty"`
	BlockImport  *BlockImport  `parser:"| @@" json:"BlockImport,omitempty"`
	Type         *Type         `parser:") | (@@ " json:"Type,omitempty"`

	Default *Type `parser:"('=' @@)? )" json:"Default,omitempty"`

	Meta `json:"-"`
}

func (Statement) AstNode

func (c Statement) AstNode() ([]ast.Node, error)

type Statements

type Statements []Statement

func (Statements) AstNode

func (c Statements) AstNode() (ast.NodeList, error)

type Struct

type Struct struct {
	Statements Statements `parser:"'{' EOS* (@@ ((EOS|',')+ @@)*)? EOS* '}'" json:"Statements,omitempty"`

	Meta `json:"-"`
}

func (Struct) AstNode

func (c Struct) AstNode() ([]ast.Node, error)

type Type

type Type struct {
	Args *Args `parser:"@@?" json:"Args,omitempty"`

	IdentWithType *IdentWithType `parser:"(@@" json:"IdentWithType,omitempty"`
	IdentWithArgs *IdentWithArgs `parser:"| @@" json:"IdentWithArgs,omitempty"`
	Ident         *Ident         `parser:"| @@" json:"Ident,omitempty"`
	Const         *Const         `parser:"| @@" json:"Const,omitempty"`
	Struct        *Struct        `parser:"| @@)" json:"Struct,omitempty"`

	Meta `json:"-"`
}

func (Type) AstType

func (c Type) AstType() (*ast.Type, error)

Jump to

Keyboard shortcuts

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