ast package full godoc

This commit is contained in:
Aidan 2020-07-18 14:40:35 -07:00
parent 956044cfae
commit fec3550702
No known key found for this signature in database
GPG key ID: 327711E983899316
7 changed files with 68 additions and 26 deletions

View file

@ -26,11 +26,19 @@ import (
"gitlab.com/whom/shs/log"
)
// Trigger this if you are using this for a shell
/* defines whether or not to synchronize tokens wiht os environment vars
* will not sync non stringable tokens
*/
var SyncTablesWithOSEnviron = false
/* mapping of key to token.
*/
type VarTable *map[string]*Token
/* retrieve the token cooresponding to a given key
* if SyncTablesWithOSEnviron is true and no token exists for a key
* os Environment variables will be searched for the key
*/
func GetVar(arg string, vt VarTable) *Token {
val, ok := (*vt)[arg]
if !ok {
@ -55,8 +63,10 @@ func GetVar(arg string, vt VarTable) *Token {
return val
}
// TODO: this could be much more optimal
// probably a stdlib thing
/* adds a key->token mapping to the table
* if SyncTablesWithOSEnviron is true, will also add value to os environment
* will not do so for non stringable tokens
*/
func SetVar(variable string, value *Token, vt VarTable) {
(*vt)[variable] = value
if SyncTablesWithOSEnviron &&
@ -85,22 +95,9 @@ func ListVars(vt VarTable) []string {
return keys
}
// Library represents variables defined in inner scope
// It is assumed library is ordered from innermost scope to outermost scope
func GetVarFromTables(arg string, library []VarTable) *Token {
var res *Token
res = nil
for i := 0; i < len(library); i += 1 {
res = GetVar(arg, library[i])
if res != nil {
// TODO: Log scope res was found in?
break
}
}
return res
}
/* if SyncTablesWithOSEnviron is true
* function will put ever environment variable into VarTable
*/
func InitVarTable(table VarTable) {
if !SyncTablesWithOSEnviron {
return
@ -133,7 +130,10 @@ func DeleteVarTable(table VarTable) {
}
}
}
a
/* removes var from vartable
* if SyncTablesWithOSENviron is true, also unsets environment variable
*/
func RemoveVar(arg string, table VarTable) {
if SyncTablesWithOSEnviron {
err := os.Unsetenv(arg)