parser

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: 4 Imported by: 1

Documentation

Overview

Package parser is a RiveScript language parser.

This package can be used as a stand-alone parser for third party developers to use, if you want to be able to simply parse (and syntax check!) RiveScript source code and get an "abstract syntax tree" back from it.

Index

Constants

View Source
const RS_VERSION float64 = 2.0

Variables

This section is empty.

Functions

This section is empty.

Types

type Parser

type Parser struct {
	C ParserConfig
}

func New

func New(config ParserConfig) *Parser

New creates and returns a new instance of a RiveScript Parser.

func (*Parser) Parse

func (self *Parser) Parse(filename string, code []string) (*ast.Root, error)

Parse reads and parses RiveScript source code.

This will return an AST Root object containing all of the relevant information parsed from the source code.

In case of errors (e.g. a syntax error while Strict Mode is enabled) will return a nil AST root and an error object.

Parameters

filename: An arbitrary name for the source code being parsed. It will be
	used when reporting warnings from this package.
code: An array of lines of RiveScript source code.

type ParserConfig

type ParserConfig struct {
	Strict bool // Strict syntax checking enable (true by default)
	UTF8   bool // Enable UTF-8 mode (false by default)

	// Optional handlers for the caller to get debug information out.
	OnDebug func(message string, a ...interface{})
	OnWarn  func(message, filename string, lineno int, a ...interface{})
}

ParserConfig configures the parser.

Configuration Options

Strict: Enable strict syntax checking. Syntax errors will be considered
	fatal and abandon the parsing process.
UTF8: Enable UTF-8 mode. When enabled, this allows triggers to contain
	foreign symbols without raising a syntax error.
OnDebug: A function handler for receiving debug information from this
	package, if you want that information.
OnWarn: A function handler for receiving warnings (non-fatal errors) from
	this package.

All options have meaningful zero values.

Jump to

Keyboard shortcuts

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