WsParser_VS/libSyntax/ast_gen.cpp

37 lines
1.1 KiB
C++
Raw Normal View History

2024-03-17 07:58:28 +00:00
#include "ast_gen.h"
2025-02-07 15:26:20 +00:00
#include "ast_access.h"
2024-03-17 07:58:28 +00:00
using namespace ast_gen;
2025-02-07 15:26:20 +00:00
using namespace ast_basic;
using namespace lib_token;
using namespace lib_syntax;
using namespace lib_words;
2024-03-17 07:58:28 +00:00
2025-02-07 15:26:20 +00:00
SyntaxParser::SyntaxParser(std::shared_ptr<IBasicRule> rule)
: _rule_bind(rule) { }
2024-03-17 07:58:28 +00:00
2025-02-07 15:26:20 +00:00
QList<std::shared_ptr<const MatchCursor>> SyntaxParser::parse(std::shared_ptr<IPrimitiveWord> words) {
auto cursor = std::make_shared<MatchCursor>();
cursor->setCurrent(nullptr, words);
2024-03-17 07:58:28 +00:00
2025-02-07 15:26:20 +00:00
auto list = this->_rule_bind->parse(cursor);
std::sort(list.begin(), list.end(),
[&](std::shared_ptr<const MatchCursor> a, std::shared_ptr<const MatchCursor> b) {
return a->totalErrorCount() < b->totalErrorCount();
});
2024-03-17 07:58:28 +00:00
2025-02-07 15:26:20 +00:00
return list;
2024-03-17 07:58:28 +00:00
}
2025-02-07 15:26:20 +00:00
#include "tokens_impl.h"
std::shared_ptr<IExprInstance> ast_gen::SyntaxParser::getAst(
std::shared_ptr<const lib_syntax::MatchCursor> cursor, std::shared_ptr<IExprInstance> root) {
2025-02-07 15:26:20 +00:00
std::shared_ptr<const IActionToken> action_token = cursor->currentToken();
while (action_token->prevToken()) {
action_token = action_token->prevToken();
}
2024-03-17 07:58:28 +00:00
2025-02-07 15:26:20 +00:00
return std::const_pointer_cast<IActionToken>(action_token)->makeSure(root);
2024-03-17 07:58:28 +00:00
}