summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2016-08-19 21:53:25 +0200
committertomsmeding <tom.smeding@gmail.com>2016-08-19 21:53:25 +0200
commit34dc898fde1562d4e31102c260755956d6c0eb4a (patch)
tree615783f0c83b4234551a999e8a0897ac44d55ed0
parentc9127b2bd399ce5d3e9483a82434948202592309 (diff)
Handle quoting of lists
-rw-r--r--code.lysp2
-rw-r--r--main.c1
-rw-r--r--parser.c16
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: