mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 11:55:30 +00:00
Fixed PEG payground problem when parsed size is less than the actual text size
This commit is contained in:
parent
02d009777c
commit
4109480a0c
@ -84,12 +84,16 @@ function parse() {
|
||||
|
||||
codeAst.insert(data.ast);
|
||||
codeAstOptimized.insert(data.astOptimized);
|
||||
|
||||
if (data.source_valid) {
|
||||
$codeValidation.removeClass('editor-validation-invalid').text('Valid').show();
|
||||
} else {
|
||||
$codeValidation.addClass('editor-validation-invalid').text('Invalid').show();
|
||||
}
|
||||
|
||||
if (data.code.length > 0) {
|
||||
const html = generateErrorListHTML(data.code);
|
||||
$codeInfo.html(html);
|
||||
$codeValidation.addClass('editor-validation-invalid').text('Invalid').show();
|
||||
}
|
||||
} else {
|
||||
$grammarValidation.addClass('editor-validation-invalid').text('Invalid').show();
|
||||
|
@ -43,7 +43,7 @@ bool parse_grammar(const std::string &text, peg::parser &peg,
|
||||
return ret;
|
||||
}
|
||||
|
||||
void parse_code(const std::string &text, peg::parser &peg, std::string &json,
|
||||
bool parse_code(const std::string &text, peg::parser &peg, std::string &json,
|
||||
std::shared_ptr<peg::Ast> &ast) {
|
||||
peg.enable_ast();
|
||||
bool init;
|
||||
@ -51,6 +51,7 @@ void parse_code(const std::string &text, peg::parser &peg, std::string &json,
|
||||
json += "[";
|
||||
auto ret = peg.parse_n(text.data(), text.size(), ast);
|
||||
json += "]";
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string lint(const std::string &grammarText, const std::string &codeText, bool opt_mode) {
|
||||
@ -60,11 +61,12 @@ std::string lint(const std::string &grammarText, const std::string &codeText, bo
|
||||
std::string astResultOptimized;
|
||||
|
||||
peg::parser peg;
|
||||
auto ret = parse_grammar(grammarText, peg, grammarResult);
|
||||
auto is_grammar_valid = parse_grammar(grammarText, peg, grammarResult);
|
||||
auto is_source_valid = false;
|
||||
|
||||
if (ret && peg) {
|
||||
if (is_grammar_valid && peg) {
|
||||
std::shared_ptr<peg::Ast> ast;
|
||||
parse_code(codeText, peg, codeResult, ast);
|
||||
is_source_valid = parse_code(codeText, peg, codeResult, ast);
|
||||
if (ast) {
|
||||
astResult = escape_json(peg::ast_to_s(ast));
|
||||
astResultOptimized = escape_json(
|
||||
@ -74,8 +76,9 @@ std::string lint(const std::string &grammarText, const std::string &codeText, bo
|
||||
|
||||
std::string json;
|
||||
json += "{";
|
||||
json += std::string("\"grammar_valid\":") + (ret ? "true" : "false");
|
||||
json += std::string("\"grammar_valid\":") + (is_grammar_valid ? "true" : "false");
|
||||
json += ",\"grammar\":" + grammarResult;
|
||||
json += std::string(",\"source_valid\":") + (is_source_valid ? "true" : "false");
|
||||
if (!codeResult.empty()) {
|
||||
json += ",\"code\":" + codeResult;
|
||||
json += ",\"ast\":\"" + astResult + "\"";
|
||||
|
File diff suppressed because one or more lines are too long
BIN
docs/native.wasm
BIN
docs/native.wasm
Binary file not shown.
Loading…
Reference in New Issue
Block a user