From 81cb9488cd8593154b3a33303c62778d0a0db961 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sun, 11 Feb 2018 19:07:55 +1100 Subject: [PATCH] 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 --- csrc/scanner.mdc | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) 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; } -- 2.43.0