Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable the RegExp u flag #631

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/nearley-language-bootstrapped.js
Original file line number Diff line number Diff line change
@@ -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]; }
Expand Down Expand Up @@ -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 [ ].
Expand All @@ -64,7 +64,7 @@ function insensitive(sl) {
for (var i=0; i<s.length; i++) {
var c = s.charAt(i);
if (c.toUpperCase() !== c || c.toLowerCase() !== c) {
result.push(new RegExp("[" + c.toLowerCase() + c.toUpperCase() + "]"));
result.push(new RegExp("[" + c.toLowerCase() + c.toUpperCase() + "]", 'u'));
} else {
result.push({literal: c});
}
Expand Down
4 changes: 2 additions & 2 deletions lib/nearley-language-bootstrapped.ne
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,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 [ ].
Expand All @@ -61,7 +61,7 @@ function insensitive(sl) {
for (var i=0; i<s.length; i++) {
var c = s.charAt(i);
if (c.toUpperCase() !== c || c.toLowerCase() !== c) {
result.push(new RegExp("[" + c.toLowerCase() + c.toUpperCase() + "]"));
result.push(new RegExp("[" + c.toLowerCase() + c.toUpperCase() + "]", 'u'));
} else {
result.push({literal: c});
}
Expand Down
8 changes: 4 additions & 4 deletions test/bootstrap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ describe('bootstrapped lexer', () => {

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",
])
})

Expand All @@ -94,7 +94,7 @@ describe('bootstrapped lexer', () => {
expect(lex("foo[[0-9]]")).toEqual([
"word foo",
"[ [",
"charclass /[0-9]/",
"charclass /[0-9]/u",
"] ]",
])
})
Expand Down
4 changes: 2 additions & 2 deletions test/grammars/scannerless-nearley.ne
Original file line number Diff line number Diff line change
Expand Up @@ -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]]); } %}
Expand Down
4 changes: 2 additions & 2 deletions test/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:",
Expand Down