parser

package module
v0.0.1-alpha1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2021 License: BSD-3-Clause Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RemoveComments

func RemoveComments(raw string) string

Types

type AccessibilityModifier

type AccessibilityModifier int
const (
	AccessModPublic AccessibilityModifier = iota
	AccessModPrivate
	AccessModOperator
)

func (*AccessibilityModifier) Capture

func (a *AccessibilityModifier) Capture(values []string) error

type ArrayLiteral

type ArrayLiteral struct {
	Type     *TypeName     `"new" "[""]" @@`
	Contents []*Expression `"{" ((@@ ",")* @@)? "}"`
}

type Assignment

type Assignment struct {
	Target        *ObjectName `@@ "="`
	ValueToAssign *Expression `@@`
}

type Bit

type Bit bool

func (*Bit) Capture

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

type Class

type Class struct {
	Name    string         `"class" @Ident`
	Members []*ClassMember `"{" (@@ ";")* "}"`
}

type ClassMember

type ClassMember struct {
	Accessibility *AccessibilityModifier `@("public" | "private" | "operator")`
	Name          string                 `@Ident`
	Parameters    []*Parameter           `("(" (@@ ","?)* ")")?`
	Type          *TypeName              `@@`
	MethodBody    []*Statement           `("{" @@* "}")?`
}

type Construction

type Construction struct {
	Type   *TypeName     `"new" @@`
	Params []*Expression `"(" (@@ ",")* @@ ")"`
}

type Enum

type Enum struct {
	Name    string   `"enum" @Ident`
	Options []string `"{" ((@Ident ";")* @Ident)? "}"`
}

type Expression

type Expression struct {
	Parts []*ExpressionPart `@@+`
}

type ExpressionPart

type ExpressionPart struct {
	Null         bool          `@"null"`
	Literal      *Literal      `|@@`
	Call         *MethodCall   `|@@`
	Construction *Construction `|@@`
	Parenthesis  *Expression   `|"(" @@ ")"`
	Operator     *Operator     `` /* 126-byte string literal not displayed */
	ObjAccess    *ObjectName   `|@@`
}

type ForEachLoop

type ForEachLoop struct {
	VarName    string       `"foreach" "(" "var" @Ident`
	VarType    *TypeName    `@@`
	IndexName  string       `"index" @Ident`
	Collection *Expression  `"in" @@ ")"`
	Body       []*Statement `"{" @@* "}"`
}

type ForLoop

type ForLoop struct {
	VarCreation *Statement   `"for" "(" @@ ";"`
	Condition   *Expression  `@@ ";"`
	Increment   *Statement   `@@ ")"`
	Body        []*Statement `"{" @@* "}"`
}

type IfStatement

type IfStatement struct {
	Condition *Expression  `"if" "(" @@ ")"`
	Body      []*Statement `"{" @@* "}"`
}

type Literal

type Literal struct {
	Array  *ArrayLiteral `@@`
	Bit    *Bit          `|@("1" | "0" | "true" | "false")`
	Float  float64       `|@Float`
	Int    int           `|@Int`
	Char   *string       `|@Char`
	String *string       `|@String`
}

type LocalVarDefinition

type LocalVarDefinition struct {
	Name          string      `"var" @Ident`
	Type          *TypeName   `@@`
	ValueToAssign *Expression `("=" @@)?`
}

type MethodCall

type MethodCall struct {
	Name   *ObjectName   `@@`
	Params []*Expression `"(" (@@ ",")* @@ ")"`
}

type Namespace

type Namespace struct {
	NamespaceParts []string `(@Ident ":")* @Ident`
}

type NamespaceDeclaration

type NamespaceDeclaration struct {
	Name    *Namespace         `"namespace" @@`
	Members []*NamespaceMember `("{" @@* "}"`
	Class   *Class             `|@@`
	Enum    *Enum              `|@@)`
}

type NamespaceMember

type NamespaceMember struct {
	Class *Class `@@`
	Enum  *Enum  `|@@`
}

type ObjectName

type ObjectName struct {
	Type *TypeName `(@@ ".")?`
	Name string    `@Ident`
}

type Operator

type Operator int
const (
	OpAdd Operator = iota
	OpSub
	OpMul
	OpDiv
	OpIntDiv
	OpMod
	OpEq
	OpNeq
	OpGt
	OpLt
	OpGtEq
	OpLtEq
	OpNot
	OpAnd
	OpScAnd
	OpOr
	OpScOr
	OpXor
	OpBinEq
)

func (*Operator) Capture

func (a *Operator) Capture(values []string) error

type Parameter

type Parameter struct {
	Name string    `@Ident`
	Type *TypeName `@@`
}

type Statement

type Statement struct {
	Return     *Expression         `"return" @@ ";"`
	VarDef     *LocalVarDefinition `|@@ ";"`
	Assignment *Assignment         `|@@ ";"`
	Method     *MethodCall         `|@@ ";"`
	If         *IfStatement        `|@@ ";"`
	For        *ForLoop            `|@@ ";"`
	ForEach    *ForEachLoop        `|@@ ";"`
	While      *WhileLoop          `|@@ ";"`
}

type TypeName

type TypeName struct {
	IsVoid    bool       `@"void"`
	Nullable  bool       `|(@"?"?`
	Array     bool       `@("[""]")?`
	Namespace *Namespace `(@@ ".")?`
	Name      string     `@Ident)`
}

type Up

type Up struct {
	WithDeclarations      []*WithDeclaration      `@@*`
	NamespaceDeclarations []*NamespaceDeclaration `@@*`
}

func Parse

func Parse(rawCode string) (*Up, error)

func ParseFromFile

func ParseFromFile(filePath string) (*Up, error)

type WhileLoop

type WhileLoop struct {
	Condition *Expression  `"while" "(" @@ ")"`
	Body      []*Statement `"{" @@* "}"`
}

type WithDeclaration

type WithDeclaration struct {
	Namespace *Namespace `"with" @@ ";"`
}

Jump to

Keyboard shortcuts

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