fix build from last night
This commit is contained in:
parent
ab340ceb0a
commit
87004ff7fd
6 changed files with 210 additions and 213 deletions
|
|
@ -18,7 +18,6 @@
|
||||||
package ast
|
package ast
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"gitlab.com/whom/shs/log"
|
"gitlab.com/whom/shs/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -40,7 +39,7 @@ type Function struct {
|
||||||
|
|
||||||
// list of types (LIST, NUMBER, STRING, etc) representing args
|
// list of types (LIST, NUMBER, STRING, etc) representing args
|
||||||
Args []Token_t
|
Args []Token_t
|
||||||
NumArgs bool // -1 means infinite
|
NumArgs int // -1 means infinite
|
||||||
|
|
||||||
// lazy arg checking (use NumArgs instead of args)
|
// lazy arg checking (use NumArgs instead of args)
|
||||||
ArgLazy bool
|
ArgLazy bool
|
||||||
|
|
@ -62,7 +61,7 @@ type FuncTable *map[string]*Function
|
||||||
* makes sure correct arguments are passed in
|
* makes sure correct arguments are passed in
|
||||||
*/
|
*/
|
||||||
func (f Function) ParseFunction(args *Token) bool {
|
func (f Function) ParseFunction(args *Token) bool {
|
||||||
total = len(f.Args)
|
total := len(f.Args)
|
||||||
for iter := args; iter != nil; iter = iter.Next {
|
for iter := args; iter != nil; iter = iter.Next {
|
||||||
total -= 1
|
total -= 1
|
||||||
if total <= 0 {
|
if total <= 0 {
|
||||||
|
|
@ -88,7 +87,7 @@ func (f Function) ParseFunction(args *Token) bool {
|
||||||
/* same as ParseFunction but only evaluates the number of args
|
/* same as ParseFunction but only evaluates the number of args
|
||||||
*/
|
*/
|
||||||
func (f Function) LazyParseFunction(args *Token) bool {
|
func (f Function) LazyParseFunction(args *Token) bool {
|
||||||
if (f.NumArgs < 0) {
|
if f.NumArgs < 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,15 +117,15 @@ func (f Function) LazyParseFunction(args *Token) bool {
|
||||||
* calls ParseFunction and increments TimesCalled
|
* calls ParseFunction and increments TimesCalled
|
||||||
*/
|
*/
|
||||||
func (f Function) CallFunction(args *Token, vt VarTable, ft FuncTable) *Token {
|
func (f Function) CallFunction(args *Token, vt VarTable, ft FuncTable) *Token {
|
||||||
if not f.EvalLazy {
|
if !f.EvalLazy {
|
||||||
args = args.Eval(ft, vt, !f.SymLazy)
|
args = args.Eval(ft, vt, !f.SymLazy)
|
||||||
}
|
}
|
||||||
|
|
||||||
passes := false
|
passes := false
|
||||||
if f.ArgsLazy {
|
if f.ArgLazy {
|
||||||
passes = LazyParseFunction(args)
|
passes = f.LazyParseFunction(args)
|
||||||
} else {
|
} else {
|
||||||
passes = ParseFunction(args)
|
passes = f.ParseFunction(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
if passes {
|
if passes {
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
dyn_prompt := ast.GetFunction("_SH_PROMPT", funcs)
|
dyn_prompt := ast.GetFunction("_SH_PROMPT", funcs)
|
||||||
if dyn_prompt == nil || dyn_prompt.Args != 0 {
|
if dyn_prompt == nil || dyn_prompt.NumArgs != 0 {
|
||||||
dyn_prompt = nil
|
dyn_prompt = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ func DeclFunc(input *ast.Token, vars ast.VarTable, funcs ast.FuncTable) *ast.Tok
|
||||||
Name: name.Value(),
|
Name: name.Value(),
|
||||||
TimesCalled: 0,
|
TimesCalled: 0,
|
||||||
NumArgs: numArgs,
|
NumArgs: numArgs,
|
||||||
LazyArgs: true
|
ArgLazy: true,
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ func Len(input *ast.Token, vars ast.VarTable, funcs ast.FuncTable) *ast.Token {
|
||||||
}
|
}
|
||||||
|
|
||||||
length := 0
|
length := 0
|
||||||
if input.Tag = ast.STRING {
|
if input.Tag == ast.STRING {
|
||||||
length = len(input.Value())
|
length = len(input.Value())
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
401
stdlib/stdlib.go
401
stdlib/stdlib.go
|
|
@ -20,7 +20,6 @@ package stdlib
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"fmt"
|
"fmt"
|
||||||
"gitlab.com/whom/shs/log"
|
|
||||||
"gitlab.com/whom/shs/ast"
|
"gitlab.com/whom/shs/ast"
|
||||||
"gitlab.com/whom/shs/util"
|
"gitlab.com/whom/shs/util"
|
||||||
)
|
)
|
||||||
|
|
@ -32,316 +31,316 @@ func GenFuncTable() ast.FuncTable {
|
||||||
var stdlib ast.FuncTable
|
var stdlib ast.FuncTable
|
||||||
stdlib = &map[string]*ast.Function{
|
stdlib = &map[string]*ast.Function{
|
||||||
"if": &ast.Function{
|
"if": &ast.Function{
|
||||||
Function: ShsIf,
|
Function: ShsIf,
|
||||||
Name: "if",
|
Name: "if",
|
||||||
NumArgs: 3,
|
NumArgs: 3,
|
||||||
EvalLazy true,
|
EvalLazy: true,
|
||||||
ArgLazy true
|
ArgLazy: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"while": &ast.Function{
|
"while": &ast.Function{
|
||||||
Function: ShsWhile,
|
Function: ShsWhile,
|
||||||
Name: "while",
|
Name: "while",
|
||||||
NumArgs: -1,
|
NumArgs: -1,
|
||||||
EvalLazy true,
|
EvalLazy: true,
|
||||||
ArgLazy true,
|
ArgLazy: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"progn": &ast.Function{
|
"progn": &ast.Function{
|
||||||
Function: ShsProgn,
|
Function: ShsProgn,
|
||||||
Name: "shs_progn",
|
Name: "shs_progn",
|
||||||
NumArgs: -1,
|
NumArgs: -1,
|
||||||
EvalLazy: true,
|
EvalLazy: true,
|
||||||
ArgLazy: true,
|
ArgLazy: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"func": &ast.Function{
|
"func": &ast.Function{
|
||||||
Function: DeclFunc,
|
Function: DeclFunc,
|
||||||
Name: "decl_func",
|
Name: "decl_func",
|
||||||
Args: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
ast.STRING,
|
ast.STRING,
|
||||||
ast.LIST,
|
ast.LIST,
|
||||||
ast.LIST
|
ast.LIST,
|
||||||
},
|
},
|
||||||
EvalLazy: true,
|
EvalLazy: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"len": &ast.Function{
|
"len": &ast.Function{
|
||||||
Function: Len,
|
Function: Len,
|
||||||
Name: "len",
|
Name: "len",
|
||||||
NumArgs: 1,
|
NumArgs: 1,
|
||||||
ArgLazy: true,
|
ArgLazy: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"head": &ast.Function{
|
"head": &ast.Function{
|
||||||
Function: Head,
|
Function: Head,
|
||||||
Name: "head",
|
Name: "head",
|
||||||
Args: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
ast.LIST
|
ast.LIST,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"tail": &ast.Function{
|
"tail": &ast.Function{
|
||||||
Function: Tail,
|
Function: Tail,
|
||||||
Name: "tail",
|
Name: "tail",
|
||||||
Args: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
ast.LIST
|
ast.LIST,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"slice": &ast.Function{
|
"slice": &ast.Function{
|
||||||
Function: Slice,
|
Function: Slice,
|
||||||
Name: "slice",
|
Name: "slice",
|
||||||
Args: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
ast.NUMBER,
|
ast.NUMBER,
|
||||||
ast.NUMBER,
|
ast.NUMBER,
|
||||||
ast.LIST
|
ast.LIST,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"export": &ast.Function{
|
"export": &ast.Function{
|
||||||
Function: Export,
|
Function: Export,
|
||||||
Name: "export",
|
Name: "export",
|
||||||
LazyEval: true,
|
EvalLazy: true,
|
||||||
Args: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
ast.STRING,
|
ast.STRING,
|
||||||
ast.LIST
|
ast.LIST,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"input": &ast.Function{
|
"input": &ast.Function{
|
||||||
Function: Input,
|
Function: Input,
|
||||||
Name: "input",
|
Name: "input",
|
||||||
Args: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
ast.STRING
|
ast.STRING,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"load": &ast.Function{
|
"load": &ast.Function{
|
||||||
Function: Load,
|
Function: Load,
|
||||||
Name: "load",
|
Name: "load",
|
||||||
Args: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
ast.STRING
|
ast.STRING,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"bool": &ast.Function{
|
"bool": &ast.Function{
|
||||||
Function: BoolCast,
|
Function: BoolCast,
|
||||||
Name: "bool",
|
Name: "bool",
|
||||||
Args: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
ast.STRING
|
ast.STRING,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"string": &ast.Function{
|
"string": &ast.Function{
|
||||||
Function: StrCast,
|
Function: StrCast,
|
||||||
Name: "string",
|
Name: "string",
|
||||||
NumArgs: 1,
|
NumArgs: 1,
|
||||||
ArgLazy: true,
|
ArgLazy: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"number": &ast.Function{
|
"number": &ast.Function{
|
||||||
Function: NumCast,
|
Function: NumCast,
|
||||||
Name: "number",
|
Name: "number",
|
||||||
Args: []ast.Token{
|
Args: []ast.Token_t{
|
||||||
ast.NUMBER
|
ast.NUMBER,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"...": &ast.Function{
|
"...": &ast.Function{
|
||||||
Function: Expand,
|
Function: Expand,
|
||||||
Name: "...",
|
Name: "...",
|
||||||
Args: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
ast.LIST
|
ast.LIST,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"append": &ast.Function{
|
"append": &ast.Function{
|
||||||
Function: L_append,
|
Function: L_append,
|
||||||
Name: "append",
|
Name: "append",
|
||||||
NumArgs: -1,
|
NumArgs: -1,
|
||||||
ArgLazy: true,
|
ArgLazy: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"join": &ast.Function{
|
"join": &ast.Function{
|
||||||
Function: Join,
|
Function: Join,
|
||||||
Name: "join",
|
Name: "join",
|
||||||
Args: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
ast.STRING,
|
ast.STRING,
|
||||||
ast.LIST
|
ast.LIST,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"split": &ast.Function{
|
"split": &ast.Function{
|
||||||
Function: Split,
|
Function: Split,
|
||||||
Name: "split",
|
Name: "split",
|
||||||
Args: ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
|
ast.STRING,
|
||||||
ast.STRING,
|
ast.STRING,
|
||||||
ast.STRING
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"substr": &ast.Function{
|
"substr": &ast.Function{
|
||||||
Function: Substr,
|
Function: Substr,
|
||||||
Name: "substr",
|
Name: "substr",
|
||||||
Args: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
ast.NUMBER,
|
ast.NUMBER,
|
||||||
ast.NUMBER,
|
ast.NUMBER,
|
||||||
ast.STRING
|
ast.STRING,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"exit": &ast.Function{
|
"exit": &ast.Function{
|
||||||
Function: ExitShell,
|
Function: ExitShell,
|
||||||
Name: "exit",
|
Name: "exit",
|
||||||
Args: []ast.Token_t{},
|
Args: []ast.Token_t{},
|
||||||
},
|
},
|
||||||
|
|
||||||
"eq": &ast.Function{
|
"eq": &ast.Function{
|
||||||
Function: Eq,
|
Function: Eq,
|
||||||
Name: "==",
|
Name: "==",
|
||||||
Args: 2,
|
NumArgs: 2,
|
||||||
ArgLazy: true,
|
ArgLazy: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"ne": &ast.Function{
|
"ne": &ast.Function{
|
||||||
Function: Ne,
|
Function: Ne,
|
||||||
Name: "!=",
|
Name: "!=",
|
||||||
Args: 2,
|
NumArgs: 2,
|
||||||
ArgLazy: true,
|
ArgLazy: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"<": &ast.Function{
|
"<": &ast.Function{
|
||||||
Function: Lt,
|
Function: Lt,
|
||||||
Name: "<",
|
Name: "<",
|
||||||
Args: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
|
ast.NUMBER,
|
||||||
ast.NUMBER,
|
ast.NUMBER,
|
||||||
ast.NUMBER
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
">": &ast.Function{
|
">": &ast.Function{
|
||||||
Function: Gt,
|
Function: Gt,
|
||||||
Name: ">",
|
Name: ">",
|
||||||
Args: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
|
ast.NUMBER,
|
||||||
ast.NUMBER,
|
ast.NUMBER,
|
||||||
ast.NUMBER
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"<=": &ast.Function{
|
"<=": &ast.Function{
|
||||||
Function: Lte,
|
Function: Lte,
|
||||||
Name: "<=",
|
Name: "<=",
|
||||||
Args: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
|
ast.NUMBER,
|
||||||
ast.NUMBER,
|
ast.NUMBER,
|
||||||
ast.NUMBER
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
">=": &ast.Function{
|
">=": &ast.Function{
|
||||||
Function: Gte,
|
Function: Gte,
|
||||||
Name: ">=",
|
Name: ">=",
|
||||||
Args: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
|
ast.NUMBER,
|
||||||
ast.NUMBER,
|
ast.NUMBER,
|
||||||
ast.NUMBER
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"!": &ast.Function{
|
"!": &ast.Function{
|
||||||
Function: Not,
|
Function: Not,
|
||||||
Name: "!",
|
Name: "!",
|
||||||
Args: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
ast.Bool
|
ast.BOOL,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"+": &ast.Function{
|
"+": &ast.Function{
|
||||||
Function: Add,
|
Function: Add,
|
||||||
Name: "add",
|
Name: "add",
|
||||||
NumArgs: -1,
|
NumArgs: -1,
|
||||||
ArgLazy: true,
|
ArgLazy: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"-": &ast.Function{
|
"-": &ast.Function{
|
||||||
Function: Sub,
|
Function: Sub,
|
||||||
Name: "sub",
|
Name: "sub",
|
||||||
NumArgs: -1,
|
NumArgs: -1,
|
||||||
ArgLazy: true,
|
ArgLazy: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"*": &ast.Function{
|
"*": &ast.Function{
|
||||||
Function: Mult,
|
Function: Mult,
|
||||||
Name: "mult",
|
Name: "mult",
|
||||||
NumArgs: -1,
|
NumArgs: -1,
|
||||||
ArgLazy: true,
|
ArgLazy: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"/": &ast.Function{
|
"/": &ast.Function{
|
||||||
Function: Div,
|
Function: Div,
|
||||||
Name: "div",
|
Name: "div",
|
||||||
NumArgs: -1,
|
NumArgs: -1,
|
||||||
ArgLazy: true,
|
ArgLazy: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"cd": &ast.Function{
|
"cd": &ast.Function{
|
||||||
Function: Cd,
|
Function: Cd,
|
||||||
Name: "changedir",
|
Name: "changedir",
|
||||||
Args: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
ast.STRING
|
ast.STRING,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"concat": &ast.Function{
|
"concat": &ast.Function{
|
||||||
Function: Concat,
|
Function: Concat,
|
||||||
Name:"concatenate",
|
Name: "concatenate",
|
||||||
NumArgs: -1,
|
NumArgs: -1,
|
||||||
ArgLazy: true,
|
ArgLazy: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"print": &ast.Function{
|
"print": &ast.Function{
|
||||||
Function: PrintStr,
|
Function: PrintStr,
|
||||||
Name: "print",
|
Name: "print",
|
||||||
Args: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
ast.STRING
|
ast.STRING,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"l": &ast.Function{
|
"l": &ast.Function{
|
||||||
Function: Call,
|
Function: Call,
|
||||||
Name: "call",
|
Name: "call",
|
||||||
NumArgs: -1,
|
NumArgs: -1,
|
||||||
ArgLazy: true,
|
ArgLazy: true,
|
||||||
SymLazy: true,
|
SymLazy: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"bg": &ast.Function{
|
"bg": &ast.Function{
|
||||||
Function: Bgcall,
|
Function: Bgcall,
|
||||||
Name: "background call",
|
Name: "background call",
|
||||||
NumArgs: -1,
|
NumArgs: -1,
|
||||||
ArgLazy: true,
|
ArgLazy: true,
|
||||||
SymLazy: true,
|
SymLazy: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"fg": &ast.Function{
|
"fg": &ast.Function{
|
||||||
Function: Fg,
|
Function: Fg,
|
||||||
Name: "foreground",
|
Name: "foreground",
|
||||||
NumArgs: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
ast.NUMBER
|
ast.NUMBER,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"$": &ast.Function{
|
"$": &ast.Function{
|
||||||
Function: ReadCmd,
|
Function: ReadCmd,
|
||||||
Name: "read cmd",
|
Name: "read cmd",
|
||||||
NumnArgs: -1,
|
NumArgs: -1,
|
||||||
ArgLazy: true,
|
ArgLazy: true,
|
||||||
SymLazy: true,
|
SymLazy: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"?": &ast.Function{
|
"?": &ast.Function{
|
||||||
Function: GetExit,
|
Function: GetExit,
|
||||||
Name:"get exit code",
|
Name: "get exit code",
|
||||||
Args: ast.Token_t{},
|
Args: []ast.Token_t{},
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -354,50 +353,50 @@ func GenFuncTable() ast.FuncTable {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"jobs": &ast.Function{
|
"jobs": &ast.Function{
|
||||||
Function: Jobs,
|
Function: Jobs,
|
||||||
Name: "list jobs",
|
Name: "list jobs",
|
||||||
Args: ast.Token_t{},
|
Args: []ast.Token_t{},
|
||||||
},
|
},
|
||||||
|
|
||||||
"info": &ast.Function{
|
"info": &ast.Function{
|
||||||
Function: ShInfo,
|
Function: ShInfo,
|
||||||
Name: "Shell Info",
|
Name: "Shell Info",
|
||||||
Args: ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
ast.SYMBOL
|
ast.SYMBOL,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"fexists": &ast.Function{
|
"fexists": &ast.Function{
|
||||||
Function: Fexists,
|
Function: Fexists,
|
||||||
Name: "file exists",
|
Name: "file exists",
|
||||||
Args: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
ast.STRING
|
ast.STRING,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"fread": &ast.Function{
|
"fread": &ast.Function{
|
||||||
Function: Fread,
|
Function: Fread,
|
||||||
Name: "read file",
|
Name: "read file",
|
||||||
Args: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
ast.STRING
|
ast.STRING,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"fwrite": &ast.Function{
|
"fwrite": &ast.Function{
|
||||||
Function: Fwrite,
|
Function: Fwrite,
|
||||||
Name: "write file",
|
Name: "write file",
|
||||||
Args: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
|
ast.STRING,
|
||||||
ast.STRING,
|
ast.STRING,
|
||||||
ast.STRING
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"fappend": &ast.Function{
|
"fappend": &ast.Function{
|
||||||
Function: Fappend,
|
Function: Fappend,
|
||||||
Name:"append to file",
|
Name: "append to file",
|
||||||
Args: []ast.Token_t{
|
Args: []ast.Token_t{
|
||||||
|
ast.STRING,
|
||||||
ast.STRING,
|
ast.STRING,
|
||||||
ast.STRING
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -421,34 +420,32 @@ func ExitShell(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||||
* Example: (info append)
|
* Example: (info append)
|
||||||
*/
|
*/
|
||||||
func ShInfo(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
func ShInfo(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||||
switch in.Tag {
|
repr := ast.GetVar(in.Value(), vt)
|
||||||
case ast.BOOL:
|
if repr != nil {
|
||||||
fmt.Printf("BOOL LITERAL\nValue: %s\n", in.Value())
|
fmt.Printf("VARIABLE\nTYPE: %s\nVALUE: %s\n", ast.GetTagAsStr(repr.Tag), repr.Value())
|
||||||
case ast.STRING:
|
return nil
|
||||||
fmt.Printf("STRING LITERAL \nValue: %s\n", in.Value())
|
|
||||||
case ast.NUMBER:
|
|
||||||
fmt.Printf("NUMBER LITERAL \nValue: %s\n", in.Value())
|
|
||||||
case ast.LIST:
|
|
||||||
fmt.Printf("LIST \nString Value: %s, AST:\n", in.String())
|
|
||||||
ast.PrintSExprsIndividually(in)
|
|
||||||
case ast.SYMBOL:
|
|
||||||
repr := ast.GetVar(in.Value(), vt)
|
|
||||||
if repr != nil {
|
|
||||||
fmt.Printf("VARIABLE\nTYPE: %s\nVALUE: %s\n", ast.GetTagAsStr(repr.Tag), repr.Value())
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
funct := ast.GetFunction(in.Value(), ft)
|
|
||||||
if funct != nil {
|
|
||||||
fmt.Printf("FUNCTION\nNAME: %s\nTIMES CALLED: %s\nNUM ARGS: %d\n", funct.Name, funct.TimesCalled, funct.NumArgs)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: print func args
|
|
||||||
|
|
||||||
fmt.Printf("UNKNOWN SYMBOL\n")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
funct := ast.GetFunction(in.Value(), ft)
|
||||||
|
if funct != nil {
|
||||||
|
fmt.Printf("FUNCTION\nNAME: %s\nTIMES CALLED: %s\n\n", funct.Name, funct.TimesCalled)
|
||||||
|
if funct.ArgLazy {
|
||||||
|
fmt.Printf("function does not evaluate args by type\nARG COUNT: %s\n", funct.NumArgs)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("function evaluates args by type\nARGS: ")
|
||||||
|
for _, i := range(funct.Args) {
|
||||||
|
fmt.Printf(ast.GetTagAsStr(i))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("SYMLAZY: %t\n", funct.SymLazy)
|
||||||
|
fmt.Printf("(can undefined symbols be passed in)\n")
|
||||||
|
fmt.Printf("EVALLAZY: %t\n", funct.EvalLazy)
|
||||||
|
fmt.Printf("(are all forms in evaluated before function call)\n")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("UNKNOWN SYMBOL\n")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,7 @@ func Join(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||||
* Example: (substr 1 5 "Linus Torvalds") -> "inus "
|
* Example: (substr 1 5 "Linus Torvalds") -> "inus "
|
||||||
*/
|
*/
|
||||||
func Substr(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
func Substr(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token {
|
||||||
|
start := in
|
||||||
end := start.Next
|
end := start.Next
|
||||||
str := end.Next
|
str := end.Next
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue