MCPcopy Create free account
hub / github.com/codemix/htmling / buildMessage

Function buildMessage

lib/parser.js:950–984  ·  view source on GitHub ↗
(expected, found)

Source from the content-addressed store, hash-verified

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 }
985
986 var posDetails = peg$computePosDetails(pos),
987 found = pos < input.length ? input.charAt(pos) : null;

Callers 1

peg$buildExceptionFunction · 0.85

Calls 1

stringEscapeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…