sparql

package
v1.22.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package sparql parses Sparql query for translation.

Package sparql includes parsing utilities for Sparql query.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseQuery

func ParseQuery(queryString string) ([]base.Node, []*base.Query, *base.QueryOptions, error)

ParseQuery parses a sparql query into list of nodes and list of query statements.

func ScanBareIdent

func ScanBareIdent(r io.RuneScanner) string

ScanBareIdent reads bare identifier from a rune reader.

func ScanDelimited

func ScanDelimited(
	r io.RuneScanner, start, end rune, escapes map[rune]rune, escapesPassThru bool) ([]byte, error)

ScanDelimited reads a delimited set of runes.

func ScanString

func ScanString(r io.RuneScanner) (string, error)

ScanString reads a quoted string from a rune reader.

Types

type Orderby

type Orderby struct {
	Variable string
	ASC      bool
}

Orderby represents the order by condition.

type ParseError

type ParseError struct {
	Message  string
	Found    string
	Expected []string
	Pos      Pos
}

ParseError represents an error that occurred during parsing.

type Parser

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

Parser represents a Sparql parser.

func NewParser

func NewParser(r io.Reader) *Parser

NewParser returns a new instance of Parser.

func (*Parser) Parse

func (p *Parser) Parse() (*QueryTree, *ParseError)

Parse parses sparql query into syntax tree.

func (*Parser) Scan

func (p *Parser) Scan() (tok Token, pos Pos, lit string)

Scan returns the next token from the underlying scanner.

func (*Parser) ScanIgnoreWhitespace

func (p *Parser) ScanIgnoreWhitespace() (tok Token, pos Pos, lit string)

ScanIgnoreWhitespace scans the next non-whitespace and non-comment token.

func (*Parser) Unscan

func (p *Parser) Unscan()

Unscan pushes the previously read token back onto the buffer.

type Pos

type Pos struct {
	Line int
	Char int
}

Pos specifies the line and character position of a token. The Char and Line are both zero-based indexes.

type Prologue

type Prologue struct {
	Base   string
	Prefix map[string]string
}

Prologue represents query prologue information

type QueryTree

type QueryTree struct {
	P *Prologue
	S *Select
	W *Where
	O *Orderby
	L int
}

QueryTree represents a parsed Sparql syntax tree.

type Scanner

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

Scanner represents a lexical scanner for InfluxQL.

func NewScanner

func NewScanner(r io.Reader) *Scanner

NewScanner returns a new instance of Scanner.

func (*Scanner) Scan

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

Scan returns the next token and position from the underlying reader. Also returns the literal text read for strings, numbers, and duration tokens since these token types can have different literal representations.

type Select

type Select struct {
	Variable []string
	Distinct bool
}

Select contains information in the SELECT statement.

type Token

type Token int

Token is a lexical token in Sparql.

const (
	// ILLEGAL and following are base tokens.
	ILLEGAL Token = iota
	EOF
	WS

	// IDENT and following are Sparql literal tokens.
	IDENT     // rdf
	URI       // <http://example.org>
	VARIABLE  // ?a
	NUMBER    // 123.45
	STRING    // "abc"
	BADSTRING // "abc
	BADESCAPE // \q
	TRUE      // true
	FALSE     // false

	// AND and following are Sparql operators.
	AND // AND
	OR  // OR
	EQ  // =

	LT        // <
	GT        // >
	LPAREN    // (
	RPAREN    // )
	LBRAC     // {
	RBRAC     // }
	COMMA     // ,
	SEMICOLON // ;
	DOT       //.
	HASH      // #

	// ASC and following are Sparql keywords.
	ASC
	BASE
	BY
	DESC
	DISTINCT
	FILTER
	FROM
	IN
	LIMIT
	ORDER
	PREFIX
	SELECT
	WHERE
)

func Lookup

func Lookup(ident string) Token

Lookup returns the token associated with a given string.

func (Token) Precedence

func (tok Token) Precedence() int

Precedence returns the operator precedence of the binary operator token.

func (Token) String

func (tok Token) String() string

String returns the string representation of the token.

type Triple

type Triple struct {
	Sub  string
	Pred string
	Objs []string
}

Triple reprensts a triple in Sparql query.

type Where

type Where struct {
	Triples []Triple
}

Where represents the where condition in Sparql query.

Jump to

Keyboard shortcuts

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