aboutsummaryrefslogtreecommitdiff
path: root/src/parse.cff
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse.cff')
-rw-r--r--src/parse.cff26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/parse.cff b/src/parse.cff
index f5beb23..ce32475 100644
--- a/src/parse.cff
+++ b/src/parse.cff
@@ -339,6 +339,10 @@ fn lex(P *Parser) Tok {
tok.loc = (P.tokloc = P.curloc);
if isdigit(c = chrpeek(P)) {
let s [80]u8 = {};
+ if P.is_comment {
+ readtilsep(P, s[0::], #t);
+ return tok;
+ }
if readtilsep(P, s[0::], #t) < 0 {
fatal(P, tok.loc, "bad number literal");
}
@@ -352,6 +356,10 @@ fn lex(P *Parser) Tok {
}
if isalpha(c) or c == '_' or c == '$' or c > 0x7F {
let s [120]u8;
+ if P.is_comment {
+ readtilsep(P, s[0::], #t);
+ return tok;
+ }
if readtilsep(P, s[0::], #f) < 0 {
fatal(P, tok.loc, "identifier too long");
}
@@ -370,12 +378,18 @@ fn lex(P *Parser) Tok {
}
if c == '#' {
let s [100]u8 = {};
+ if P.is_comment {
+ readtilhsep(P, s[0::], #t);
+ return tok;
+ }
if readtilhsep(P, s[0::], #f) < 0 {
fatal(P, P.tokloc, "invalid #keyword");
}
switch {
case streq(s, "#") and chrpeek(P) == '{';
chr(P);
+ let is_comment = P.is_comment;
+ P.is_comment = #t;
let bal = 1;
while bal != 0 {
switch lex(P).t {
@@ -384,6 +398,7 @@ fn lex(P *Parser) Tok {
case :eof; fatal(P, tok.loc, "unterminated comment");
}
}
+ P.is_comment = is_comment;
return lex(P);
case streq(s, "#");
tok.t = '#';
@@ -428,9 +443,12 @@ fn lex(P *Parser) Tok {
delim == '"' ? "string" : "character");
}
if c != '\\' {
- str->push(c);
+ if !P.is_comment {
+ str->push(c);
+ }
continue;
}
+ if P.is_comment { continue; }
switch ((c = chr(P))) {
case 0, '\n';
fatal(P, P.tokloc, "unterminated %s literal",
@@ -452,6 +470,8 @@ fn lex(P *Parser) Tok {
}
}
+ if P.is_comment { return tok; }
+
if delim == '"' {
tok.t = :str;
str->push('\0');
@@ -556,7 +576,9 @@ fn lex(P *Parser) Tok {
tok.t = :eof;
return tok;
}
- fatal(P, tok.loc, "stray %qc in program", c);
+ if !P.is_comment {
+ fatal(P, tok.loc, "stray %qc in program", c);
+ }
}
fn lexpeek(P *Parser) Tok {