(message, expected, pos)
| 925 | } |
| 926 | |
| 927 | function peg$buildException(message, expected, pos) { |
| 928 | function cleanupExpected(expected) { |
| 929 | var i = 1; |
| 930 | |
| 931 | expected.sort(function(a, b) { |
| 932 | if (a.description < b.description) { |
| 933 | return -1; |
| 934 | } else if (a.description > b.description) { |
| 935 | return 1; |
| 936 | } else { |
| 937 | return 0; |
| 938 | } |
| 939 | }); |
| 940 | |
| 941 | while (i < expected.length) { |
| 942 | if (expected[i - 1] === expected[i]) { |
| 943 | expected.splice(i, 1); |
| 944 | } else { |
| 945 | i++; |
| 946 | } |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | function buildMessage(expected, found) { |
| 951 | function stringEscape(s) { |
| 952 | function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); } |
| 953 | |
| 954 | return s |
| 955 | .replace(/\\/g, '\\\\') |
| 956 | .replace(/"/g, '\\"') |
| 957 | .replace(/\x08/g, '\\b') |
| 958 | .replace(/\t/g, '\\t') |
| 959 | .replace(/\n/g, '\\n') |
| 960 | .replace(/\f/g, '\\f') |
| 961 | .replace(/\r/g, '\\r') |
| 962 | .replace(/[\x00-\x07\x0B\x0E\x0F]/g, function(ch) { return '\\x0' + hex(ch); }) |
| 963 | .replace(/[\x10-\x1F\x80-\xFF]/g, function(ch) { return '\\x' + hex(ch); }) |
| 964 | .replace(/[\u0180-\u0FFF]/g, function(ch) { return '\\u0' + hex(ch); }) |
| 965 | .replace(/[\u1080-\uFFFF]/g, function(ch) { return '\\u' + hex(ch); }); |
| 966 | } |
| 967 | |
| 968 | var expectedDescs = new Array(expected.length), |
| 969 | expectedDesc, foundDesc, i; |
| 970 | |
| 971 | for (i = 0; i < expected.length; i++) { |
| 972 | expectedDescs[i] = expected[i].description; |
| 973 | } |
| 974 | |
| 975 | expectedDesc = expected.length > 1 |
| 976 | ? expectedDescs.slice(0, -1).join(", ") |
| 977 | + " or " |
| 978 | + expectedDescs[expected.length - 1] |
| 979 | : expectedDescs[0]; |
| 980 | |
| 981 | foundDesc = found ? "\"" + stringEscape(found) + "\"" : "end of input"; |
| 982 | |
| 983 | return "Expected " + expectedDesc + " but " + foundDesc + " found."; |
| 984 | } |
no test coverage detected
searching dependent graphs…