]> ocean-lang.org Git - ocean/commitdiff
scanner: fix parsing of comments.
authorNeilBrown <neil@brown.name>
Sun, 11 Feb 2018 08:07:55 +0000 (19:07 +1100)
committerNeilBrown <neil@brown.name>
Tue, 13 Feb 2018 02:23:07 +0000 (13:23 +1100)
If '/' is a known mark, then "//" and "/*" comments don't get
parsed properly.  Add handling for this case.

Signed-off-by: NeilBrown <neil@brown.name>
csrc/scanner.mdc

index d15b44b88d200984552805d856d50e3ff8730e85..5480faaf6dddf21105fcafd383962acd6ddb703b 100644 (file)
@@ -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<<TK_string)) && is_quote(ch))
                        break;
-               if (prev == '#')
+               if (prev == '#' && n < 0)
+                       /* '#' is not a known mark, so assume it is a comment */
                        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;
                }
-               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;
                }