mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-06 15:08:48 +00:00
printing fixes
This commit is contained in:
parent
0bb72e0b10
commit
469cb3581f
23 changed files with 318 additions and 151 deletions
|
|
@ -2,11 +2,13 @@
|
|||
|
||||
#include "basic_builders.hpp"
|
||||
#include "basic_nodes.hpp"
|
||||
#include "basic_printers.hpp"
|
||||
#include "doc_builders.hpp"
|
||||
#include "doc_nodes.hpp"
|
||||
#include "error_handling.hpp"
|
||||
#include "expression_builders.hpp"
|
||||
#include "statement_nodes.hpp"
|
||||
#include "statement_printers.hpp"
|
||||
#include "tokens.hpp"
|
||||
#include "tree_sitter_wrapper.hpp"
|
||||
#include "type_builders.hpp"
|
||||
|
|
@ -37,18 +39,42 @@ void build_statement(parser::ParseTree::Node parser_node,
|
|||
nodes::TypeStorage &type_storage) {
|
||||
tokens::Type type = tokens::string_to_type(parser_node.get_type());
|
||||
|
||||
printers::Printer printer(std::cout, 2, 80, false);
|
||||
|
||||
switch (type) {
|
||||
case tokens::Type::IMPORT:
|
||||
build_import(parser_node);
|
||||
printers::print_import(build_import(parser_node),
|
||||
printer); // TODO TEMPORARY
|
||||
printer.new_indent_line();
|
||||
return;
|
||||
case tokens::Type::TYPE_DEFINITION:
|
||||
build_type_definition(parser_node, expression_storage, type_storage);
|
||||
printers::print_type_definition(
|
||||
build_type_definition(parser_node, expression_storage, type_storage),
|
||||
printer); // TODO TEMPORARY
|
||||
printer.new_indent_line();
|
||||
return;
|
||||
case tokens::Type::FUNCTION_DEFINITION:
|
||||
build_function_definition(parser_node, expression_storage, type_storage);
|
||||
printers::print_function_definition(
|
||||
build_function_definition(parser_node, expression_storage,
|
||||
type_storage),
|
||||
printer); // TODO TEMPORARY
|
||||
printer.new_indent_line();
|
||||
return;
|
||||
case tokens::Type::TYPECLASS_DEFINITION:
|
||||
build_typeclass_definition(parser_node, expression_storage, type_storage);
|
||||
printers::print_typeclass_definition(
|
||||
build_typeclass_definition(parser_node, expression_storage,
|
||||
type_storage),
|
||||
printer); // TODO TEMPORARY
|
||||
printer.new_indent_line();
|
||||
return;
|
||||
case tokens::Type::EMPTY_LINES:
|
||||
build_empty_lines(parser_node);
|
||||
printers::print_empty_lines(build_empty_lines(parser_node),
|
||||
printer); // TODO TEMPORARY
|
||||
return;
|
||||
default:
|
||||
error_handling::handle_parsing_error("Unexprected statement node type",
|
||||
|
|
@ -219,7 +245,7 @@ build_function_definition(parser::ParseTree::Node parser_node,
|
|||
nodes::FunctionDefinition::STATIC;
|
||||
|
||||
current_node = name_node.previous_sibling();
|
||||
if (!current_node.is_null() && current_node.is_named()) {
|
||||
if (!current_node.is_null() && !current_node.is_named()) {
|
||||
std::string modifier_str = current_node.get_value();
|
||||
if (modifier_str == "%" || modifier_str == "let") {
|
||||
modifier = nodes::FunctionDefinition::LET;
|
||||
|
|
@ -270,11 +296,11 @@ build_function_definition(parser::ParseTree::Node parser_node,
|
|||
argument_reference_types.push_back(last_reference_type);
|
||||
arguments.push_back(build_identifier(current_node));
|
||||
optional_arguments.push_back(!current_node.next_sibling().is_null() &&
|
||||
current_node.next_sibling().is_named() &&
|
||||
!current_node.next_sibling().is_named() &&
|
||||
current_node.next_sibling().get_value() ==
|
||||
"?");
|
||||
result_arguments.push_back(!current_node.next_sibling().is_null() &&
|
||||
current_node.next_sibling().is_named() &&
|
||||
!current_node.next_sibling().is_named() &&
|
||||
current_node.next_sibling().get_value() ==
|
||||
"!");
|
||||
if (optional_arguments.back() || result_arguments.back()) {
|
||||
|
|
@ -306,7 +332,10 @@ build_function_definition(parser::ParseTree::Node parser_node,
|
|||
std::vector<std::optional<std::string>> *annotations = nullptr;
|
||||
std::vector<nodes::Modifier> *reference_types = nullptr;
|
||||
|
||||
if (!at_least_one_argument_annotation_found) {
|
||||
bool is_annotations_same_to_names =
|
||||
(!at_least_one_argument_annotation_found && types.empty());
|
||||
|
||||
if (is_annotations_same_to_names) {
|
||||
for (size_t i = 0; i < argument_annotations.size(); ++i) {
|
||||
std::string argument_annotation = *arguments[i].get();
|
||||
argument_annotations[i] =
|
||||
|
|
@ -346,6 +375,7 @@ build_function_definition(parser::ParseTree::Node parser_node,
|
|||
std::move(*annotations), std::move(arguments),
|
||||
std::move(*reference_types), std::move(types),
|
||||
std::move(optional_arguments), std::move(result_arguments),
|
||||
is_annotations_same_to_names,
|
||||
expression_node.has_value()
|
||||
? build_expression(expression_node.value(), expression_storage,
|
||||
type_storage)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue