40 lines
910 B
C++
40 lines
910 B
C++
#include <pslang/parser/parser.hpp>
|
|
#include <pslang/parser/context.hpp>
|
|
#include <pslang/parser/indented_statement.hpp>
|
|
#include <pslang/ast/location.hpp>
|
|
#include "gen_parser.hpp"
|
|
#include "gen_lexer.hpp"
|
|
|
|
namespace pslang::parser
|
|
{
|
|
|
|
ast::statement_ptr parse(std::string_view path)
|
|
{
|
|
yyin = fopen(path.data(), "r");
|
|
if (!yyin)
|
|
throw std::system_error(std::make_error_code(static_cast<std::errc>(errno)));
|
|
|
|
ast::location location{.begin = {.filename = path}, .end = {.filename = path}};
|
|
indented_statement_list statements;
|
|
context ctx{location, statements};
|
|
|
|
bison::parser parser(ctx);
|
|
|
|
parser.parse();
|
|
|
|
fclose(yyin);
|
|
|
|
// Add a fake AST node for the entry point
|
|
return std::make_shared<ast::statement>(ast::function_definition{
|
|
{
|
|
"[entry point]",
|
|
{},
|
|
std::make_shared<ast::type>(types::unit_type{}),
|
|
{},
|
|
},
|
|
finalize(std::move(statements)),
|
|
{},
|
|
});
|
|
}
|
|
|
|
}
|