lang

package
v0.0.0-...-4d0e586 Latest Latest
Warning

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

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

Documentation

Overview

Package lang parses failure association rule predicates. The predicate syntax defined here is intended to be a subset of BigQuery Standard SQL's Expression syntax, with the same semantics. This provides a few benefits:

  • Well-known and understood syntax and semantics.
  • Ability to leverage existing high-quality documentation to communicate language concepts to end-users.
  • Simplified debugging of LUCI Analysis (by allowing direct copy- paste of expressions into BigQuery to verify clustering is correct).
  • Possibility of using BigQuery as an execution engine in future.

Rules permitted by this package look similar to:

reason LIKE "% exited with code 5 %" AND NOT
  ( test = "arc.Boot" OR test = "arc.StartStop" )

The grammar for the language in Extended Backus-Naur form follows. The top-level production rule is BoolExpr.

BoolExpr = BoolTerm , ( "OR" , BoolTerm )* ; BoolTerm = BoolFactor , ( "AND" , BoolFactor )* ; BoolFactor = [ "NOT" ] BoolPrimary ; BoolPrimary = BoolItem | BoolPredicate ; BoolItem = BoolConst | "(" , BoolExpr , ")" | BoolFunc ; BoolConst = "TRUE" | "FALSE" ; BoolFunc = Identifier , "(" , StringExpr , ( "," , StringExpr )* , ")" ; BoolPredicate = StringExpr , BoolTest ; BoolTest = CompPredicate | NegatablePredicate ; CompPredicate = Operator , StringExpr ; Operator = "!=" | "<>" | "=" NegatablePredicate = [ "NOT" ] , ( InPredicate | LikePredicate ) ; InPredicate = "IN" , "(" , StringExpr , ( "," , StringExpr )* , ")" ; LikePredicate = "LIKE" , String ; StringExpr = String | Identifier ;

Where: - Identifier represents the production rule for identifiers. - String is the production rule for a double-quoted string literal. The precise definitions of which are omitted here but found in the implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Merge

func Merge(rule1 string, rule2 string) (string, error)

Merge merges two failure association rules with a logical "OR".

func ValidateLikePattern

func ValidateLikePattern(likePattern string) error

ValidateLikePattern validates the given string is a valid LIKE pattern. In particular, this checks that all escape sequences are valid, and that there is no unfinished trailing escape sequence (trailing '\').

Types

type Expr

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

Expr represents a predicate for a failure association rule.

func Parse

func Parse(text string) (*Expr, error)

Parse parses a failure association rule from the specified text. idents is the set of identifiers that are recognised by the application.

func (*Expr) Evaluate

func (e *Expr) Evaluate(failure *clustering.Failure) bool

Evaluate evaluates the given expression, using the given values for variables used in the expression.

func (*Expr) String

func (e *Expr) String() string

String returns the predicate as a string, with normalised formatting.

Jump to

Keyboard shortcuts

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