Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add support for escaped quotes and apostrophes in striings #442

Merged
merged 1 commit into from

1 participant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 20, 2012
  1. @s3u

    Support escaped quotes

    s3u authored
This page is out of date. Refresh to see the latest.
View
4 CHANGES.md
@@ -1,3 +1,7 @@
+## Apr 20, 2012
+
+* Add support for escaped quotes in string values
+
## Apr 19, 2012
* Updated PEG.js to 0.7. I see 50% improvement in speed which matters for string and uri templates
View
698 modules/compiler/lib/peg/ql.js
@@ -161,13 +161,16 @@ module.exports = (function(){
"Indexed": parse_Indexed,
"Expr": parse_Expr,
"ExprBlock": parse_ExprBlock,
- "StringLiteral": parse_StringLiteral,
"Identifier": parse_Identifier,
"Descendent": parse_Descendent,
"Selector": parse_Selector,
"PositiveNumber": parse_PositiveNumber,
+ "StringLiteral": parse_StringLiteral,
+ "DoubleString": parse_DoubleString,
"SingleString": parse_SingleString,
- "DoubleString": parse_DoubleString
+ "dchar": parse_dchar,
+ "achar": parse_achar,
+ "hexDigit": parse_hexDigit
};
if (startRule !== undefined) {
@@ -6286,96 +6289,6 @@ module.exports = (function(){
return result0;
}
- function parse_StringLiteral() {
- var result0, result1, result2;
- var pos0, pos1;
-
- pos0 = clone(pos);
- pos1 = clone(pos);
- if (input.charCodeAt(pos.offset) === 34) {
- result0 = "\"";
- advance(pos, 1);
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"\\\"\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_DoubleString();
- if (result1 !== null) {
- if (input.charCodeAt(pos.offset) === 34) {
- result2 = "\"";
- advance(pos, 1);
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"\\\"\"");
- }
- }
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = clone(pos1);
- }
- } else {
- result0 = null;
- pos = clone(pos1);
- }
- } else {
- result0 = null;
- pos = clone(pos1);
- }
- if (result0 === null) {
- pos1 = clone(pos);
- if (input.charCodeAt(pos.offset) === 39) {
- result0 = "'";
- advance(pos, 1);
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"'\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_SingleString();
- if (result1 !== null) {
- if (input.charCodeAt(pos.offset) === 39) {
- result2 = "'";
- advance(pos, 1);
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"'\"");
- }
- }
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = clone(pos1);
- }
- } else {
- result0 = null;
- pos = clone(pos1);
- }
- } else {
- result0 = null;
- pos = clone(pos1);
- }
- }
- if (result0 !== null) {
- result0 = (function(offset, line, column, parts) {
- return '"' + parts[1] + '"';
- })(pos0.offset, pos0.line, pos0.column, result0);
- }
- if (result0 === null) {
- pos = clone(pos0);
- }
- return result0;
- }
-
function parse_Identifier() {
var result0, result1, result2;
var pos0, pos1;
@@ -6537,100 +6450,108 @@ module.exports = (function(){
return result0;
}
- function parse_SingleString() {
- var result0, result1;
- var pos0;
+ function parse_StringLiteral() {
+ var result0, result1, result2;
+ var pos0, pos1;
pos0 = clone(pos);
- result0 = [];
- if (/^[ -&]/.test(input.charAt(pos.offset))) {
- result1 = input.charAt(pos.offset);
+ pos1 = clone(pos);
+ if (input.charCodeAt(pos.offset) === 34) {
+ result0 = "\"";
advance(pos, 1);
} else {
- result1 = null;
+ result0 = null;
if (reportFailures === 0) {
- matchFailed("[ -&]");
+ matchFailed("\"\\\"\"");
}
}
- if (result1 === null) {
- if (/^[(-[]/.test(input.charAt(pos.offset))) {
- result1 = input.charAt(pos.offset);
- advance(pos, 1);
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("[(-[]");
- }
- }
- if (result1 === null) {
- if (/^[\]-\uFFFF]/.test(input.charAt(pos.offset))) {
- result1 = input.charAt(pos.offset);
+ if (result0 !== null) {
+ result1 = parse_DoubleString();
+ if (result1 !== null) {
+ if (input.charCodeAt(pos.offset) === 34) {
+ result2 = "\"";
advance(pos, 1);
} else {
- result1 = null;
+ result2 = null;
if (reportFailures === 0) {
- matchFailed("[\\]-\\uFFFF]");
+ matchFailed("\"\\\"\"");
}
}
- if (result1 === null) {
- if (/^[\\"]/.test(input.charAt(pos.offset))) {
- result1 = input.charAt(pos.offset);
- advance(pos, 1);
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("[\\\\\"]");
- }
- }
+ if (result2 !== null) {
+ result0 = [result0, result1, result2];
+ } else {
+ result0 = null;
+ pos = clone(pos1);
}
+ } else {
+ result0 = null;
+ pos = clone(pos1);
}
+ } else {
+ result0 = null;
+ pos = clone(pos1);
}
- while (result1 !== null) {
- result0.push(result1);
- if (/^[ -&]/.test(input.charAt(pos.offset))) {
- result1 = input.charAt(pos.offset);
+ if (result0 === null) {
+ pos1 = clone(pos);
+ if (input.charCodeAt(pos.offset) === 39) {
+ result0 = "'";
advance(pos, 1);
} else {
- result1 = null;
+ result0 = null;
if (reportFailures === 0) {
- matchFailed("[ -&]");
+ matchFailed("\"'\"");
}
}
- if (result1 === null) {
- if (/^[(-[]/.test(input.charAt(pos.offset))) {
- result1 = input.charAt(pos.offset);
- advance(pos, 1);
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("[(-[]");
- }
- }
- if (result1 === null) {
- if (/^[\]-\uFFFF]/.test(input.charAt(pos.offset))) {
- result1 = input.charAt(pos.offset);
+ if (result0 !== null) {
+ result1 = parse_SingleString();
+ if (result1 !== null) {
+ if (input.charCodeAt(pos.offset) === 39) {
+ result2 = "'";
advance(pos, 1);
} else {
- result1 = null;
+ result2 = null;
if (reportFailures === 0) {
- matchFailed("[\\]-\\uFFFF]");
+ matchFailed("\"'\"");
}
}
- if (result1 === null) {
- if (/^[\\"]/.test(input.charAt(pos.offset))) {
- result1 = input.charAt(pos.offset);
- advance(pos, 1);
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("[\\\\\"]");
- }
- }
+ if (result2 !== null) {
+ result0 = [result0, result1, result2];
+ } else {
+ result0 = null;
+ pos = clone(pos1);
}
+ } else {
+ result0 = null;
+ pos = clone(pos1);
}
+ } else {
+ result0 = null;
+ pos = clone(pos1);
}
}
if (result0 !== null) {
+ result0 = (function(offset, line, column, parts) {
+ return '"' + parts[1] + '"';
+ })(pos0.offset, pos0.line, pos0.column, result0);
+ }
+ if (result0 === null) {
+ pos = clone(pos0);
+ }
+ return result0;
+ }
+
+ function parse_DoubleString() {
+ var result0, result1;
+ var pos0;
+
+ pos0 = clone(pos);
+ result0 = [];
+ result1 = parse_dchar();
+ while (result1 !== null) {
+ result0.push(result1);
+ result1 = parse_dchar();
+ }
+ if (result0 !== null) {
result0 = (function(offset, line, column, c) {
return c.join('');
})(pos0.offset, pos0.line, pos0.column, result0);
@@ -6641,106 +6562,461 @@ module.exports = (function(){
return result0;
}
- function parse_DoubleString() {
+ function parse_SingleString() {
var result0, result1;
var pos0;
pos0 = clone(pos);
result0 = [];
- if (/^[ -!]/.test(input.charAt(pos.offset))) {
- result1 = input.charAt(pos.offset);
+ result1 = parse_achar();
+ while (result1 !== null) {
+ result0.push(result1);
+ result1 = parse_achar();
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, line, column, c) {
+ return c.join('');
+ })(pos0.offset, pos0.line, pos0.column, result0);
+ }
+ if (result0 === null) {
+ pos = clone(pos0);
+ }
+ return result0;
+ }
+
+ function parse_dchar() {
+ var result0, result1, result2, result3, result4;
+ var pos0, pos1;
+
+ if (/^[^"\\\0-\x1F]/.test(input.charAt(pos.offset))) {
+ result0 = input.charAt(pos.offset);
advance(pos, 1);
} else {
- result1 = null;
+ result0 = null;
if (reportFailures === 0) {
- matchFailed("[ -!]");
+ matchFailed("[^\"\\\\\\0-\\x1F]");
}
}
- if (result1 === null) {
- if (/^[#-[]/.test(input.charAt(pos.offset))) {
- result1 = input.charAt(pos.offset);
- advance(pos, 1);
+ if (result0 === null) {
+ pos0 = clone(pos);
+ if (input.substr(pos.offset, 2) === "\\\"") {
+ result0 = "\\\"";
+ advance(pos, 2);
} else {
- result1 = null;
+ result0 = null;
if (reportFailures === 0) {
- matchFailed("[#-[]");
+ matchFailed("\"\\\\\\\"\"");
}
}
- if (result1 === null) {
- if (/^[\]-\uFFFF]/.test(input.charAt(pos.offset))) {
- result1 = input.charAt(pos.offset);
- advance(pos, 1);
+ if (result0 !== null) {
+ result0 = (function(offset, line, column) { return '"'; })(pos0.offset, pos0.line, pos0.column);
+ }
+ if (result0 === null) {
+ pos = clone(pos0);
+ }
+ if (result0 === null) {
+ pos0 = clone(pos);
+ if (input.substr(pos.offset, 2) === "\\\\") {
+ result0 = "\\\\";
+ advance(pos, 2);
} else {
- result1 = null;
+ result0 = null;
if (reportFailures === 0) {
- matchFailed("[\\]-\\uFFFF]");
+ matchFailed("\"\\\\\\\\\"");
}
}
- if (result1 === null) {
- if (/^[\\']/.test(input.charAt(pos.offset))) {
- result1 = input.charAt(pos.offset);
- advance(pos, 1);
+ if (result0 !== null) {
+ result0 = (function(offset, line, column) { return "\\"; })(pos0.offset, pos0.line, pos0.column);
+ }
+ if (result0 === null) {
+ pos = clone(pos0);
+ }
+ if (result0 === null) {
+ pos0 = clone(pos);
+ if (input.substr(pos.offset, 2) === "\\/") {
+ result0 = "\\/";
+ advance(pos, 2);
} else {
- result1 = null;
+ result0 = null;
if (reportFailures === 0) {
- matchFailed("[\\\\']");
+ matchFailed("\"\\\\/\"");
+ }
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, line, column) { return "/"; })(pos0.offset, pos0.line, pos0.column);
+ }
+ if (result0 === null) {
+ pos = clone(pos0);
+ }
+ if (result0 === null) {
+ pos0 = clone(pos);
+ if (input.substr(pos.offset, 2) === "\\b") {
+ result0 = "\\b";
+ advance(pos, 2);
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"\\\\b\"");
+ }
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, line, column) { return "\b"; })(pos0.offset, pos0.line, pos0.column);
+ }
+ if (result0 === null) {
+ pos = clone(pos0);
+ }
+ if (result0 === null) {
+ pos0 = clone(pos);
+ if (input.substr(pos.offset, 2) === "\\f") {
+ result0 = "\\f";
+ advance(pos, 2);
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"\\\\f\"");
+ }
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, line, column) { return "\f"; })(pos0.offset, pos0.line, pos0.column);
+ }
+ if (result0 === null) {
+ pos = clone(pos0);
+ }
+ if (result0 === null) {
+ pos0 = clone(pos);
+ if (input.substr(pos.offset, 2) === "\\n") {
+ result0 = "\\n";
+ advance(pos, 2);
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"\\\\n\"");
+ }
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, line, column) { return "\n"; })(pos0.offset, pos0.line, pos0.column);
+ }
+ if (result0 === null) {
+ pos = clone(pos0);
+ }
+ if (result0 === null) {
+ pos0 = clone(pos);
+ if (input.substr(pos.offset, 2) === "\\r") {
+ result0 = "\\r";
+ advance(pos, 2);
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"\\\\r\"");
+ }
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, line, column) { return "\r"; })(pos0.offset, pos0.line, pos0.column);
+ }
+ if (result0 === null) {
+ pos = clone(pos0);
+ }
+ if (result0 === null) {
+ pos0 = clone(pos);
+ if (input.substr(pos.offset, 2) === "\\t") {
+ result0 = "\\t";
+ advance(pos, 2);
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"\\\\t\"");
+ }
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, line, column) { return "\t"; })(pos0.offset, pos0.line, pos0.column);
+ }
+ if (result0 === null) {
+ pos = clone(pos0);
+ }
+ if (result0 === null) {
+ pos0 = clone(pos);
+ pos1 = clone(pos);
+ if (input.substr(pos.offset, 2) === "\\u") {
+ result0 = "\\u";
+ advance(pos, 2);
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"\\\\u\"");
+ }
+ }
+ if (result0 !== null) {
+ result1 = parse_hexDigit();
+ if (result1 !== null) {
+ result2 = parse_hexDigit();
+ if (result2 !== null) {
+ result3 = parse_hexDigit();
+ if (result3 !== null) {
+ result4 = parse_hexDigit();
+ if (result4 !== null) {
+ result0 = [result0, result1, result2, result3, result4];
+ } else {
+ result0 = null;
+ pos = clone(pos1);
+ }
+ } else {
+ result0 = null;
+ pos = clone(pos1);
+ }
+ } else {
+ result0 = null;
+ pos = clone(pos1);
+ }
+ } else {
+ result0 = null;
+ pos = clone(pos1);
+ }
+ } else {
+ result0 = null;
+ pos = clone(pos1);
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, line, column, h1, h2, h3, h4) {
+ return String.fromCharCode(parseInt("0x" + h1 + h2 + h3 + h4));
+ })(pos0.offset, pos0.line, pos0.column, result0[1], result0[2], result0[3], result0[4]);
+ }
+ if (result0 === null) {
+ pos = clone(pos0);
+ }
+ }
+ }
+ }
+ }
}
}
}
}
}
- while (result1 !== null) {
- result0.push(result1);
- if (/^[ -!]/.test(input.charAt(pos.offset))) {
- result1 = input.charAt(pos.offset);
- advance(pos, 1);
+ return result0;
+ }
+
+ function parse_achar() {
+ var result0, result1, result2, result3, result4;
+ var pos0, pos1;
+
+ if (/^[^'\\\0-\x1F]/.test(input.charAt(pos.offset))) {
+ result0 = input.charAt(pos.offset);
+ advance(pos, 1);
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("[^'\\\\\\0-\\x1F]");
+ }
+ }
+ if (result0 === null) {
+ pos0 = clone(pos);
+ if (input.substr(pos.offset, 2) === "\\'") {
+ result0 = "\\'";
+ advance(pos, 2);
} else {
- result1 = null;
+ result0 = null;
if (reportFailures === 0) {
- matchFailed("[ -!]");
+ matchFailed("\"\\\\'\"");
}
}
- if (result1 === null) {
- if (/^[#-[]/.test(input.charAt(pos.offset))) {
- result1 = input.charAt(pos.offset);
- advance(pos, 1);
+ if (result0 !== null) {
+ result0 = (function(offset, line, column) { return "\'"; })(pos0.offset, pos0.line, pos0.column);
+ }
+ if (result0 === null) {
+ pos = clone(pos0);
+ }
+ if (result0 === null) {
+ pos0 = clone(pos);
+ if (input.substr(pos.offset, 2) === "\\\\") {
+ result0 = "\\\\";
+ advance(pos, 2);
} else {
- result1 = null;
+ result0 = null;
if (reportFailures === 0) {
- matchFailed("[#-[]");
+ matchFailed("\"\\\\\\\\\"");
}
}
- if (result1 === null) {
- if (/^[\]-\uFFFF]/.test(input.charAt(pos.offset))) {
- result1 = input.charAt(pos.offset);
- advance(pos, 1);
+ if (result0 !== null) {
+ result0 = (function(offset, line, column) { return "\\"; })(pos0.offset, pos0.line, pos0.column);
+ }
+ if (result0 === null) {
+ pos = clone(pos0);
+ }
+ if (result0 === null) {
+ pos0 = clone(pos);
+ if (input.substr(pos.offset, 2) === "\\/") {
+ result0 = "\\/";
+ advance(pos, 2);
} else {
- result1 = null;
+ result0 = null;
if (reportFailures === 0) {
- matchFailed("[\\]-\\uFFFF]");
+ matchFailed("\"\\\\/\"");
}
}
- if (result1 === null) {
- if (/^[\\']/.test(input.charAt(pos.offset))) {
- result1 = input.charAt(pos.offset);
- advance(pos, 1);
+ if (result0 !== null) {
+ result0 = (function(offset, line, column) { return "/"; })(pos0.offset, pos0.line, pos0.column);
+ }
+ if (result0 === null) {
+ pos = clone(pos0);
+ }
+ if (result0 === null) {
+ pos0 = clone(pos);
+ if (input.substr(pos.offset, 2) === "\\b") {
+ result0 = "\\b";
+ advance(pos, 2);
} else {
- result1 = null;
+ result0 = null;
if (reportFailures === 0) {
- matchFailed("[\\\\']");
+ matchFailed("\"\\\\b\"");
+ }
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, line, column) { return "\b"; })(pos0.offset, pos0.line, pos0.column);
+ }
+ if (result0 === null) {
+ pos = clone(pos0);
+ }
+ if (result0 === null) {
+ pos0 = clone(pos);
+ if (input.substr(pos.offset, 2) === "\\f") {
+ result0 = "\\f";
+ advance(pos, 2);
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"\\\\f\"");
+ }
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, line, column) { return "\f"; })(pos0.offset, pos0.line, pos0.column);
+ }
+ if (result0 === null) {
+ pos = clone(pos0);
+ }
+ if (result0 === null) {
+ pos0 = clone(pos);
+ if (input.substr(pos.offset, 2) === "\\n") {
+ result0 = "\\n";
+ advance(pos, 2);
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"\\\\n\"");
+ }
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, line, column) { return "\n"; })(pos0.offset, pos0.line, pos0.column);
+ }
+ if (result0 === null) {
+ pos = clone(pos0);
+ }
+ if (result0 === null) {
+ pos0 = clone(pos);
+ if (input.substr(pos.offset, 2) === "\\r") {
+ result0 = "\\r";
+ advance(pos, 2);
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"\\\\r\"");
+ }
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, line, column) { return "\r"; })(pos0.offset, pos0.line, pos0.column);
+ }
+ if (result0 === null) {
+ pos = clone(pos0);
+ }
+ if (result0 === null) {
+ pos0 = clone(pos);
+ if (input.substr(pos.offset, 2) === "\\t") {
+ result0 = "\\t";
+ advance(pos, 2);
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"\\\\t\"");
+ }
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, line, column) { return "\t"; })(pos0.offset, pos0.line, pos0.column);
+ }
+ if (result0 === null) {
+ pos = clone(pos0);
+ }
+ if (result0 === null) {
+ pos0 = clone(pos);
+ pos1 = clone(pos);
+ if (input.substr(pos.offset, 2) === "\\u") {
+ result0 = "\\u";
+ advance(pos, 2);
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("\"\\\\u\"");
+ }
+ }
+ if (result0 !== null) {
+ result1 = parse_hexDigit();
+ if (result1 !== null) {
+ result2 = parse_hexDigit();
+ if (result2 !== null) {
+ result3 = parse_hexDigit();
+ if (result3 !== null) {
+ result4 = parse_hexDigit();
+ if (result4 !== null) {
+ result0 = [result0, result1, result2, result3, result4];
+ } else {
+ result0 = null;
+ pos = clone(pos1);
+ }
+ } else {
+ result0 = null;
+ pos = clone(pos1);
+ }
+ } else {
+ result0 = null;
+ pos = clone(pos1);
+ }
+ } else {
+ result0 = null;
+ pos = clone(pos1);
+ }
+ } else {
+ result0 = null;
+ pos = clone(pos1);
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, line, column, h1, h2, h3, h4) {
+ return String.fromCharCode(parseInt("0x" + h1 + h2 + h3 + h4));
+ })(pos0.offset, pos0.line, pos0.column, result0[1], result0[2], result0[3], result0[4]);
+ }
+ if (result0 === null) {
+ pos = clone(pos0);
+ }
+ }
+ }
+ }
}
}
}
}
}
}
- if (result0 !== null) {
- result0 = (function(offset, line, column, c) {
- return c.join('');
- })(pos0.offset, pos0.line, pos0.column, result0);
- }
- if (result0 === null) {
- pos = clone(pos0);
+ return result0;
+ }
+
+ function parse_hexDigit() {
+ var result0;
+
+ if (/^[0-9a-fA-F]/.test(input.charAt(pos.offset))) {
+ result0 = input.charAt(pos.offset);
+ advance(pos, 1);
+ } else {
+ result0 = null;
+ if (reportFailures === 0) {
+ matchFailed("[0-9a-fA-F]");
+ }
}
return result0;
}
View
2  modules/compiler/package.json
@@ -1,7 +1,7 @@
{
"author": "ql.io",
"name": "ql.io-compiler",
- "version": "0.5.4",
+ "version": "0.5.5",
"repository": {
"type": "git",
"url": "https://github.com/ql-io/ql.io"
View
47 modules/compiler/pegs/ql.peg
@@ -1,3 +1,4 @@
+
/*
* Copyright 2011 eBay Software Foundation
*
@@ -1086,10 +1087,6 @@ ExprBlock = s:StringLiteral {
return s.substr(1, s.length - 2);
}
-StringLiteral = parts:(('"' DoubleString '"') / ("'" SingleString "'")) {
- return '"' + parts[1] + '"';
-}
-
Identifier = c:([a-zA-Z$:][a-zA-Z_0-9:]*) {
var ret = c[0];
for(i = 1; i < c.length; i++) {
@@ -1108,12 +1105,46 @@ PositiveNumber = d:[0-9]+ {
return parseInt(d.join(''));
}
-// Apostrophe is not allowed
-SingleString = c:([\u0020-\u0026]/[\u0028-\u005B]/[\u005D-\uFFFF]/[\\"])* {
- return c.join('');
+StringLiteral = parts:(('"' DoubleString '"') / ("'" SingleString "'")) {
+ return '"' + parts[1] + '"';
}
// Quotation mark is not allowed
-DoubleString = c:([\u0020-\u0021]/[\u0023-\u005B]/[\u005D-\uFFFF]/[\\'])* {
+DoubleString = c:dchar* {
return c.join('');
}
+
+// Apostrophe is not allowed
+SingleString = c:achar* {
+ return c.join('');
+}
+
+// In the original JSON grammar: "any-Unicode-character-except-"-or-\-or-control-character"
+dchar = [^"\\\0-\x1F\x7f]
+ / '\\"' { return '"'; }
+ / "\\\\" { return "\\"; }
+ / "\\/" { return "/"; }
+ / "\\b" { return "\b"; }
+ / "\\f" { return "\f"; }
+ / "\\n" { return "\n"; }
+ / "\\r" { return "\r"; }
+ / "\\t" { return "\t"; }
+ / "\\u" h1:hexDigit h2:hexDigit h3:hexDigit h4:hexDigit {
+ return String.fromCharCode(parseInt("0x" + h1 + h2 + h3 + h4));
+}
+
+achar = [^'\\\0-\x1F\x7f]
+ / "\\'" { return "\'"; }
+ / "\\\\" { return "\\"; }
+ / "\\/" { return "/"; }
+ / "\\b" { return "\b"; }
+ / "\\f" { return "\f"; }
+ / "\\n" { return "\n"; }
+ / "\\r" { return "\r"; }
+ / "\\t" { return "\t"; }
+ / "\\u" h1:hexDigit h2:hexDigit h3:hexDigit h4:hexDigit {
+ return String.fromCharCode(parseInt("0x" + h1 + h2 + h3 + h4));
+}
+
+hexDigit
+ = [0-9a-fA-F]
View
29 modules/compiler/test/ql-script-test.js
@@ -495,5 +495,34 @@ return {"result" : "{fields}"};\
test.ok(false);
test.done();
}
+ },
+
+ 'escaped-quotes': function(test) {
+ var script = 'a = "Hello\\"World"';
+ try {
+ var cooked = compiler.compile(script);
+ test.equals(cooked[0].object, "Hello\"World");
+ test.done()
+ }
+ catch(e) {
+ console.log(e.stack || e);
+ test.ok(false);
+ test.done();
+ }
+ },
+
+ 'escaped-apos': function(test) {
+ var script = "a = 'Hello\\'World'";
+ try {
+ var cooked = compiler.compile(script);
+ test.equals(cooked[0].object, 'Hello\'World');
+ test.done()
+ }
+ catch(e) {
+ console.log(e.stack || e);
+ test.ok(false);
+ test.done();
+ }
}
+
};
Something went wrong with that request. Please try again.