mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 20:05:31 +00:00
Fixed problems in server mode of peglint
This commit is contained in:
parent
c89c44f1ef
commit
47e51d3651
@ -14,5 +14,5 @@ CR <- '\r'
|
|||||||
DQUOTE <- '"'
|
DQUOTE <- '"'
|
||||||
LF <- '\n'
|
LF <- '\n'
|
||||||
NL <- CR LF / CR / LF
|
NL <- CR LF / CR / LF
|
||||||
TEXTDATA <- ![",] .
|
TEXTDATA <- !([",] / NL) .
|
||||||
D_DQUOTE <- '"' '"'
|
D_DQUOTE <- '"' '"'
|
||||||
|
2256
lint/httplib.h
2256
lint/httplib.h
File diff suppressed because it is too large
Load Diff
@ -118,9 +118,13 @@ body {
|
|||||||
// Setup editros
|
// Setup editros
|
||||||
var grammar = ace.edit("grammar-editor");
|
var grammar = ace.edit("grammar-editor");
|
||||||
grammar.setShowPrintMargin(false);
|
grammar.setShowPrintMargin(false);
|
||||||
|
grammar.setValue(localStorage.getItem('grammarText'));
|
||||||
|
grammar.moveCursorTo(0, 0);
|
||||||
|
|
||||||
var code = ace.edit("code-editor");
|
var code = ace.edit("code-editor");
|
||||||
code.setShowPrintMargin(false);
|
code.setShowPrintMargin(false);
|
||||||
|
code.setValue(localStorage.getItem('codeText'));
|
||||||
|
code.moveCursorTo(0, 0);
|
||||||
|
|
||||||
var codeAst = ace.edit("code-ast");
|
var codeAst = ace.edit("code-ast");
|
||||||
codeAst.setShowPrintMargin(false);
|
codeAst.setShowPrintMargin(false);
|
||||||
@ -161,36 +165,42 @@ body {
|
|||||||
var $codeInfo = $('#code-info');
|
var $codeInfo = $('#code-info');
|
||||||
var codeText = code.getValue();
|
var codeText = code.getValue();
|
||||||
|
|
||||||
|
localStorage.setItem('grammarText', grammarText);
|
||||||
|
localStorage.setItem('codeText', codeText);
|
||||||
|
|
||||||
|
$grammarInfo.html('');
|
||||||
|
$grammarValidation.hide();
|
||||||
|
$codeInfo.html('');
|
||||||
|
$codeValidation.hide();
|
||||||
|
codeAst.setValue('');
|
||||||
|
codeAstOptimized.setValue('');
|
||||||
|
|
||||||
|
if (grammarText.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$.post("/parse", {
|
$.post("/parse", {
|
||||||
grammar: grammarText,
|
grammar: grammarText,
|
||||||
code: codeText
|
code: codeText
|
||||||
}).done(function (data) {
|
}).done(function (data) {
|
||||||
var isValid = data.grammar.length === 0;
|
var isValid = data.grammar.length === 0;
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
$grammarInfo.html('');
|
$grammarValidation.removeClass('editor-validation-invalid').text('Valid').show();
|
||||||
$grammarValidation.removeClass('editor-validation-invalid').text('Valid');
|
|
||||||
|
|
||||||
codeAst.setValue('');
|
|
||||||
codeAstOptimized.setValue('');
|
|
||||||
|
|
||||||
var isValid = data.code.length === 0;
|
var isValid = data.code.length === 0;
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
$codeInfo.html('');
|
|
||||||
$codeValidation.removeClass('editor-validation-invalid').text('Valid');
|
|
||||||
codeAst.insert(data.ast);
|
codeAst.insert(data.ast);
|
||||||
codeAstOptimized.insert(data.astOptimized);
|
codeAstOptimized.insert(data.astOptimized);
|
||||||
|
$codeValidation.removeClass('editor-validation-invalid').text('Valid').show();
|
||||||
} else {
|
} else {
|
||||||
var html = generateErrorListHTML(data.code);
|
var html = generateErrorListHTML(data.code);
|
||||||
$codeInfo.html(html);
|
$codeInfo.html(html);
|
||||||
$codeValidation.addClass('editor-validation-invalid').text('Invalid');
|
$codeValidation.addClass('editor-validation-invalid').text('Invalid').show();
|
||||||
}
|
}
|
||||||
$codeValidation.show();
|
|
||||||
} else {
|
} else {
|
||||||
var html = generateErrorListHTML(data.grammar);
|
var html = generateErrorListHTML(data.grammar);
|
||||||
$grammarInfo.html(html);
|
$grammarInfo.html(html);
|
||||||
$grammarValidation.addClass('editor-validation-invalid').text('Invalid');
|
$grammarValidation.addClass('editor-validation-invalid').text('Invalid').show();
|
||||||
|
|
||||||
$codeValidation.hide();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -289,15 +299,15 @@ int run_server(int port, const vector<char>& syntax, const vector<char>& source)
|
|||||||
{
|
{
|
||||||
Server svr;
|
Server svr;
|
||||||
|
|
||||||
svr.get("/", [&](const Request& /*req*/, Response& res) {
|
svr.Get("/", [&](const Request& /*req*/, Response& res) {
|
||||||
indexHTML = replace_all(indexHTML, "{{syntax}}", string(syntax.data(), syntax.size()).c_str());
|
indexHTML = replace_all(indexHTML, "{{syntax}}", string(syntax.data(), syntax.size()).c_str());
|
||||||
indexHTML = replace_all(indexHTML, "{{source}}", string(source.data(), source.size()).c_str());
|
indexHTML = replace_all(indexHTML, "{{source}}", string(source.data(), source.size()).c_str());
|
||||||
|
|
||||||
res.set_content(indexHTML, "text/html");
|
res.set_content(indexHTML, "text/html");
|
||||||
});
|
});
|
||||||
|
|
||||||
svr.post("/parse", [](const Request& req, Response& res) {
|
svr.Post("/parse", [](const Request& req, Response& res) {
|
||||||
const auto& grammarText = req.params.at("grammar");
|
const auto& grammarText = req.get_param_value("grammar");
|
||||||
|
|
||||||
string grammarResult;
|
string grammarResult;
|
||||||
string codeResult;
|
string codeResult;
|
||||||
@ -308,14 +318,16 @@ int run_server(int port, const vector<char>& syntax, const vector<char>& source)
|
|||||||
auto ret = parse_grammar(grammarText, peg, grammarResult);
|
auto ret = parse_grammar(grammarText, peg, grammarResult);
|
||||||
|
|
||||||
if (ret && peg) {
|
if (ret && peg) {
|
||||||
const auto& codeText = req.params.at("code");
|
const auto& codeText = req.get_param_value("code");
|
||||||
shared_ptr<peg::Ast> ast;
|
shared_ptr<peg::Ast> ast;
|
||||||
if (parse_code(codeText, peg, codeResult, ast)) {
|
if (parse_code(codeText, peg, codeResult, ast)) {
|
||||||
astResult = peg::ast_to_s(ast);
|
astResult = peg::ast_to_s(ast);
|
||||||
astResult = replace_all(astResult, "\n", "\\n");
|
astResult = replace_all(astResult, "\n", "\\n");
|
||||||
|
astResult = replace_all(astResult, "\"", "%22");
|
||||||
|
|
||||||
astResultOptimized = peg::ast_to_s(peg::AstOptimizer(true).optimize(ast));
|
astResultOptimized = peg::ast_to_s(peg::AstOptimizer(true).optimize(ast));
|
||||||
astResultOptimized = replace_all(astResultOptimized, "\n", "\\n");
|
astResultOptimized = replace_all(astResultOptimized, "\n", "\\n");
|
||||||
|
astResultOptimized = replace_all(astResultOptimized, "\"", "%22");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user