From d48983dd6aff569f52659525c3c3d9096ef405bd Mon Sep 17 00:00:00 2001 From: David Majda Date: Mon, 13 Jun 2016 10:21:46 +0200 Subject: [PATCH] Don't use the "i" suffix for case-insensitive class descriptions If the described class is case-sensitive, nothing changes. If the described class is case-insensitive, its description doesn't indicate that anymore. The indication was awkward and it was meaningful only for parser users familiar with PEG.js grammar syntax (typically a minority). For cases where case insensitivity indication is vital, named rules can be used to customize the reporting. Note that literal descriptions already ignore the case-sensitivity flag; this commit only makes things consistent. --- lib/compiler/passes/generate-bytecode.js | 2 +- lib/parser.js | 2 +- spec/unit/compiler/passes/generate-bytecode.spec.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/compiler/passes/generate-bytecode.js b/lib/compiler/passes/generate-bytecode.js index 32997f4..fa4798f 100644 --- a/lib/compiler/passes/generate-bytecode.js +++ b/lib/compiler/passes/generate-bytecode.js @@ -632,7 +632,7 @@ function generateBytecode(ast) { + classDescriptionEscape(part[1]) : classDescriptionEscape(part); }).join("") - + "]" + (node.ignoreCase ? "i" : ""); + + "]"; regexpIndex = addConst(regexp); expectedIndex = addConst([ diff --git a/lib/parser.js b/lib/parser.js index e5947cc..c3a07f1 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -288,7 +288,7 @@ peg$c129 = /^[0-9]/, peg$c130 = { type: "class", value: "[0-9]", description: "[0-9]" }, peg$c131 = /^[0-9a-f]/i, - peg$c132 = { type: "class", value: "[0-9a-f]i", description: "[0-9a-f]i" }, + peg$c132 = { type: "class", value: "[0-9a-f]i", description: "[0-9a-f]" }, peg$c133 = ".", peg$c134 = { type: "literal", value: ".", description: "\".\"" }, peg$c135 = function() { return { type: "any", location: location() }; }, diff --git a/spec/unit/compiler/passes/generate-bytecode.spec.js b/spec/unit/compiler/passes/generate-bytecode.spec.js index 1995b9c..9fdad43 100644 --- a/spec/unit/compiler/passes/generate-bytecode.spec.js +++ b/spec/unit/compiler/passes/generate-bytecode.spec.js @@ -616,7 +616,7 @@ describe("compiler pass |generateBytecode|", function() { it("defines correct constants", function() { expect(pass).toChangeAST('start = [a]i', constsDetails([ '/^[a]/i', - '{ type: "class", value: "[a]i", description: "[a]i" }' + '{ type: "class", value: "[a]i", description: "[a]" }' ])); }); });