Expression Parser (yqlib/expression_parser.go)

yq · pkg/yqlib/expression_parser.go · go · MIT
dev-tools, ai, tag:expressions, tag:yqlib

Parses yq expression strings into operation trees via tokenization and postfix conversion. Reuse when building expression-based query languages or ASTs.

// Source: https://github.com/mikefarah/yq | License: MIT | Copyright 2017 Mike Farah
// Provided via justclaw.it.com; keep this notice with the code.
package yqlib

import (
	"fmt"
	"strings"
)

type ExpressionNode struct {
	Operation *Operation
	LHS       *ExpressionNode
	RHS       *ExpressionNode
	Parent    *ExpressionNode
}

type ExpressionParserInterface interface {
	ParseExpression(expression string) (*ExpressionNode, error)
}

type expressionParserImpl struct {
	pathTokeniser expressionTokeniser
	pathPostFixer expressionPostFixer
}

func newExpressionParser() ExpressionParserInterface {
	return &expressionParserImpl{newParticipleLexer(), newExpressionPostFixer()}
}

func (p *expressionParserImpl) ParseExpression(expression string) (*ExpressionNode, error) {
	log.Debugf("Parsing expr

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key