pattern: fix newline, tab, and carriage return treatment

This commit is contained in:
hellerve 2020-02-09 12:56:13 +01:00
parent f1cff0b889
commit d7cf3982f8
2 changed files with 11 additions and 15 deletions

View File

@ -304,20 +304,16 @@ init: /* using goto's to optimize tail recursion */
s = NULL; /* match failed */
break;
}
case 'n': { /* newline? */
if (*s == '\r') {
if (*(++s) == '\n') s++;
} else if (*s == '\n')
s++;
else
s = NULL;
break;
}
case 'r': /* carriage return? */
case 'n': /* newline? */
case 't': { /* tab? */
if (*s == '\t')
s++;
else
s = NULL;
char h = *(p + 1);
p += 2;
if ( (*s == '\r' && h == 'r')
|| (*s == '\n' && h == 'n')
|| (*s == '\t' && h == 't')
) { s++; goto init; }
else s = NULL;
break;
}
case '0':

View File

@ -110,8 +110,8 @@ parseInternalPattern = do maybeAnchor <- Parsec.optionMaybe (Parsec.char '^')
_ <- Parsec.char '\\'
c <- Parsec.oneOf ['1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'c', 'd', 'g', 'l', 'p', 's', 'u', 'w',
'x', 'n', 't', 'b', 'f', '[', ']', '\\', '$',
'(', ')', '^', '"', '*', '.', '-']
'x', 'n', 'r', 't', 'b', 'f', '[', ']', '\\',
'$', '(', ')', '^', '"', '*', '.', '-']
case c of
'b' -> do c1 <- Parsec.noneOf ['"']
c2 <- Parsec.noneOf ['"']