Concept

package
v0.0.0-...-1802cdc Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2020 License: Artistic-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Concepts = make(map[string]Concept)
View Source
var Expression = compiler.Expression{
	Detect: func(c *compiler.Compiler) compiler.Type {
		var Name = c.Token()

		if concept, ok := Concepts[Name]; ok {

			if c.Peek() == "(" {
				return CreateAndCall(c, Name, concept)
			} else {
				return Create(c, Name, concept, nil)
			}
		}
		return nil
	},
}
View Source
var Functions = make(map[string]Func)
View Source
var Name = compiler.Translatable{
	compiler.English: "concept",
}
View Source
var Return = compiler.Statement{
	Name: compiler.Translatable{
		compiler.English: "return",
	},

	OnScan: func(c *compiler.Compiler) {
		c.Return(c.ScanExpression())
	},
}
View Source
var Statement = compiler.Statement{
	Name: Name,

	OnScan: func(c *compiler.Compiler) {

		var Name = c.Scan()
		c.Expecting("(")

		var Arguments []string
		for c.Peek() != ")" {
			Arguments = append(Arguments, c.Scan())

			if c.Peek() != ")" {
				c.Expecting(",")
			}
		}
		c.Expecting(")")

		var cache compiler.Cache
		if c.ScanIf(":") {
			cache = c.NewCache("", "\n")
		} else {
			cache = c.NewCache("", "}")
		}

		Concepts[Name] = Concept{
			Arguments: Arguments,
			Cache:     cache,
		}
	},

	Detect: func(c *compiler.Compiler) bool {

		var Name = c.Token()

		if function := c.GetVariable(Name); function.Defined && function.Value().IsFunc() {

			if len(function.Value().Func().Arguments()) == 0 {
				c.Expecting("(")
				c.Expecting(")")

				function.Value().Func().Run()
				return true
			}

			c.Unimplemented()

		}

		if concept, ok := Concepts[Name]; ok {
			CreateAndCall(c, Name, concept)
			return true
		}
		return false
	},
}

Functions

func Create

func Create(c *compiler.Compiler, Name string, concept Concept, args func(*compiler.Compiler)) Func

func CreateAndCall

func CreateAndCall(c *compiler.Compiler, Name string, concept Concept) compiler.Type

Types

type Concept

type Concept struct {
	Arguments []string
	Cache     compiler.Cache
}

TODO merge this into Compiler

Jump to

Keyboard shortcuts

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