fix parseInludes bug

This commit is contained in:
Umur Ozkul 2022-08-23 11:47:24 +02:00
parent b7ae9804a5
commit 9cf3a93b70
4 changed files with 145 additions and 203 deletions

View File

@ -5,9 +5,7 @@
"use strict"; "use strict";
function peg$subclass(child, parent) { function peg$subclass(child, parent) {
function C() { function C() { this.constructor = child; }
this.constructor = child;
}
C.prototype = parent.prototype; C.prototype = parent.prototype;
child.prototype = new C(); child.prototype = new C();
} }
@ -29,9 +27,7 @@ peg$subclass(peg$SyntaxError, Error);
function peg$padEnd(str, targetLength, padString) { function peg$padEnd(str, targetLength, padString) {
padString = padString || " "; padString = padString || " ";
if (str.length > targetLength) { if (str.length > targetLength) { return str; }
return str;
}
targetLength -= str.length; targetLength -= str.length;
padString += padString.repeat(targetLength); padString += padString.repeat(targetLength);
return str + padString.slice(0, targetLength); return str + padString.slice(0, targetLength);
@ -52,24 +48,15 @@ peg$SyntaxError.prototype.format = function (sources) {
var loc = this.location.source + ":" + s.line + ":" + s.column; var loc = this.location.source + ":" + s.line + ":" + s.column;
if (src) { if (src) {
var e = this.location.end; var e = this.location.end;
var filler = peg$padEnd("", s.line.toString().length, " "); var filler = peg$padEnd("", s.line.toString().length, ' ');
var line = src[s.line - 1]; var line = src[s.line - 1];
var last = s.line === e.line ? e.column : line.length + 1; var last = s.line === e.line ? e.column : line.length + 1;
var hatLen = last - s.column || 1; var hatLen = (last - s.column) || 1;
str += str += "\n --> " + loc + "\n"
"\n --> " + + filler + " |\n"
loc + + s.line + " | " + line + "\n"
"\n" + + filler + " | " + peg$padEnd("", s.column - 1, ' ')
filler + + peg$padEnd("", hatLen, "^");
" |\n" +
s.line +
" | " +
line +
"\n" +
filler +
" | " +
peg$padEnd("", s.column - 1, " ") +
peg$padEnd("", hatLen, "^");
} else { } else {
str += "\n at " + loc; str += "\n at " + loc;
} }
@ -80,7 +67,7 @@ peg$SyntaxError.prototype.format = function (sources) {
peg$SyntaxError.buildMessage = function(expected, found) { peg$SyntaxError.buildMessage = function(expected, found) {
var DESCRIBE_EXPECTATION_FNS = { var DESCRIBE_EXPECTATION_FNS = {
literal: function(expectation) { literal: function(expectation) {
return '"' + literalEscape(expectation.text) + '"'; return "\"" + literalEscape(expectation.text) + "\"";
}, },
class: function(expectation) { class: function(expectation) {
@ -90,9 +77,7 @@ peg$SyntaxError.buildMessage = function (expected, found) {
: classEscape(part); : classEscape(part);
}); });
return ( return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]";
"[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]"
);
}, },
any: function() { any: function() {
@ -105,7 +90,7 @@ peg$SyntaxError.buildMessage = function (expected, found) {
other: function(expectation) { other: function(expectation) {
return expectation.description; return expectation.description;
}, }
}; };
function hex(ch) { function hex(ch) {
@ -115,17 +100,13 @@ peg$SyntaxError.buildMessage = function (expected, found) {
function literalEscape(s) { function literalEscape(s) {
return s return s
.replace(/\\/g, "\\\\") .replace(/\\/g, "\\\\")
.replace(/"/g, '\\"') .replace(/"/g, "\\\"")
.replace(/\0/g, "\\0") .replace(/\0/g, "\\0")
.replace(/\t/g, "\\t") .replace(/\t/g, "\\t")
.replace(/\n/g, "\\n") .replace(/\n/g, "\\n")
.replace(/\r/g, "\\r") .replace(/\r/g, "\\r")
.replace(/[\x00-\x0F]/g, function (ch) { .replace(/[\x00-\x0F]/g, function(ch) { return "\\x0" + hex(ch); })
return "\\x0" + hex(ch); .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return "\\x" + hex(ch); });
})
.replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
return "\\x" + hex(ch);
});
} }
function classEscape(s) { function classEscape(s) {
@ -138,12 +119,8 @@ peg$SyntaxError.buildMessage = function (expected, found) {
.replace(/\t/g, "\\t") .replace(/\t/g, "\\t")
.replace(/\n/g, "\\n") .replace(/\n/g, "\\n")
.replace(/\r/g, "\\r") .replace(/\r/g, "\\r")
.replace(/[\x00-\x0F]/g, function (ch) { .replace(/[\x00-\x0F]/g, function(ch) { return "\\x0" + hex(ch); })
return "\\x0" + hex(ch); .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return "\\x" + hex(ch); });
})
.replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
return "\\x" + hex(ch);
});
} }
function describeExpectation(expectation) { function describeExpectation(expectation) {
@ -174,25 +151,17 @@ peg$SyntaxError.buildMessage = function (expected, found) {
return descriptions[0] + " or " + descriptions[1]; return descriptions[0] + " or " + descriptions[1];
default: default:
return ( return descriptions.slice(0, -1).join(", ")
descriptions.slice(0, -1).join(", ") + + ", or "
", or " + + descriptions[descriptions.length - 1];
descriptions[descriptions.length - 1]
);
} }
} }
function describeFound(found) { function describeFound(found) {
return found ? '"' + literalEscape(found) + '"' : "end of input"; return found ? "\"" + literalEscape(found) + "\"" : "end of input";
} }
return ( return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
"Expected " +
describeExpected(expected) +
" but " +
describeFound(found) +
" found."
);
}; };
function peg$parse(input, options) { function peg$parse(input, options) {
@ -206,7 +175,7 @@ function peg$parse(input, options) {
var peg$c0 = "#include"; var peg$c0 = "#include";
var peg$c1 = "'"; var peg$c1 = "'";
var peg$c2 = '"'; var peg$c2 = "\"";
var peg$c3 = "//"; var peg$c3 = "//";
var peg$c4 = "/*"; var peg$c4 = "/*";
var peg$c5 = "*/"; var peg$c5 = "*/";
@ -222,8 +191,8 @@ function peg$parse(input, options) {
var peg$e1 = peg$otherExpectation("string"); var peg$e1 = peg$otherExpectation("string");
var peg$e2 = peg$literalExpectation("'", false); var peg$e2 = peg$literalExpectation("'", false);
var peg$e3 = peg$classExpectation(["'"], true, false); var peg$e3 = peg$classExpectation(["'"], true, false);
var peg$e4 = peg$literalExpectation('"', false); var peg$e4 = peg$literalExpectation("\"", false);
var peg$e5 = peg$classExpectation(['"'], true, false); var peg$e5 = peg$classExpectation(["\""], true, false);
var peg$e6 = peg$literalExpectation("//", false); var peg$e6 = peg$literalExpectation("//", false);
var peg$e7 = peg$literalExpectation("/*", false); var peg$e7 = peg$literalExpectation("/*", false);
var peg$e8 = peg$classExpectation(["*"], true, false); var peg$e8 = peg$classExpectation(["*"], true, false);
@ -234,24 +203,12 @@ function peg$parse(input, options) {
var peg$e13 = peg$classExpectation(["\n", "\r"], false, false); var peg$e13 = peg$classExpectation(["\n", "\r"], false, false);
var peg$e14 = peg$classExpectation(["\r", "\n"], true, false); var peg$e14 = peg$classExpectation(["\r", "\n"], true, false);
var peg$f0 = function (head, tail) { var peg$f0 = function(head, tail) {return [head, ...tail].filter( e => e != '');};
return [head, ...tail].filter((e) => e != ""); var peg$f1 = function() {return [];};
}; var peg$f2 = function(characters) {return characters.join('');};
var peg$f1 = function () { var peg$f3 = function(characters) {return characters.join('');};
return []; var peg$f4 = function() { return '';};
}; var peg$f5 = function() { return '';};
var peg$f2 = function (characters) {
return characters.join("");
};
var peg$f3 = function (characters) {
return characters.join("");
};
var peg$f4 = function () {
return "";
};
var peg$f5 = function () {
return "";
};
var peg$currPos = 0; var peg$currPos = 0;
var peg$savedPos = 0; var peg$savedPos = 0;
var peg$posDetailsCache = [{ line: 1, column: 1 }]; var peg$posDetailsCache = [{ line: 1, column: 1 }];
@ -265,9 +222,7 @@ function peg$parse(input, options) {
if ("startRule" in options) { if ("startRule" in options) {
if (!(options.startRule in peg$startRuleFunctions)) { if (!(options.startRule in peg$startRuleFunctions)) {
throw new Error( throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
"Can't start parsing from rule \"" + options.startRule + '".'
);
} }
peg$startRuleFunction = peg$startRuleFunctions[options.startRule]; peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
@ -285,7 +240,7 @@ function peg$parse(input, options) {
return { return {
source: peg$source, source: peg$source,
start: peg$savedPos, start: peg$savedPos,
end: peg$currPos, end: peg$currPos
}; };
} }
@ -294,8 +249,7 @@ function peg$parse(input, options) {
} }
function expected(description, location) { function expected(description, location) {
location = location = location !== undefined
location !== undefined
? location ? location
: peg$computeLocation(peg$savedPos, peg$currPos); : peg$computeLocation(peg$savedPos, peg$currPos);
@ -307,8 +261,7 @@ function peg$parse(input, options) {
} }
function error(message, location) { function error(message, location) {
location = location = location !== undefined
location !== undefined
? location ? location
: peg$computeLocation(peg$savedPos, peg$currPos); : peg$computeLocation(peg$savedPos, peg$currPos);
@ -320,12 +273,7 @@ function peg$parse(input, options) {
} }
function peg$classExpectation(parts, inverted, ignoreCase) { function peg$classExpectation(parts, inverted, ignoreCase) {
return { return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase };
type: "class",
parts: parts,
inverted: inverted,
ignoreCase: ignoreCase,
};
} }
function peg$anyExpectation() { function peg$anyExpectation() {
@ -355,7 +303,7 @@ function peg$parse(input, options) {
details = peg$posDetailsCache[p]; details = peg$posDetailsCache[p];
details = { details = {
line: details.line, line: details.line,
column: details.column, column: details.column
}; };
while (p < pos) { while (p < pos) {
@ -384,20 +332,18 @@ function peg$parse(input, options) {
start: { start: {
offset: startPos, offset: startPos,
line: startPosDetails.line, line: startPosDetails.line,
column: startPosDetails.column, column: startPosDetails.column
}, },
end: { end: {
offset: endPos, offset: endPos,
line: endPosDetails.line, line: endPosDetails.line,
column: endPosDetails.column, column: endPosDetails.column
}, }
}; };
} }
function peg$fail(expected) { function peg$fail(expected) {
if (peg$currPos < peg$maxFailPos) { if (peg$currPos < peg$maxFailPos) { return; }
return;
}
if (peg$currPos > peg$maxFailPos) { if (peg$currPos > peg$maxFailPos) {
peg$maxFailPos = peg$currPos; peg$maxFailPos = peg$currPos;
@ -421,7 +367,7 @@ function peg$parse(input, options) {
} }
function peg$parsestart() { function peg$parsestart() {
var s0, s1, s2, s3; var s0, s1, s2, s3, s4;
var key = peg$currPos * 10 + 0; var key = peg$currPos * 10 + 0;
var cached = peg$resultsCache[key]; var cached = peg$resultsCache[key];
@ -433,16 +379,40 @@ function peg$parse(input, options) {
} }
s0 = peg$currPos; s0 = peg$currPos;
s1 = peg$parseincludes(); s1 = [];
if (s1 !== peg$FAILED) { s2 = peg$parsenewLine();
s2 = []; if (s2 === peg$FAILED) {
s3 = peg$parsenewLine(); s2 = peg$parse_();
while (s3 !== peg$FAILED) { if (s2 === peg$FAILED) {
s2.push(s3); s2 = peg$parsecomment();
s3 = peg$parsenewLine(); if (s2 === peg$FAILED) {
s2 = peg$parsedelimitedComment();
} }
s3 = peg$parseignore(); }
s0 = s1; }
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$parsenewLine();
if (s2 === peg$FAILED) {
s2 = peg$parse_();
if (s2 === peg$FAILED) {
s2 = peg$parsecomment();
if (s2 === peg$FAILED) {
s2 = peg$parsedelimitedComment();
}
}
}
}
s2 = peg$parseincludes();
if (s2 !== peg$FAILED) {
s3 = [];
s4 = peg$parsenewLine();
while (s4 !== peg$FAILED) {
s3.push(s4);
s4 = peg$parsenewLine();
}
s4 = peg$parseignore();
s0 = s2;
} else { } else {
peg$currPos = s0; peg$currPos = s0;
s0 = peg$FAILED; s0 = peg$FAILED;
@ -538,7 +508,7 @@ function peg$parse(input, options) {
} }
function peg$parseincludeStatement() { function peg$parseincludeStatement() {
var s0, s1, s2, s3, s4, s5; var s0, s1, s2, s3, s4, s5, s6;
var key = peg$currPos * 10 + 2; var key = peg$currPos * 10 + 2;
var cached = peg$resultsCache[key]; var cached = peg$resultsCache[key];
@ -550,31 +520,35 @@ function peg$parse(input, options) {
} }
s0 = peg$currPos; s0 = peg$currPos;
s1 = [];
s2 = peg$parse_();
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$parse_();
}
if (input.substr(peg$currPos, 8) === peg$c0) { if (input.substr(peg$currPos, 8) === peg$c0) {
s1 = peg$c0; s2 = peg$c0;
peg$currPos += 8; peg$currPos += 8;
} else { } else {
s1 = peg$FAILED; s2 = peg$FAILED;
if (peg$silentFails === 0) { if (peg$silentFails === 0) { peg$fail(peg$e0); }
peg$fail(peg$e0);
} }
if (s2 !== peg$FAILED) {
s3 = [];
s4 = peg$parse_();
while (s4 !== peg$FAILED) {
s3.push(s4);
s4 = peg$parse_();
} }
if (s1 !== peg$FAILED) { s4 = peg$parsestring();
s2 = []; if (s4 !== peg$FAILED) {
s3 = peg$parse_(); s5 = [];
while (s3 !== peg$FAILED) { s6 = peg$parse_();
s2.push(s3); while (s6 !== peg$FAILED) {
s3 = peg$parse_(); s5.push(s6);
s6 = peg$parse_();
} }
s3 = peg$parsestring(); s0 = s4;
if (s3 !== peg$FAILED) {
s4 = [];
s5 = peg$parse_();
while (s5 !== peg$FAILED) {
s4.push(s5);
s5 = peg$parse_();
}
s0 = s3;
} else { } else {
peg$currPos = s0; peg$currPos = s0;
s0 = peg$FAILED; s0 = peg$FAILED;
@ -615,9 +589,7 @@ function peg$parse(input, options) {
peg$currPos++; peg$currPos++;
} else { } else {
s2 = peg$FAILED; s2 = peg$FAILED;
if (peg$silentFails === 0) { if (peg$silentFails === 0) { peg$fail(peg$e2); }
peg$fail(peg$e2);
}
} }
if (s2 !== peg$FAILED) { if (s2 !== peg$FAILED) {
s3 = []; s3 = [];
@ -626,9 +598,7 @@ function peg$parse(input, options) {
peg$currPos++; peg$currPos++;
} else { } else {
s4 = peg$FAILED; s4 = peg$FAILED;
if (peg$silentFails === 0) { if (peg$silentFails === 0) { peg$fail(peg$e3); }
peg$fail(peg$e3);
}
} }
while (s4 !== peg$FAILED) { while (s4 !== peg$FAILED) {
s3.push(s4); s3.push(s4);
@ -637,9 +607,7 @@ function peg$parse(input, options) {
peg$currPos++; peg$currPos++;
} else { } else {
s4 = peg$FAILED; s4 = peg$FAILED;
if (peg$silentFails === 0) { if (peg$silentFails === 0) { peg$fail(peg$e3); }
peg$fail(peg$e3);
}
} }
} }
if (input.charCodeAt(peg$currPos) === 39) { if (input.charCodeAt(peg$currPos) === 39) {
@ -647,9 +615,7 @@ function peg$parse(input, options) {
peg$currPos++; peg$currPos++;
} else { } else {
s4 = peg$FAILED; s4 = peg$FAILED;
if (peg$silentFails === 0) { if (peg$silentFails === 0) { peg$fail(peg$e2); }
peg$fail(peg$e2);
}
} }
if (s4 !== peg$FAILED) { if (s4 !== peg$FAILED) {
s1 = s3; s1 = s3;
@ -674,9 +640,7 @@ function peg$parse(input, options) {
peg$currPos++; peg$currPos++;
} else { } else {
s2 = peg$FAILED; s2 = peg$FAILED;
if (peg$silentFails === 0) { if (peg$silentFails === 0) { peg$fail(peg$e4); }
peg$fail(peg$e4);
}
} }
if (s2 !== peg$FAILED) { if (s2 !== peg$FAILED) {
s3 = []; s3 = [];
@ -685,9 +649,7 @@ function peg$parse(input, options) {
peg$currPos++; peg$currPos++;
} else { } else {
s4 = peg$FAILED; s4 = peg$FAILED;
if (peg$silentFails === 0) { if (peg$silentFails === 0) { peg$fail(peg$e5); }
peg$fail(peg$e5);
}
} }
while (s4 !== peg$FAILED) { while (s4 !== peg$FAILED) {
s3.push(s4); s3.push(s4);
@ -696,9 +658,7 @@ function peg$parse(input, options) {
peg$currPos++; peg$currPos++;
} else { } else {
s4 = peg$FAILED; s4 = peg$FAILED;
if (peg$silentFails === 0) { if (peg$silentFails === 0) { peg$fail(peg$e5); }
peg$fail(peg$e5);
}
} }
} }
if (input.charCodeAt(peg$currPos) === 34) { if (input.charCodeAt(peg$currPos) === 34) {
@ -706,9 +666,7 @@ function peg$parse(input, options) {
peg$currPos++; peg$currPos++;
} else { } else {
s4 = peg$FAILED; s4 = peg$FAILED;
if (peg$silentFails === 0) { if (peg$silentFails === 0) { peg$fail(peg$e4); }
peg$fail(peg$e4);
}
} }
if (s4 !== peg$FAILED) { if (s4 !== peg$FAILED) {
s1 = s3; s1 = s3;
@ -729,9 +687,7 @@ function peg$parse(input, options) {
peg$silentFails--; peg$silentFails--;
if (s0 === peg$FAILED) { if (s0 === peg$FAILED) {
s1 = peg$FAILED; s1 = peg$FAILED;
if (peg$silentFails === 0) { if (peg$silentFails === 0) { peg$fail(peg$e1); }
peg$fail(peg$e1);
}
} }
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
@ -793,9 +749,7 @@ function peg$parse(input, options) {
peg$currPos += 2; peg$currPos += 2;
} else { } else {
s1 = peg$FAILED; s1 = peg$FAILED;
if (peg$silentFails === 0) { if (peg$silentFails === 0) { peg$fail(peg$e6); }
peg$fail(peg$e6);
}
} }
if (s1 !== peg$FAILED) { if (s1 !== peg$FAILED) {
s2 = []; s2 = [];
@ -834,9 +788,7 @@ function peg$parse(input, options) {
peg$currPos += 2; peg$currPos += 2;
} else { } else {
s1 = peg$FAILED; s1 = peg$FAILED;
if (peg$silentFails === 0) { if (peg$silentFails === 0) { peg$fail(peg$e7); }
peg$fail(peg$e7);
}
} }
if (s1 !== peg$FAILED) { if (s1 !== peg$FAILED) {
s2 = []; s2 = [];
@ -845,9 +797,7 @@ function peg$parse(input, options) {
peg$currPos++; peg$currPos++;
} else { } else {
s3 = peg$FAILED; s3 = peg$FAILED;
if (peg$silentFails === 0) { if (peg$silentFails === 0) { peg$fail(peg$e8); }
peg$fail(peg$e8);
}
} }
while (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) {
s2.push(s3); s2.push(s3);
@ -856,9 +806,7 @@ function peg$parse(input, options) {
peg$currPos++; peg$currPos++;
} else { } else {
s3 = peg$FAILED; s3 = peg$FAILED;
if (peg$silentFails === 0) { if (peg$silentFails === 0) { peg$fail(peg$e8); }
peg$fail(peg$e8);
}
} }
} }
if (input.substr(peg$currPos, 2) === peg$c5) { if (input.substr(peg$currPos, 2) === peg$c5) {
@ -866,9 +814,7 @@ function peg$parse(input, options) {
peg$currPos += 2; peg$currPos += 2;
} else { } else {
s3 = peg$FAILED; s3 = peg$FAILED;
if (peg$silentFails === 0) { if (peg$silentFails === 0) { peg$fail(peg$e9); }
peg$fail(peg$e9);
}
} }
if (s3 !== peg$FAILED) { if (s3 !== peg$FAILED) {
peg$savedPos = s0; peg$savedPos = s0;
@ -905,16 +851,12 @@ function peg$parse(input, options) {
peg$currPos++; peg$currPos++;
} else { } else {
s0 = peg$FAILED; s0 = peg$FAILED;
if (peg$silentFails === 0) { if (peg$silentFails === 0) { peg$fail(peg$e11); }
peg$fail(peg$e11);
}
} }
peg$silentFails--; peg$silentFails--;
if (s0 === peg$FAILED) { if (s0 === peg$FAILED) {
s1 = peg$FAILED; s1 = peg$FAILED;
if (peg$silentFails === 0) { if (peg$silentFails === 0) { peg$fail(peg$e10); }
peg$fail(peg$e10);
}
} }
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
@ -940,16 +882,12 @@ function peg$parse(input, options) {
peg$currPos++; peg$currPos++;
} else { } else {
s0 = peg$FAILED; s0 = peg$FAILED;
if (peg$silentFails === 0) { if (peg$silentFails === 0) { peg$fail(peg$e13); }
peg$fail(peg$e13);
}
} }
peg$silentFails--; peg$silentFails--;
if (s0 === peg$FAILED) { if (s0 === peg$FAILED) {
s1 = peg$FAILED; s1 = peg$FAILED;
if (peg$silentFails === 0) { if (peg$silentFails === 0) { peg$fail(peg$e12); }
peg$fail(peg$e12);
}
} }
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
@ -974,9 +912,7 @@ function peg$parse(input, options) {
peg$currPos++; peg$currPos++;
} else { } else {
s0 = peg$FAILED; s0 = peg$FAILED;
if (peg$silentFails === 0) { if (peg$silentFails === 0) { peg$fail(peg$e14); }
peg$fail(peg$e14);
}
} }
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
@ -1005,5 +941,5 @@ function peg$parse(input, options) {
module.exports = { module.exports = {
SyntaxError: peg$SyntaxError, SyntaxError: peg$SyntaxError,
parse: peg$parse, parse: peg$parse
}; };

View File

@ -3,9 +3,8 @@
// #include "string" // #include "string"
// #include "string2" // #include "string2"
start start
= @includes newLine* ignore = (newLine/_/comment/delimitedComment)* @includes newLine* ignore
includes includes
= head:includeStatement tail:(newLine+ @includeStatement)* = head:includeStatement tail:(newLine+ @includeStatement)*
@ -14,7 +13,7 @@ includes
{return [];} {return [];}
includeStatement includeStatement
= '#include' _* @string _* = _* '#include' _* @string _*
/ comment / comment
/ delimitedComment / delimitedComment

View File

@ -1,8 +1,15 @@
@module("./ReducerProject_IncludeParser.js") external parse__: string => array<string> = "parse" @module("./ReducerProject_IncludeParser.js") external parse__: string => array<string> = "parse"
let parseIncludes = (expr: string): array<string> => let parseIncludes = (expr: string): result<array<string>, Reducer_ErrorValue.errorValue> =>
try { try {
parse__(expr) let answer = parse__(expr)
// let logEntry = answer->Js.Array2.joinWith(",")
// `parseIncludes: ${logEntry} for expr: ${expr}`->Js.log
answer->Ok
} catch { } catch {
| Js.Exn.Error(_obj) => [] | Js.Exn.Error(obj) =>
RESyntaxError(
Belt.Option.getExn(Js.Exn.message(obj)),
Reducer_Peggy_Parse.syntaxErrorToLocation(obj)->Some,
)->Error
} }

View File

@ -106,7 +106,7 @@ let setIncludes = (T.ProjectItem(r): t, includes: T.includesType): t => T.Projec
//TODO: forward parse errors to the user //TODO: forward parse errors to the user
let parseIncludes = (this: t): t => let parseIncludes = (this: t): t =>
setIncludes(this, getSource(this)->ReducerProject_ParseIncludes.parseIncludes->Ok) setIncludes(this, getSource(this)->ReducerProject_ParseIncludes.parseIncludes)
let doRawParse = (this: t): T.rawParseArgumentType => this->getSource->Reducer_Peggy_Parse.parse let doRawParse = (this: t): T.rawParseArgumentType => this->getSource->Reducer_Peggy_Parse.parse