all: getting closer to being able to read the stdlib

This commit is contained in:
2018-05-15 04:05:25 +02:00
parent a136959423
commit 0f19b677a2
2 changed files with 43 additions and 22 deletions

View File

@@ -30,6 +30,7 @@ func tokenize(input string) []string {
withoutComments := string(comments.ReplaceAll([]byte(input), []byte("")))
explodedParens := explode(withoutComments, "(", ")")
explodedBrackets := explode(explodedParens, "[", "]")
// TODO this consumes multiple spaces
return withoutEmpty(whitespace.Split(explodedBrackets, -1))
}
@@ -75,7 +76,8 @@ func parseValue(input []string) (*ast.AST, error, []string) {
}
if input[0][0] == '"' {
var agg []string
agg := []string{input[0]}
input = input[1:]
for {
if len(input) == 0 {
return nil, errors.New("Unmatched \""), input
@@ -233,3 +235,23 @@ func parseToken(input []string) (*ast.AST, error, []string) {
func Parse(input string) (*ast.AST, error, []string) {
return parseToken(tokenize(input))
}
func ParseAll(input string) ([]*ast.AST, error) {
tokens := tokenize(input)
var res []*ast.AST
for {
if len(tokens) == 0 {
break
}
parsed, err, unconsumed := parseToken(tokens)
if err != nil {
return res, err
}
res = append(res, parsed)
tokens = unconsumed
}
return res, nil
}