From 982806fd5ddfd85ee6f0b82b528520c607de4113 Mon Sep 17 00:00:00 2001 From: Mark Andrus Roberts Date: Sat, 11 Mar 2023 22:51:32 +0100 Subject: [PATCH] Enable the RegExp `u` flag --- lib/nearley-language-bootstrapped.js | 6 +++--- lib/nearley-language-bootstrapped.ne | 4 ++-- test/bootstrap.test.js | 8 ++++---- test/grammars/scannerless-nearley.ne | 4 ++-- test/parser.test.js | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/nearley-language-bootstrapped.js b/lib/nearley-language-bootstrapped.js index 267f04ee..0ede59c3 100644 --- a/lib/nearley-language-bootstrapped.js +++ b/lib/nearley-language-bootstrapped.js @@ -1,4 +1,4 @@ -// Generated automatically by nearley, version 2.19.5 +// Generated automatically by nearley, version 2.20.1 // http://github.com/Hardmath123/nearley (function () { function id(x) { return x[0]; } @@ -48,7 +48,7 @@ var lexer = moo.states({ main: Object.assign({}, rules, { charclass: { match: /\.|\[(?:\\.|[^\\\n])+?\]/, - value: x => new RegExp(x), + value: x => new RegExp(x, 'u'), }, }), // Both macro arguments and charclasses are both enclosed in [ ]. @@ -64,7 +64,7 @@ function insensitive(sl) { for (var i=0; i new RegExp(x), + value: x => new RegExp(x, 'u'), }, }), // Both macro arguments and charclasses are both enclosed in [ ]. @@ -61,7 +61,7 @@ function insensitive(sl) { for (var i=0; i { it('lexes charclasses', () => { expect(lex(".")).toEqual([ - "charclass /./", + "charclass /./u", ]) expect(lex("[^a-z\\s]")).toEqual([ - "charclass /[^a-z\\s]/", + "charclass /[^a-z\\s]/u", ]) expect(lex("foo->[^a-z\\s]")).toEqual([ "word foo", "arrow ->", - "charclass /[^a-z\\s]/", + "charclass /[^a-z\\s]/u", ]) }) @@ -94,7 +94,7 @@ describe('bootstrapped lexer', () => { expect(lex("foo[[0-9]]")).toEqual([ "word foo", "[ [", - "charclass /[0-9]/", + "charclass /[0-9]/u", "] ]", ]) }) diff --git a/test/grammars/scannerless-nearley.ne b/test/grammars/scannerless-nearley.ne index f4462160..d03e2f8b 100644 --- a/test/grammars/scannerless-nearley.ne +++ b/test/grammars/scannerless-nearley.ne @@ -70,8 +70,8 @@ string -> dqstring {% function(d) {return { literal: d[0] }; } %} #char -> [^\\"] {% function(d) { return d[0]; } %} # | "\\" . {% function(d) { return JSON.parse("\""+"\\"+d[1]+"\""); } %} -charclass -> "." {% function(d) { return new RegExp("."); } %} - | "[" charclassmembers "]" {% function(d) { return new RegExp("[" + d[1].join('') + "]"); } %} +charclass -> "." {% function(d) { return new RegExp(".", 'u'); } %} + | "[" charclassmembers "]" {% function(d) { return new RegExp("[" + d[1].join('') + "]", 'u'); } %} charclassmembers -> null | charclassmembers charclassmember {% function(d) { return d[0].concat([d[1]]); } %} diff --git a/test/parser.test.js b/test/parser.test.js index 165b3fc1..832d2e04 100644 --- a/test/parser.test.js +++ b/test/parser.test.js @@ -50,8 +50,8 @@ describe('Parser: API', function() { "", "Unexpected \"!\". Instead, I was expecting to see one of the following:", "", - "A character matching /[a-z0-9]/ based on:", - " x → ● /[a-z0-9]/", + "A character matching /[a-z0-9]/u based on:", + " x → ● /[a-z0-9]/u", " y$ebnf$1 → y$ebnf$1 ● x", " y → ● y$ebnf$1", "A \"\\n\" based on:",