parser

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package parser implements a participle parser for the TSCN file format

Index

Constants

View Source
const (
	ResourceTypeExtResource = "ext_resource"
	ResourceTypeSubResource = "sub_resource"
	ResourceTypeEditable    = "editable"
	ResourceTypeConnection  = "connection"
	ResourceTypeNode        = "node"
	ResourceTypeResource    = "resource"
)

Supported resource types

Variables

This section is empty.

Functions

This section is empty.

Types

type GdField

type GdField struct {
	Key   string   `parser:"@Ident '='"`
	Value *GdValue `parser:" @@"`
	Pos   lexer.Position
}

GdField represents a field with a value

type GdMapField

type GdMapField struct {
	Key   string   `parser:"@String ':'"`
	Value *GdValue `parser:" @@"`
	Pos   lexer.Position
}

GdMapField represents a field with a value within a map

func (*GdMapField) ToString

func (kv *GdMapField) ToString() string

ToString returns a string representation of a GdMapField

type GdResource

type GdResource struct {
	ResourceType string     `parser:"'[' @Ident "`
	Attributes   []*GdField `parser:"@@* ']'"`
	Fields       []*GdField `parser:"@@*"`
	Pos          lexer.Position
}

GdResource represents a resource within a TSCN file

func (*GdResource) GetAttribute

func (res *GdResource) GetAttribute(name string) (*GdValue, error)

GetAttribute finds an attribute by name, returns error if not found

func (*GdResource) GetField

func (res *GdResource) GetField(name string) (*GdValue, error)

GetField finds an attribute by name, returns error if not found

type GdType

type GdType struct {
	Key        string     `parser:" @Ident ('('"`
	Parameters []*GdValue `parser:"(@@ ( ',' @@ )* )? ')')?"`
	Pos        lexer.Position
}

GdType represents a type with values

type GdValue

type GdValue struct {
	IsEmptyMap   *bool         `parser:" (@'{' '}')"`
	Map          []*GdMapField `parser:"| '{' ( @@ ( ',' @@ )* )? '}'"`
	KeyValuePair *GdMapField   `parser:"| @@"`
	IsEmptyArray *bool         `parser:"| (@'[' ']')"`
	Array        []*GdValue    `parser:"| '[' ( @@ ( ',' @@ )* )? (',')? ']'"`
	String       *string       `parser:"| @String"`
	Integer      *int64        `parser:"| @Int"`
	Float        *float64      `parser:"| @Float"`
	Bool         *bool         `parser:"| (@'true' | 'false')"`
	Null         *bool         `parser:"| (@'null')"`
	Type         *GdType       `parser:"| @@"`
	Pos          lexer.Position
}

GdValue represents a value

func (*GdValue) Raw

func (v *GdValue) Raw() interface{}

Raw returns an interface{} which contains the actual value of the associated GdValue

func (*GdValue) ToString

func (v *GdValue) ToString() string

ToString returns a string representation of the associated GdValue

type TscnFile

type TscnFile struct {
	Key        string        `parser:"('[' @Ident"`
	Attributes []*GdField    `parser:"@@* ']')?"`
	Fields     []*GdField    `parser:"@@*"`
	Sections   []*GdResource `parser:"@@*"`
	Pos        lexer.Position
}

TscnFile represents a .tscn file

func Parse

func Parse(r io.Reader) (*TscnFile, error)

Parse content and return a simple representation of the file format.

func (*TscnFile) GetAttribute

func (tscn *TscnFile) GetAttribute(name string) (*GdValue, error)

GetAttribute finds an attribute by name, returns error if not found

Jump to

Keyboard shortcuts

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