<commit_before>package main

import "fmt"

type AST interface {
	eval(*Evaluator)
	show()
}

type ASTBase struct {
	filename string
	lineno   int
}

type AssignAST struct {
	ASTBase
	lhs string
	rhs string
	op  string
}

func (ast *AssignAST) eval(ev *Evaluator) {
	ev.evalAssign(ast)
}

func (ast *AssignAST) evalRHS(ev *Evaluator, lhs string) Var {
	switch ast.op {
	case ":=":
		// TODO: origin
		return SimpleVar{value: ev.evalExpr(ast.rhs)}
	case "=":
		return RecursiveVar{expr: ast.rhs}
	case "+=":
		prev := ev.LookupVar(lhs)
		if !prev.IsDefined() {
			return RecursiveVar{expr: ast.rhs}
		}
		return prev.Append(ev, ast.rhs)
	case "?=":
		prev := ev.LookupVar(lhs)
		if prev.IsDefined() {
			return prev
		}
		return RecursiveVar{
			expr: ev.evalExpr(ast.rhs),
		}
	default:
		panic(fmt.Sprintf("unknown assign op: %q", ast.op))
	}
}

func (ast *AssignAST) show() {
	Log("%s=%q", ast.lhs, ast.rhs)
}

// Note we cannot be sure what this is, until all variables in |expr|
// are expanded.
type MaybeRuleAST struct {
	ASTBase
	expr      string
	cmds      []string
	cmdLineno int
}

func (ast *MaybeRuleAST) eval(ev *Evaluator) {
	ev.evalMaybeRule(ast)
}

func (ast *MaybeRuleAST) show() {
	Log("%s", ast.expr)
	for _, cmd := range ast.cmds {<commit_msg>fix var_cond_assign<commit_after>package main

import "fmt"

type AST interface {
	eval(*Evaluator)
	show()
}

type ASTBase struct {
	filename string
	lineno   int
}

type AssignAST struct {
	ASTBase
	lhs string
	rhs string
	op  string
}

func (ast *AssignAST) eval(ev *Evaluator) {
	ev.evalAssign(ast)
}

func (ast *AssignAST) evalRHS(ev *Evaluator, lhs string) Var {
	switch ast.op {
	case ":=":
		// TODO: origin
		return SimpleVar{value: ev.evalExpr(ast.rhs)}
	case "=":
		return RecursiveVar{expr: ast.rhs}
	case "+=":
		prev := ev.LookupVar(lhs)
		if !prev.IsDefined() {
			return RecursiveVar{expr: ast.rhs}
		}
		return prev.Append(ev, ast.rhs)
	case "?=":
		prev := ev.LookupVar(lhs)
		if prev.IsDefined() {
			return prev
		}
		return RecursiveVar{expr: ast.rhs}
	default:
		panic(fmt.Sprintf("unknown assign op: %q", ast.op))
	}
}

func (ast *AssignAST) show() {
	Log("%s=%q", ast.lhs, ast.rhs)
}

// Note we cannot be sure what this is, until all variables in |expr|
// are expanded.
type MaybeRuleAST struct {
	ASTBase
	expr      string
	cmds      []string
	cmdLineno int
}

func (ast *MaybeRuleAST) eval(ev *Evaluator) {
	ev.evalMaybeRule(ast)
}

func (ast *MaybeRuleAST) show() {
	Log("%s", ast.expr)
	for _, cmd := range ast.cmds {
{'fraction_non_alphanumeric': 0.14268632921482663, 'fraction_numerical': 0.0, 'mean_word_length': 3.6481481481481484, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1471279', 'n_tokens_mistral': 1021, 'n_tokens_neox': 995, 'n_words': 258}