parser

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package parser offers a CQL parser that produces an intermediate ELM like data structure for evaluation.

Index

Constants

View Source
const (
	// SyntaxError is returned by the lexer when the CQL does not meet the grammar.
	SyntaxError = ErrorType("SyntaxError")
	// ValidationError is returned by the parser when the CQL meets the grammar, but does not meet
	// some other validation rules (like referencing a non-existent expression definition).
	ValidationError = ErrorType("ValidationError")
	// InternalError occurs when the parser errors in an unexpected way. This is not a user error, nor
	// a feature that we purposefully do not support.
	InternalError = ErrorType("InternalError")
	// UnsupportedError is return for CQL language features that are not yet supported.
	UnsupportedError = ErrorType("UnsupportedError")
)
View Source
const (
	// ErrorSeverityInfo is informational.
	ErrorSeverityInfo = ErrorSeverity("Info")
	// ErrorSeverityWarning is a medium severity error.
	ErrorSeverityWarning = ErrorSeverity("Warning")
	// ErrorSeverityError is a high severity error.
	ErrorSeverityError = ErrorSeverity("Error")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
}

Config configures the parsing of CQL.

type ErrorSeverity

type ErrorSeverity string

ErrorSeverity represents different ParsingError severity levels.

type ErrorType

type ErrorType string

ErrorType is the type of parsing error.

type LibraryErrors

type LibraryErrors struct {
	LibKey result.LibKey
	Errors []*ParsingError
}

LibraryErrors contains a list of CQL parsing errors that occurred within a single library.

func (*LibraryErrors) Append

func (le *LibraryErrors) Append(e *ParsingError)

Append adds the given error to the list of ParsingErrors.

func (*LibraryErrors) Error

func (le *LibraryErrors) Error() string

func (*LibraryErrors) Unwrap

func (le *LibraryErrors) Unwrap() []error

Unwrap implements the Go standard errors package Unwrap() function. See https://pkg.go.dev/errors.

type ParameterErrors

type ParameterErrors struct {
	DefKey result.DefKey
	Errors []*ParsingError
}

ParameterErrors contains a list of CQL parsing errors that occurred parsing a single parameter.

func (*ParameterErrors) Append

func (pe *ParameterErrors) Append(e *ParsingError)

Append adds the given error to the list of ParsingErrors.

func (*ParameterErrors) Error

func (pe *ParameterErrors) Error() string

func (*ParameterErrors) Unwrap

func (pe *ParameterErrors) Unwrap() []error

Unwrap implements the Go standard errors package Unwrap() function. See https://pkg.go.dev/errors.

type Parser

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

Parser parses CQL library and parameter strings into our intermediate ELM like data structure. The parser is responsible for all validation and implicit conversions.

func New

func New(ctx context.Context, dataModels [][]byte) (*Parser, error)

New returns a new Parser initialized to the data models.

func (*Parser) DataModel

func (p *Parser) DataModel() *modelinfo.ModelInfos

DataModel returns the parsed model info.

func (*Parser) Libraries

func (p *Parser) Libraries(ctx context.Context, cqlLibs []string, config Config) ([]*model.Library, error)

Libraries parses the CQL libraries into a list of model.Library or an error. Underlying parsing issues will return a ParsingErrors struct that users can check for and report to the user accordingly. TODO: b/332337287 - Investigate returning results as a map now that libraries are being sorted.

func (*Parser) Parameters

func (p *Parser) Parameters(ctx context.Context, params map[result.DefKey]string, config Config) (map[result.DefKey]model.IExpression, error)

Parameters parses CQL literals into model.IExpressions. Each param should be a CQL literal, not an expression definition, valueset or other CQL construct.

type ParsingError

type ParsingError struct {
	// High level message about the error.
	Message string
	// Line is the 1-based line number within source file where the error occurred.
	Line int
	// Column is the 0-based column number within source file where the error occurred.
	Column int
	// Type is the type of the error that occurred, such as SyntaxError or InternalError.
	Type ErrorType
	// Severity represents different severity levels.
	Severity ErrorSeverity
	// Cause is an optional, underlying error that caused the parsing error.
	Cause error
}

ParsingError represents a specific parser error and its location.

func (*ParsingError) Error

func (pe *ParsingError) Error() string

func (*ParsingError) Unwrap

func (pe *ParsingError) Unwrap() error

Jump to

Keyboard shortcuts

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