move expr into its own package, make basic main

This commit is contained in:
Brian Picciano 2016-07-23 11:06:26 -06:00
parent ec817b58cd
commit 0de50c47ba
3 changed files with 38 additions and 2 deletions

View File

@ -1,4 +1,4 @@
package ginger
package expr
import (
"fmt"
@ -272,6 +272,24 @@ func sliceEnclosedToks(toks []lexer.Token, start, end lexer.Token) ([]lexer.Toke
}
}
func Parse(r io.Reader) ([]Expr, error) {
toks := readAllToks(r)
var ret []Expr
var expr Expr
var err error
for len(toks) > 0 {
if toks[0].TokenType == lexer.EOF {
return ret, nil
}
expr, toks, err = parse(toks)
if err != nil {
return nil, err
}
ret = append(ret, expr)
}
return ret, nil
}
func readAllToks(r io.Reader) []lexer.Token {
l := lexer.New(r)
var toks []lexer.Token

View File

@ -1,4 +1,4 @@
package ginger
package expr
import (
. "testing"

18
main.go Normal file
View File

@ -0,0 +1,18 @@
package main
import (
"fmt"
"os"
"github.com/mediocregopher/ginger/expr"
)
func main() {
ee, err := expr.Parse(os.Stdin)
if err != nil {
panic(err)
}
for _, e := range ee {
fmt.Println(e)
}
}