move expr into its own package, make basic main
This commit is contained in:
parent
ec817b58cd
commit
0de50c47ba
@ -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
|
@ -1,4 +1,4 @@
|
||||
package ginger
|
||||
package expr
|
||||
|
||||
import (
|
||||
. "testing"
|
Loading…
Reference in New Issue
Block a user