aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-09-01 09:31:49 +0200
committerlemon <lsof@mailbox.org>2022-09-01 09:31:49 +0200
commit95b02a948385370092bae845a83fd5f14af82438 (patch)
tree001483cbe9a015d6bde56f051dd62a88ac88d7ec /src
parent3bbbacae5c7deb27b2125bbfb47d8ce73ca56bb0 (diff)
relax block comment lexing requirements
Diffstat (limited to 'src')
-rw-r--r--src/cffc.hff1
-rw-r--r--src/parse.cff26
2 files changed, 25 insertions, 2 deletions
diff --git a/src/cffc.hff b/src/cffc.hff
index 135e8d8..6ae2c6d 100644
--- a/src/cffc.hff
+++ b/src/cffc.hff
@@ -149,6 +149,7 @@ struct Parser {
curloc Loc,
eof bool,
error bool,
+ is_comment bool,
is_header bool,
peekchr Option<int>,
peektok Option<Tok>,
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 {