From eade4187ba0ae04fe8e6eed9a1e33bfd44b73c06 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 20 Aug 2016 13:34:15 +0200 Subject: Parse comments --- code.lysp | 8 +++++++- parser.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/code.lysp b/code.lysp index 1e82fa1..47a0268 100644 --- a/code.lysp +++ b/code.lysp @@ -1 +1,7 @@ -(print (+ 1 (% 10 3)) () '(()) (('())) 'kaas "kazen enzo") +(print + (+ 1 (% 10 3)) + () + '( #| dit is commentaar|# ()) + (('())) + 'kaas ;meer commentaar + "kazen enzo") diff --git a/parser.c b/parser.c index bab19a7..910f3da 100644 --- a/parser.c +++ b/parser.c @@ -59,6 +59,39 @@ static Token nexttoken(Cursor *cursor){ while(cursor->l>=1&&isspace(*cursor->s))advance(cursor,1); if(cursor->l==0)return tt_eof(); + bool acted; + do { + acted=false; + if(*cursor->s==';'){ + acted=true; + int i; + for(i=1;il;i++){ + if(cursor->s[i]=='\n')break; + } + if(i>=cursor->l-1){ + advance(cursor,cursor->l); + return tt_eof(); + } + advance(cursor,i+1); + } + + if(cursor->l>=4&&cursor->s[0]=='#'&&cursor->s[1]=='|'){ + acted=true; + int i; + for(i=3;il;i++){ + if(cursor->s[i-1]=='|'&&cursor->s[i]=='#')break; + } + if(i>=cursor->l-1){ + advance(cursor,cursor->l); + return tt_eof(); + } + advance(cursor,i+1); + } + } while(acted); + + while(cursor->l>=1&&isspace(*cursor->s))advance(cursor,1); + if(cursor->l==0)return tt_eof(); + if(strchr(SYMBOLCHARS,*cursor->s)!=NULL|| (cursor->l>=2&&cursor->s[0]=='\''&&strchr(SYMBOLCHARS,cursor->s[1]))){ advance(cursor,1); -- cgit v1.2.3