Array

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 Expression = compiler.Expression{
	Detect: func(c *compiler.Compiler) compiler.Type {

		if c.Token() == "#" {
			var collection = c.Shunt(c.Expression(), 5) //Custom operator precidence.

			if collection.Value().IsArray() {
				return c.Len(collection)
			} else {
				c.RaiseError(compiler.Translatable{
					compiler.English: "Cannot take the length of type " + collection.LanguageType().Name(),
				})
			}
		}

		if c.Token() == "array" {
			c.Expecting("(")

			if c.Peek() == "[" {
				c.Scan()

				var expression = c.ScanExpression()
				var elements []Type

				elements = append(elements, expression)

				for {
					if c.Peek() == "," {

						c.Scan()
						elements = append(elements, c.ScanType(elements[0]))

					} else {
						c.Expecting("]")
						c.Expecting(")")
						break
					}
				}

				return c.Array(elements...)
			}

			var length = c.ScanType(c.Int()).(Int)
			c.Expecting(")")

			return c.Int().Array(int(length.Literal().Int64()))
		}

		return nil
	},
}
View Source
var Shunt = func(c *compiler.Compiler, symbol string, a, b compiler.Type) compiler.Type {

	if a.Value().IsArray() && symbol == "[" {

		if !b.Value().Is(c.Int()) {
			c.RaiseError(errors.IndexError())
		} else {
			c.Expecting("]")

			return a.Value().Array().Index(b.Value().Int())
		}

	}

	return nil
}
View Source
var Statement = compiler.Statement{
	Detect: func(c *compiler.Compiler) bool {
		if c.GetVariable(c.Token()).Defined {

			var name = c.Token()
			var variable = c.Variable(name)

			if variable.Value().IsArray() && c.Peek() == "[" {
				c.Scan()

				var index = c.ScanType(c.Int()).(Int)
				c.Expecting("]")

				c.Expecting("=")

				variable.Value().Array().Modify(index, c.ScanType(variable.Value().Array().Subtype()))
				return true
			}

		}
		return false
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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