macro: defining macros works

This commit is contained in:
2018-05-15 00:00:30 +02:00
parent 702bd703b9
commit 616e531ddd
3 changed files with 91 additions and 4 deletions

21
main.go
View File

@@ -10,6 +10,7 @@ import (
"github.com/chzyer/readline"
"github.com/hellerve/argos/eval"
"github.com/hellerve/argos/macro"
"github.com/hellerve/argos/parser"
)
@@ -23,6 +24,7 @@ func runRepl() {
defer rl.Close()
e := eval.RootEnv()
m := macro.NewMacroEnv()
for {
input, err := rl.Readline()
@@ -46,8 +48,15 @@ func runRepl() {
continue
}
expanded, err := macro.Expand(parsed, m)
if err != nil {
fmt.Println(err)
continue
}
// TODO: how to avoid bindings on error?
evald, err := eval.Eval(parsed, e)
evald, err := eval.Eval(expanded, e)
if err != nil {
fmt.Println(err)
@@ -60,6 +69,7 @@ func runRepl() {
func runFile(path string) {
e := eval.RootEnv()
m := macro.NewMacroEnv()
input, err := ioutil.ReadFile(path)
if err != nil {
@@ -79,7 +89,14 @@ func runFile(path string) {
return
}
evald, err := eval.Eval(parsed, e)
expanded, err := macro.Expand(parsed, m)
if err != nil {
fmt.Println(err)
return
}
evald, err := eval.Eval(expanded, e)
if err != nil {
fmt.Println(err)