Skip to content

Commit f5e82ec

Browse files
committed
drop support for legacy \r newline sequence
1 parent 48f48d8 commit f5e82ec

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

dictionary/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const WORDS = new RegExp(`[^${escapeRegex(RESERVED_SYMBOLS)}]`);
3939
function lex<T>(parser: Parser<T>): Parser<T> {
4040
return parser.skip(spaces);
4141
}
42-
const comment = match(/#[^\n\r]*/, "comment");
42+
const comment = match(/#[^\n]*\n?/, "comment");
4343
const spaces = sourceOnly(all(choiceOnlyOne(match(/\s/, "space"), comment)));
4444
const backtick = matchString("`", "backtick");
4545
const colon = matchString(":", "colon");

src/misc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { distinctBy } from "@std/collections/distinct-by";
22
import { escape } from "@std/regexp/escape";
33
import { Lazy } from "./cache.ts";
44

5-
export const NEWLINES = /\r\n|\n|\r/g;
5+
export const NEWLINES = /\r?\n/g;
66

77
export function nullableAsArray<T>(value?: T): ReadonlyArray<NonNullable<T>> {
88
if (value == null) {

src/parser/lexer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ import {
4242
} from "./ucsur.ts";
4343
import { throwError } from "../misc.ts";
4444

45-
const spacesWithoutNewline = match(/[^\S\n\r]*/, "spaces");
46-
const newline = match(/[\n\r]\s*/, "newline");
45+
const spacesWithoutNewline = match(/[^\S\n]*?(?=\S|\r?\n|$)/, "spaces");
46+
const newline = match(/\r?\n\s*/, "newline");
4747
const spaces = sourceOnly(
4848
sequence(spacesWithoutNewline, choice(nothing, newline)),
4949
);

src/parser/parser_lib.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ function describeSource(src: string): string {
191191
} else {
192192
const [token] = src.match(/\S*/)!;
193193
if (token === "") {
194-
if (/^[\n\r]/.test(src)) {
194+
if (/^\r?\n/.test(src)) {
195195
return "newline";
196196
} else {
197197
return "space";

0 commit comments

Comments
 (0)