Pip.Services Logo Tokenizers, parsers and expression calculators Golang

This module is a part of the Pip.Services polyglot microservices toolkit. It provides syntax and lexical analyzers and expression calculator optimized for repeated calculations.

The module contains the following packages:

  • Calculator – Expression calculator
  • CSV – CSV tokenizer
  • IO – input/output utility classes to support lexical analysis
  • Mustache – Mustache templating engine
  • Tokenizers – lexical analyzers to break incoming character streams into tokens
  • Variants – dynamic objects that can hold any values and operators for them

Quick links:


Get the package from the Github repository:

go get -u github.com/pip-services3-gox/[email protected]

The example below shows how to use expression calculator to dynamically calculate user-defined expressions.

import (

    calc "github.com/pip-services3-gox/pip-services3-expressions-gox/calculator"
    vars "github.com/pip-services3-gox/pip-services3-expressions-gox/calculator/variables"
    variants "github.com/pip-services3-gox/pip-services3-expressions-gox/variants"

calculator := calc.NewExpressionCalculator()

calculator.SetExpression("A + b / (3 - Max(-123, 1)*2)")

variables := vars.NewVariableCollection()
variables.Add(vars.NewVariable("A", variants.NewVariantFromInteger(1)))
variables.Add(vars.NewVariable("B", variants.NewVariantFromString("3")))

result, err := calculator.EvaluateWithVariables(variables)
if err != nil {
    fmt.Println("Failed to calculate the expression")
} else {
    fmt.Println("The result of the expression is " + result.AsString())

This is an example to process mustache templates.

import (

    mustache "github.com/pip-services3-gox/pip-services3-expressions-gox/mustache"

template := mustache.NewMustacheTemplate()
template.SetTemplate("Hello, {{{NAME}}}{{#ESCLAMATION}}!{{/ESCLAMATION}}{{#unless ESCLAMATION}}.{{/unless}}")
result, err := template.EvaluateWithVariables(map[string]string{ "NAME": "Mike", "ESCLAMATION": "true" })
if err != nil {
    fmt.Println("Failed to evaluate mustache template")
} else {
    fmt.Println("The result of template evaluation is '" + result + "'")


For development you shall install the following prerequisites:

  • Golang v1.18+
  • Visual Studio Code or another IDE of your choice
  • Docker
  • Git

Run automated tests:

go test -v ./test/...

Generate API documentation:


Before committing changes run dockerized test as:



The Golang version of Pip.Services is created and maintained by:

  • Sergey Seroukhov


View Github