FIxed problems with error recovery

This commit is contained in:
yhirose 2021-01-15 00:05:22 -05:00
parent 8dc6a287f8
commit 0d005fb3da
4 changed files with 10 additions and 9 deletions

View File

@ -86,12 +86,13 @@ function parse() {
if (isValid) { if (isValid) {
$grammarValidation.removeClass('editor-validation-invalid').text('Valid').show(); $grammarValidation.removeClass('editor-validation-invalid').text('Valid').show();
const isValid = data.code.length === 0;
if (isValid) {
codeAst.insert(data.ast); codeAst.insert(data.ast);
codeAstOptimized.insert(data.astOptimized); codeAstOptimized.insert(data.astOptimized);
$codeValidation.removeClass('editor-validation-invalid').text('Valid').show(); $codeValidation.removeClass('editor-validation-invalid').text('Valid').show();
} else {
const isValid = data.code.length === 0;
if (!isValid) {
const html = generateErrorListHTML(data.code); const html = generateErrorListHTML(data.code);
$codeInfo.html(html); $codeInfo.html(html);
$codeValidation.addClass('editor-validation-invalid').text('Invalid').show(); $codeValidation.addClass('editor-validation-invalid').text('Invalid').show();

View File

@ -43,7 +43,7 @@ bool parse_grammar(const std::string &text, peg::parser &peg,
return ret; return ret;
} }
bool parse_code(const std::string &text, peg::parser &peg, std::string &json, void parse_code(const std::string &text, peg::parser &peg, std::string &json,
std::shared_ptr<peg::Ast> &ast) { std::shared_ptr<peg::Ast> &ast) {
peg.enable_ast(); peg.enable_ast();
bool init; bool init;
@ -51,7 +51,6 @@ bool parse_code(const std::string &text, peg::parser &peg, std::string &json,
json += "["; json += "[";
auto ret = peg.parse_n(text.data(), text.size(), ast); auto ret = peg.parse_n(text.data(), text.size(), ast);
json += "]"; json += "]";
return ret;
} }
inline std::vector<std::string> splitRulesText(const std::string &s) { inline std::vector<std::string> splitRulesText(const std::string &s) {
@ -78,7 +77,8 @@ std::string lint(const std::string &grammarText, const std::string &codeText,
if (ret && peg) { if (ret && peg) {
std::shared_ptr<peg::Ast> ast; std::shared_ptr<peg::Ast> ast;
if (parse_code(codeText, peg, codeResult, ast)) { parse_code(codeText, peg, codeResult, ast);
if (ast) {
astResult = escape_json(peg::ast_to_s(ast)); astResult = escape_json(peg::ast_to_s(ast));
auto rules = splitRulesText(opt_rules_text); auto rules = splitRulesText(opt_rules_text);
astResultOptimized = escape_json( astResultOptimized = escape_json(

Binary file not shown.

View File

@ -3105,7 +3105,7 @@ private:
g["Sequence"] = [&](const SemanticValues &vs) { g["Sequence"] = [&](const SemanticValues &vs) {
if (vs.empty()) { if (vs.empty()) {
return lit(""); return npd(lit(""));
} else if (vs.size() == 1) { } else if (vs.size() == 1) {
return std::any_cast<std::shared_ptr<Ope>>(vs[0]); return std::any_cast<std::shared_ptr<Ope>>(vs[0]);
} else { } else {