kvalscanner

package
v0.0.0-...-3d94c54 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2022 License: MIT, GPL-3.0 Imports: 6 Imported by: 0

README

KVAL-Scanner

Build Status GoDoc Go Report Card

Lexical scanner for KVAL (Key Value Access Language) for KVAL-Parser

Key Value Access Language

I have created a modest specification for a key value access langauge. It allows for input and access of values to a key value store such as Golang's BoltDB.

The language specification: https://github.com/kval-access-language/KVAL

Usage

Usage is pretty low-level so will normally be done via KVAL-Parse so please see there for examples.

Scanner library is maintained in its own repo so that changes between the two can be viewed as purely as possible.

License

GPL Version 3: https://github.com/kval-access-language/KVAL-BoltDB/blob/master/LICENSE

Documentation

Overview

Package kvalscanner implements a basic lexical scanner for KVAL (Key Value Access Language). The language has been created for more fluid access to Key-Value-like databases such as the popular BoltDb.

Parsers can access a new Scanner() to check that a user provided string is valid according to the language's specification. For Golang, however, this work is already done for you at http://github.com/wayblink/kval-parse

The most up-to-date specification for KVAL can be found here: https://github.com/wayblink/kval

Index

Constants

This section is empty.

Variables

View Source
var ErrorLookup = map[Token]string{
	ILLEGAL: "ILLEGAL",
	EOF:     "EOF",
	WS:      "WHITESPACE",

	LITERAL: "LITERAL",

	BUCKEY: "BUCKET >>>> KEY",
	BUCBUC: "BUCKET >> BUCKET",
	KEYVAL: "KEY :: VALUE",
	ASSIGN: "ASSIGNMENT",

	USCORE: "UNDERSCORE",
	OPATT:  "OPEN REGEX PATTERN",
	CPATT:  "CLOSE REGEX PATTERN",

	INS: "INSERT KEYWORD",
	GET: "GET KEYWORD",
	LIS: "LIS KEYWORD",
	DEL: "DEL KEYWORD",
	REN: "REN KEYWORD",

	REGEX: "REGEX PATTERN",
}

ErrorLookup map is used to look up an error and provide a human readable response

View Source
var KeywordMap = map[string]int{
	"INS": 0x1,
	"ins": 0x1,
	"Ins": 0x1,

	"GET": 0x2,
	"get": 0x2,
	"Get": 0x2,

	"LIS": 0x3,
	"lis": 0x3,
	"Lis": 0x3,

	"DEL": 0x4,
	"del": 0x4,
	"Del": 0x4,

	"REN": 0x5,
	"ren": 0x5,
	"Ren": 0x5,
}

KeywordMap values exported for KVAL Parser to verify keywords Lookup 'LIT' value in KeyWordMap and if found we have a KVAL key word, e.g. INS, GET, LIS, REN, DEL. If used correctly this map will help a parser take care of and case-sensitivity issues when users specify query strings.

Functions

This section is empty.

Types

type Scanner

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

Scanner represents a lexical scanner.

func NewScanner

func NewScanner(r io.Reader) *Scanner

NewScanner returns a new instance of Scanner.

func (*Scanner) Scan

func (s *Scanner) Scan() (tok Token, lit string)

Scan returns the next token and literal value.

type Token

type Token int

Token represents a lexical token.

const (
	ILLEGAL Token = iota // Spacial token, ILLEGAL: Token is an illegal character
	EOF                  // Spacial token, EOF: Token signals the end of input
	WS                   // Spacial token, WS: Token signals whitespace has been found

	LITERAL // LITERAL: String literal discovered

	BUCKEY // Other operator, BUCKKEY: >>>> Bucket to Key syntax for KVAL
	BUCBUC // Other operator, BUCBUC: >> Bucket to Bucket syntax for KVAL
	KEYVAL // Other operator, KEYVALL :: Key to Value syntax for KVAL
	ASSIGN // Other operator, ASSIGN: => Assignment operator for KVAL renames

	USCORE // Single character operator, USCORE: _ Return unknown Key or Value
	OPATT  // Single character operator, OPATT: { Open a regular expression pattern
	CPATT  // Single character operator, COATT: } Close a regular expression pattern

	INS // Keyword, INS: Insert capability of KVAL
	GET // Keyword, GET: Get capability of KVAL
	LIS // Keyword, LIS: LIS capability of KVAL
	DEL // Keyword, DEL: Delete capability of KVAL
	REN // Keyword, REN: Rename capability of KVAL

	REGEX // Regular expression, REGEX: {PATT} ANy regex pattern inside OPATT and CPATT
)

Tokens to scan for that satisfy the KVAL (Key Value Access Language) specification

Jump to

Keyboard shortcuts

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