Fix the reader bug in readUnquotedExpr function

This commit is contained in:
Sameer Rahmani 2020-11-14 11:02:09 +00:00
parent 1bd3a41fb6
commit 70bb8d1997
2 changed files with 14 additions and 8 deletions

View File

@ -44,7 +44,7 @@ for details take a look at the LICENSE file.
`,
Run: func(cmd *cobra.Command, args []string) {
reader.ReadString("sameer mary")
ast, _ := parser.ParseToAST("(asd mary)")
ast, _ := parser.ParseToAST("(asd 'mary '(1 2 3) `(asd ~asd ~@zxc))")
fmt.Printf("%s\n", ast.String())
},
}

View File

@ -211,17 +211,23 @@ func readUnquotedExpr(parser IParsable) (types.IExpr, error) {
}
var sym types.IExpr
expr, err := readExpr(parser)
var err error
var expr types.IExpr
if *c == "@" {
parser.next(true)
sym = types.MakeSymbol("unquote-splicing")
expr, err = readExpr(parser)
} else {
sym = types.MakeSymbol("unquote")
expr, err = readExpr(parser)
}
if err != nil {
return nil, err
}
if *c == "@" {
sym = types.MakeSymbol("unquote-splicing")
} else {
sym = types.MakeSymbol("unquote")
}
return types.MakeList([]types.IExpr{sym, expr}), nil
}