From 66ed623e65ab9350f08061fe7cf12b989c84f65c Mon Sep 17 00:00:00 2001 From: lemon Date: Sun, 14 Aug 2022 07:30:39 +0200 Subject: better comment syntax --- bootstrap/parse.c | 27 +++++++++++++-------------- misc/cff.vim | 4 ++-- src/set.hff | 4 +--- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/bootstrap/parse.c b/bootstrap/parse.c index 8707709..75a3279 100644 --- a/bootstrap/parse.c +++ b/bootstrap/parse.c @@ -370,9 +370,20 @@ lex(struct parser *P) { } else if (c == '#') { char s[100]; - if (readtilhsep(P, s, sizeof s, 0) < 0) + if (readtilhsep(P, s, sizeof s, 0) < 0) { fatal(P, P->tokspan, "invalid #keyword"); - else if (!strcmp(s, "#")) { + } else if (!strcmp(s, "#") && chrpeek(P) == '{') { + chr(P); + int bal = 1; + while (bal != 0) { + switch (lex(P).t) { + case '{': ++bal; break; + case '}': --bal; break; + case TKeof: fatal(P, tok.span, "unterminated comment"); + } + } + return lex(P); + } else if (!strcmp(s, "#")) { tok.t = '#'; } else if (!strcmp(s, "#t") || !strcmp(s, "#f")) { tok.t = TKboolit; @@ -394,18 +405,6 @@ lex(struct parser *P) { tok.t = '#FIL'; } else if (!strcmp(s, "#LINE")) { tok.t = '#LIN'; - } else if (!strcmp(s, "#!")) { - if (chr(P) != '{') fatal(P, P->tokspan, "expected '{' after '#!'"); - int bal = 1; - while (bal != 0) { - switch (lex(P).t) { - case '{': ++bal; break; - case '}': --bal; break; - case TKeof: fatal(P, tok.span, "unterminated comment"); - } - } - return lex(P); - } else { fatal(P, P->tokspan, "invalid #keyword"); } diff --git a/misc/cff.vim b/misc/cff.vim index 3e0b3b8..49ab137 100644 --- a/misc/cff.vim +++ b/misc/cff.vim @@ -31,6 +31,6 @@ syn match cFloat display contained "\d\+\.\d*\%(f\|f32\|f64\)\?\>" syn region String start=+"+ skip=+\\\\\|\\"+ end=+"+ extend syn region Character start=+'+ skip=+\\\\\|\\'+ end=+'+ extend syn region Comment start="//" end="$" -syn region mComment start="#!{" end="}" contains=mComment,mCommentBraces,String,Character -syn region mCommentBraces contained start=+[^'"!]{+ end="}" contains=mCommentBraces,String +syn region mComment start="#{" end="}" contains=mComment,mCommentBraces,String,Character +syn region mCommentBraces contained start=+[^'"#]{+ end="}" contains=mCommentBraces,String hi link mComment Comment diff --git a/src/set.hff b/src/set.hff index 396d63c..4e4b72c 100644 --- a/src/set.hff +++ b/src/set.hff @@ -1,9 +1,7 @@ import "vec.hff"; import "all.hff"; - - -#!{ KTraits: +#{ KTraits: :hash(K) u32 :eq(T, T) bool :dup(T) T } -- cgit v1.2.3