strategy

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoolCodegen

type BoolCodegen interface {
	// RenderVal renders the value of the boolean
	//
	// Hulo:
	//  let a = true
	//  let b = false
	//
	// Target code:
	//  a=1
	//  b=0
	RenderVal(node hast.Expr) (bast.Node, error)
	// RenderExpr renders the expression of the boolean
	//
	// Hulo:
	//  if true {
	//		echo "this is true"
	//  } else {
	//		echo "this is false"
	//  }
	//
	// Target code:
	//  if [ "1" = "1" ]; then
	//    echo "this is true"
	//  else
	//    echo "this is false"
	//  fi
	RenderExpr(node hast.Expr) (bast.Node, error)
}

BoolCodegen is the interface for the boolean codegen

type BooleanAsCommandStrategy

type BooleanAsCommandStrategy struct{}

func (*BooleanAsCommandStrategy) Apply

func (s *BooleanAsCommandStrategy) Apply(root hast.Node, node hast.Node) (bast.Node, error)

func (*BooleanAsCommandStrategy) Name

func (s *BooleanAsCommandStrategy) Name() string

type BooleanAsNumberStrategy

type BooleanAsNumberStrategy struct{}

func (*BooleanAsNumberStrategy) Apply

func (s *BooleanAsNumberStrategy) Apply(root hast.Node, node hast.Node) (bast.Node, error)

func (*BooleanAsNumberStrategy) Name

func (s *BooleanAsNumberStrategy) Name() string

*

  • Transform boolean to number *
  • If the boolean is true, it will be transformed to number 1, otherwise it will be transformed to number 0 *
  • For example: * *
  • if [ "$a" = "b" ]; then
  • echo "a is b"
  • else
  • echo "a is not b"
  • fi * *

type BooleanAsStringStrategy

type BooleanAsStringStrategy struct{}

BooleanAsStringStrategy converts boolean values to strings

If the boolean value is true, it will be converted to the string "true", otherwise it will be converted to the string "false"

Example:

if [ "$a" = "true" ]; then
  echo "a is true"
else
  echo "a is false"
fi

func (*BooleanAsStringStrategy) Apply

func (s *BooleanAsStringStrategy) Apply(root hast.Node, node hast.Node) (bast.Node, error)

func (*BooleanAsStringStrategy) Name

func (s *BooleanAsStringStrategy) Name() string

type NumberBoolEncoder

type NumberBoolEncoder struct{}

Jump to

Keyboard shortcuts

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