ast

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 0 Imported by: 1

Documentation

Overview

Package ast defines the Abstract Syntax Tree for RiveScript.

The tree looks like this (in JSON-style syntax):

{
	"Begin": {
		"Global": {}, // Global vars
		"Var": {},    // Bot variables
		"Sub": {},    // Substitution map
		"Person": {}, // Person substitution map
		"Array": {},  // Arrays
	},
	"Topics": {},
	"Objects": [],
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Begin

type Begin struct {
	Global map[string]string   `json:"global"`
	Var    map[string]string   `json:"var"`
	Sub    map[string]string   `json:"sub"`
	Person map[string]string   `json:"person"`
	Array  map[string][]string `json:"array"` // Map of string (names) to arrays-of-strings
}

Begin represents the "begin block" style data (configuration).

type Object

type Object struct {
	Name     string   `json:"name"`
	Language string   `json:"language"`
	Code     []string `json:"code"`
}

Object contains source code of dynamically parsed object macros.

type Root

type Root struct {
	Begin   Begin             `json:"begin"`
	Topics  map[string]*Topic `json:"topics"`
	Objects []*Object         `json:"objects"`
}

Root represents the root of the AST tree.

func New

func New() *Root

New creates a new, empty, abstract syntax tree.

func (*Root) AddTopic

func (ast *Root) AddTopic(name string)

AddTopic sets up the AST tree for a new topic and gets it ready for triggers to be added.

type Topic

type Topic struct {
	Triggers []*Trigger      `json:"triggers"`
	Includes map[string]bool `json:"includes"`
	Inherits map[string]bool `json:"inherits"`
}

Topic represents a topic of conversation.

type Trigger

type Trigger struct {
	Trigger   string   `json:"trigger"`
	Reply     []string `json:"reply"`
	Condition []string `json:"condition"`
	Redirect  string   `json:"redirect"`
	Previous  string   `json:"previous"`
}

Trigger has a trigger pattern and all the subsequent handlers for it.

Jump to

Keyboard shortcuts

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