Documentation ¶
Overview ¶
Copyright © 2021 Unknown <applicant@airwallex.com>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidOperator = errors.New("invalid operator specific")
ErrInvalidOperator is a predefined error for invalid operators.
var ErrUserExited = errors.New("user exited the operation")
ErrUserExited is a hacky way to exit the current operation
Functions ¶
func RunCalculator ¶
func RunCalculator(c *Calculator, w io.Writer, i string) error
RunCalculator runs the calculator with the provided input string and outputs colorized information to the provided io.Writer.
func RunInteractiveCalculator ¶
RunInteractiveCalculator runs the calculator with the provided io.Reader until it hits an exit operation and outputs colorized information to the provided io.Writer.
Types ¶
type Calculator ¶
type Calculator struct {
// contains filtered or unexported fields
}
Calculator is the main application which allows parsing input and adds item to the stack or performs operations on the stack.
func NewCalculator ¶
func NewCalculator(operators ...operator.Operator) (c *Calculator, err error)
NewCalculator is a factory method to create a new Calculator instance and adds the provided operators to its internal map. It detects duplicate operator types and invalid operators which do not define any operation.
func NewDefaultCalculator ¶
func NewDefaultCalculator() (*Calculator, error)
NewDefaultCalculator is a factory method to return a new Calculator instance with all default operators.
func (*Calculator) Calculate ¶
func (c *Calculator) Calculate(input string) (err error)
Calculate receives an input string, tokenizes it and checks whether the input is a) a valid operator or b) a valid float64 value.
func (*Calculator) Stack ¶
func (c *Calculator) Stack() *stack.Stack
Stack returns the current stack