diff options
author | tomsmeding <tom.smeding@gmail.com> | 2016-08-19 21:53:25 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2016-08-19 21:53:25 +0200 |
commit | 34dc898fde1562d4e31102c260755956d6c0eb4a (patch) | |
tree | 615783f0c83b4234551a999e8a0897ac44d55ed0 | |
parent | c9127b2bd399ce5d3e9483a82434948202592309 (diff) |
Handle quoting of lists
-rw-r--r-- | code.lysp | 2 | ||||
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | parser.c | 16 |
3 files changed, 15 insertions, 4 deletions
@@ -1 +1 @@ -(print (+ 1 (% 10 3)) 'kaas "kazen enzo") +(print (+ 1 (% 10 3)) () '(()) (('())) 'kaas "kazen enzo") @@ -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); @@ -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: |