mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 20:05:31 +00:00
FIxed problems with error recovery
This commit is contained in:
parent
8dc6a287f8
commit
0d005fb3da
@ -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();
|
||||||
|
|
||||||
|
codeAst.insert(data.ast);
|
||||||
|
codeAstOptimized.insert(data.astOptimized);
|
||||||
|
$codeValidation.removeClass('editor-validation-invalid').text('Valid').show();
|
||||||
|
|
||||||
const isValid = data.code.length === 0;
|
const isValid = data.code.length === 0;
|
||||||
if (isValid) {
|
|
||||||
codeAst.insert(data.ast);
|
if (!isValid) {
|
||||||
codeAstOptimized.insert(data.astOptimized);
|
|
||||||
$codeValidation.removeClass('editor-validation-invalid').text('Valid').show();
|
|
||||||
} else {
|
|
||||||
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();
|
||||||
|
@ -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(
|
||||||
|
BIN
docs/native.wasm
BIN
docs/native.wasm
Binary file not shown.
2
peglib.h
2
peglib.h
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user