From: NeilBrown Date: Sun, 11 Feb 2018 08:07:55 +0000 (+1100) Subject: scanner: fix parsing of comments. X-Git-Tag: StoneyCreek~18 X-Git-Url: https://ocean-lang.org/code/?a=commitdiff_plain;h=81cb9488cd8593154b3a33303c62778d0a0db961;p=ocean scanner: fix parsing of comments. If '/' is a known mark, then "//" and "/*" comments don't get parsed properly. Add handling for this case. Signed-off-by: NeilBrown --- diff --git a/csrc/scanner.mdc b/csrc/scanner.mdc index d15b44b..5480faa 100644 --- a/csrc/scanner.mdc +++ b/csrc/scanner.mdc @@ -344,7 +344,16 @@ Known marks are included in the same list as the list of known words. if (n >= 0) tk.num = TK_reserved + n; else if (tk.num != TK_error) { - /* found a longest-known-mark */ + /* found a longest-known-mark, still need to + * check for comments + */ + if (tk.txt.len == 2 && tk.txt.txt[0] == '/' && + (ch == '/' || ch == '*')) { + /* Yes, this is a comment, not a '/' */ + restore_unget_state(state); + tk.num = TK_error; + break; + } unget_char(state); close_token(state, &tk); return tk; @@ -354,13 +363,16 @@ Known marks are included in the same list as the list of known words. ch = get_char(state); if (!(ignored && (1< 1) { + if (prev == '/' && ch == '/' && tk.txt.len == 1 && n < 0) { + close_token(state, &tk); restore_unget_state(state); break; } - if (prev == '/' && ch == '*' && tk.txt.len > 1) { + if (prev == '/' && ch == '*' && tk.txt.len == 1 && n < 0) { + close_token(state, &tk); restore_unget_state(state); break; }