all: getting closer to being able to read the stdlib
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user