interpreter

package
v0.0.0-...-b44964e Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: Apache-2.0, Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Copyright (c) 2014-2019 Cesanta Software Limited All rights reserved

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

This section is empty.

Functions

func ExpandVars

func ExpandVars(interp *MosInterpreter, s string, skipFailed bool) (string, error)

func ExpandVarsSlice

func ExpandVarsSlice(interp *MosInterpreter, slice []string, skipFailed bool) ([]string, error)

func GetMVarName

func GetMVarName(names ...string) string

func GetMVarNameLib

func GetMVarNameLib(libName string) string

GetMVarNameLib returns a string like "mos.libs.foo"

func GetMVarNameLibPath

func GetMVarNameLibPath(libName string) string

GetMVarNameLibPath returns a string like "mos.libs.foo.path"

func GetMVarNameManifest

func GetMVarNameManifest() string

GetMVarNameManifest returns "manifest"

func GetMVarNameModule

func GetMVarNameModule(moduleName string) string

GetMVarNameModule returns a string like "mos.modules.foo"

func GetMVarNameModulePath

func GetMVarNameModulePath(moduleName string) string

GetMVarNameModulePath returns a string like "mos.modules.foo.path"

func GetMVarNameMos

func GetMVarNameMos() string

GetMVarNameMos returns "mos"

func GetMVarNameMosPlatform

func GetMVarNameMosPlatform() string

GetMVarNameMosPlatform returns "mos.platform"

func GetMVarNameMosVersion

func GetMVarNameMosVersion() string

GetMVarNameMosVersion returns "mos.version"

func SetLibVars

func SetLibVars(mVars *MosVars, libName, path string)

SetLibVars populates "mos.libs.<libName>".

func SetManifestVars

func SetManifestVars(mVars *MosVars, manifest *build.FWAppManifest) error

SetManifestVars makes all variables from the given manifest available at the top level and under "manifest". Any previously existing manifest variables are removed.

func SetModuleVars

func SetModuleVars(mVars *MosVars, moduleName, path string)

SetModuleVars populates "mos.modules.<moduleName>".

func WrapMosExpr

func WrapMosExpr(s string) string

Types

type MosInterpreter

type MosInterpreter struct {
	MVars *MosVars
}

MosInterpreter can evaluate very simple expressions, see EvaluateExpr. Expressions are evaluated against enclosed MosVars.

func NewInterpreter

func NewInterpreter(mVars *MosVars) *MosInterpreter

func (*MosInterpreter) Copy

func (mi *MosInterpreter) Copy() *MosInterpreter

func (*MosInterpreter) EvaluateExpr

func (mi *MosInterpreter) EvaluateExpr(expr string) (interface{}, error)

EvaluateExpr can evaluate expressions of the following form:

  • operand
  • operand1 op operand2

Where either operand can be a string like "foo", or an expression suitable for MosVars.GetVar, e.g. foo.bar.baz. Operation can be either == or !=.

Examples:

  • arch
  • build_vars.FOO_BAR == "foo"
  • "bar"

In the future it will be hopefully refactored into a proper expression parsing and evaluation, but so far it's a quick hack which solves the problem at hand.

func (*MosInterpreter) EvaluateExprBool

func (mi *MosInterpreter) EvaluateExprBool(expr string) (bool, error)

EvaluateExprBool calls EvaluateExpr and if the result is boolean, then returns it; otherwise returns an error

func (*MosInterpreter) EvaluateExprString

func (mi *MosInterpreter) EvaluateExprString(expr string) (string, error)

EvaluateExprString calls EvaluateExpr and converts the result to string

type MosVars

type MosVars struct {
	// contains filtered or unexported fields
}

MosVars is a wrapper around datamap.DataMap with get-fail-handler which provides some shortcut phantom values, e.g. it makes everything under "manifest" available at the top level, and also provides backward compatibility: maps "foo_bar_path" to "mos.modules.foo_bar.path" (and prints a warning if such old name is used).

There are also a couple of helper functions to set mos-specific variables: SetModuleVars() and SetManifestVars.

func NewMosVars

func NewMosVars() *MosVars

func (*MosVars) Copy

func (mv *MosVars) Copy() *MosVars

func (*MosVars) GetVar

func (mv *MosVars) GetVar(name string) (interface{}, bool)

func (*MosVars) SetVar

func (mv *MosVars) SetVar(name string, value interface{})

Jump to

Keyboard shortcuts

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