From 34dc898fde1562d4e31102c260755956d6c0eb4a Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Fri, 19 Aug 2016 21:53:25 +0200 Subject: Handle quoting of lists --- code.lysp | 2 +- main.c | 1 - parser.c | 16 ++++++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/code.lysp b/code.lysp index cebf2e1..1e82fa1 100644 --- a/code.lysp +++ b/code.lysp @@ -1 +1 @@ -(print (+ 1 (% 10 3)) 'kaas "kazen enzo") +(print (+ 1 (% 10 3)) () '(()) (('())) 'kaas "kazen enzo") diff --git a/main.c b/main.c index c3a5618..239e938 100644 --- a/main.c +++ b/main.c @@ -79,7 +79,6 @@ int main(int argc,char **argv){ return 1; } assert(pr.ast); - printf("%p\n",pr.ast); char *s=ast_stringify(pr.ast); printf("%s\n",s); free(s); diff --git a/parser.c b/parser.c index d91af7e..bab19a7 100644 --- a/parser.c +++ b/parser.c @@ -59,7 +59,8 @@ static Token nexttoken(Cursor *cursor){ while(cursor->l>=1&&isspace(*cursor->s))advance(cursor,1); if(cursor->l==0)return tt_eof(); - if(strchr(SYMBOLCHARS,*cursor->s)!=NULL){ + if(strchr(SYMBOLCHARS,*cursor->s)!=NULL|| + (cursor->l>=2&&cursor->s[0]=='\''&&strchr(SYMBOLCHARS,cursor->s[1]))){ advance(cursor,1); return tt_make(TT_SYMBOL,cursor->s-1,1); } @@ -140,6 +141,15 @@ static ParseRet parse_(Cursor *cursor){ case TT_SYMBOL:{ char closing; if(tok.len!=1)assert(false); + bool quoted=false; + if(tok.str[0]=='\''){ + quoted=true; + tok=nexttoken(cursor); + if(tok.type!=TT_SYMBOL||tok.len!=1||(tok.str[0]!='('&&tok.str[0]!='[')){ + return pr_err_c("Single quote symbol not before paren"); + } + } + if(tok.str[0]=='(')closing=')'; else if(tok.str[0]=='[')closing=']'; else if(tok.str[0]==')'||tok.str[0]==']'){ @@ -173,7 +183,9 @@ static ParseRet parse_(Cursor *cursor){ } nodes[len++]=pr.ast; } - return pr_ast(ast_list(len,nodes)); + AST *l=ast_list(len,nodes); + l->l.quoted=quoted; + return pr_ast(l); } case TT_WORD: -- cgit v1.2.3