parser

package
v0.4.15 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

compile and execute GSC requests

Index

Constants

View Source
const (

	// Colors
	ColRED     = csi + "31m"
	ColGREEN   = csi + "32m"
	ColYELLOW  = csi + "33m"
	ColBLUE    = csi + "34m"
	ColMAGENTA = csi + "35m"
	ColCYAN    = csi + "36m"

	// Graphics parameters
	Bold      = csi + "1m"
	Italic    = csi + "3m"
	Underline = csi + "4m"
	Blink     = csi + "5m"
	Reverse   = csi + "7m"
	Strike    = csi + "9m"
	Dim       = csi + "2m"

	// Cursor save/restore
	CursorSave    = csi + "s"
	CursorRestore = csi + "u"

	// Clear creen
	ClearScreen             = csi + "2J"
	ClearScreenFromCursor   = csi + "0J"
	ClearScreenBeforeCursor = csi + "1J"

	// Clear line
	ClearLine             = csi + "2K"
	ClearLineFromCursor   = csi + "0K"
	ClearLineBeforeCursor = csi + "1K"

	// Reset all settings
	AnsiRESET = csi + "0m"
)
View Source
const ABS = 57384
View Source
const AND = 57386
View Source
const AS = 57363
View Source
const ASSERT = 57418
View Source
const ASSIGN = 57350
View Source
const AT = 57409
View Source
const ATTR = 57406
View Source
const BLUE = 57433
View Source
const BOOL = 57346
View Source
const CLICK = 57352
View Source
const CLOSE = 57402
View Source
const COLON = 57404
View Source
const COMMA = 57360
View Source
const CONTAINS = 57396
View Source
const CYAN = 57434
View Source
const DISTINCT = 57408
View Source
const DIV = 57382
View Source
const DOLLAR = 57427
View Source
const DOT = 57375
View Source
const DOTDOT = 57410
View Source
const ELSE = 57417
View Source
const EQ = 57390
View Source
const FAIL = 57419
View Source
const FILE_SEPARATOR = 57414
View Source
const FIND = 57397
View Source
const FOR = 57361
View Source
const FORMAT = 57421
View Source
const FROM = 57364
View Source
const GO = 57423
View Source
const GREEN = 57431
View Source
const GSC = 57425
View Source
const GT = 57394
View Source
const GTE = 57395
View Source
const IDENTIFIER = 57349
View Source
const IF = 57415
View Source
const IN = 57354
View Source
const INPUT = 57353
View Source
const JOIN = 57400
View Source
const JSON = 57424
View Source
const LAST = 57429
View Source
const LBRACE = 57373
View Source
const LBRACKET = 57371
View Source
const LEFT = 57356
View Source
const LEN = 57376
View Source
const LIMIT = 57368
View Source
const LPAREN = 57369
View Source
const LT = 57392
View Source
const LTE = 57393
View Source
const MAGENTA = 57435
View Source
const MIDDLE = 57358
View Source
const MINUS = 57378
View Source
const MINUSMINUS = 57380
View Source
const MOD = 57383
View Source
const MULTI = 57381
View Source
const NAND = 57389
View Source
const NEQ = 57391
View Source
const NIL = 57428
View Source
const NL = 57426
View Source
const NORMAL = 57436
View Source
const NOT = 57385
View Source
const NOW = 57412
View Source
const NUMBER = 57347
View Source
const OF = 57407
View Source
const OR = 57387
View Source
const PAGE = 57401
View Source
const PAGES = 57403
View Source
const PATH = 57398
View Source
const PLUS = 57377
View Source
const PLUSPLUS = 57379
View Source
const PRINT = 57420
View Source
const QUESTION = 57411
View Source
const RANGE = 57438
View Source
const RAW = 57422
View Source
const RBRACE = 57374
View Source
const RBRACKET = 57372
View Source
const RED = 57430
View Source
const RETURN = 57359
View Source
const RIGHT = 57357
View Source
const RPAREN = 57370
View Source
const SELECT = 57362
View Source
const SEMICOLON = 57351
View Source
const SLOW = 57355
View Source
const STEP = 57366
View Source
const STRING = 57348
View Source
const TEXT = 57405
View Source
const THEN = 57416
View Source
const TO = 57365
View Source
const VERSION = 57413
View Source
const WHERE = 57367
View Source
const WITH = 57399
View Source
const XOR = 57388
View Source
const XPATH = 57437
View Source
const YELLOW = 57432

Variables

This section is empty.

Functions

func CompareAny added in v0.4.9

func CompareAny(v1, v2 any) (int, error)

CompareAny takes two interface{} values and tries to compare them. It returns -1 if v1 < v2, 0 if v1 == v2, and 1 if v1 > v2. If the types are different or not comparable, it returns an error.

func Eval added in v0.4.9

func Eval(name string, content string) (result any, err error)

Compile a request, create a defalt interpreter, and evaluate the request.

func EvalFile added in v0.4.9

func EvalFile(fname string) (result any, err error)

Same a Eval, but read request from fileName.

func EvalFileWithParams added in v0.4.9

func EvalFileWithParams(fname string, params map[string]any) (result any, err error)

Eval from file with parameter map

func EvalWithParams added in v0.4.9

func EvalWithParams(name string, content string, params map[string]any) (result any, err error)

Same a Eval, but with parameters map

func GetParamsList added in v0.4.14

func GetParamsList(compiledRequest Node) []string

Extracts the (sorted) list of parameters a compiled requests expects.

func ParseLitteral added in v0.4.9

func ParseLitteral(content string) (any, error)

ParseLitteral parse a gsc litteral with a small subset of the gsc syntax. Only accepts nil, bool, ints, strings, [] and {}.

func TokenAsString

func TokenAsString(t int) string

Prints a token defined by its constant value as a string.

Types

type Interpreter added in v0.4.9

type Interpreter struct {
	// contains filtered or unexported fields
}

Interpreter maintains context for running a compiled request.

func NewInterpreter added in v0.4.9

func NewInterpreter(ctx context.Context) *Interpreter

Start a new interpreter in default setting.

func (*Interpreter) DumpVars added in v0.4.9

func (it *Interpreter) DumpVars(w io.Writer, title string)

Write all known variables to the given writer, including input parameters. Sorted for test stability.

func (*Interpreter) Eval added in v0.4.9

func (it *Interpreter) Eval(node Node) (any, error)

Evaluate a compiled request.

func (*Interpreter) SetAsyncMode added in v0.4.9

func (it *Interpreter) SetAsyncMode(ch chan<- any) *Interpreter

Set asynchroneous mode. Results will be sent to channel for each loop. If channel is nil, sets to synchroneous mode.

func (*Interpreter) SetSyncMode added in v0.4.9

func (it *Interpreter) SetSyncMode() *Interpreter

Set synchroneous mode. Results will be aggregated and sent at the end. This is the default mode.

func (*Interpreter) With added in v0.4.9

func (it *Interpreter) With(params map[string]any) *Interpreter

Set input parameters for the request to interprete.

type Lexer added in v0.4.9

type Lexer = yyLexer

Minimal Lexer interface.

func NewLexer added in v0.4.9

func NewLexer(name string, data []byte, errorWriter io.Writer) Lexer

Construct new myLexer. Use errorWriter to capture detailed error messages. If nil, errors will appear on stdout.

type Node added in v0.4.9

type Node interface {
	// contains filtered or unexported methods
}

Node for the abstract syntax tree.

func Compile added in v0.4.9

func Compile(name string, content string) (compiledReq Node, err error)

Compile a request. Once compiled, a request can be executed multiple times in different Interpreter contexts.

type NodeMap added in v0.4.9

type NodeMap map[string]Node

A map of string to Node is also a Node.

type NodeWithBody added in v0.4.9

type NodeWithBody interface {
	Node
	// contains filtered or unexported methods
}

Node with a body (eg : loop statement)

type Nodes added in v0.4.9

type Nodes []Node

A list of Node is also a Node. There are evaluated sequentially. Evaluation stops on error or context cancelation.

Jump to

Keyboard shortcuts

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