mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2026-01-25 13:07:13 +00:00
or references, prining improvements, comments now printed, fixes
This commit is contained in:
parent
73263193a9
commit
5e70f0015f
19 changed files with 354 additions and 429 deletions
|
|
@ -1,29 +1,77 @@
|
|||
#include "basic_printers.hpp"
|
||||
|
||||
#include "error_handling.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "basic_nodes.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
namespace printers {
|
||||
|
||||
void print_modifier(const nodes::Modifier &modifier, Printer &printer) {
|
||||
void print_modifier(const nodes::Modifier &modifier, Printer &printer,
|
||||
bool const_is_none) {
|
||||
switch (modifier) {
|
||||
case nodes::Modifier::OUT:
|
||||
printer.print(printer.print_words_instead_of_symbols() ? "out " : "-> ");
|
||||
break;
|
||||
case nodes::Modifier::IN:
|
||||
printer.print(printer.print_words_instead_of_symbols() ? "in " : "<- ");
|
||||
break;
|
||||
case nodes::Modifier::REF:
|
||||
printer.print(printer.print_words_instead_of_symbols() ? "ref " : "<> ");
|
||||
break;
|
||||
case nodes::Modifier::OR_OUT:
|
||||
printer.print(printer.print_words_instead_of_symbols() ? "or_out "
|
||||
: "|-> ");
|
||||
case nodes::Modifier::CONST:
|
||||
if (!const_is_none) {
|
||||
printer.print(printer.print_words_instead_of_symbols() ? "ref " : "<> ");
|
||||
}
|
||||
break;
|
||||
case nodes::Modifier::OR_IN:
|
||||
printer.print(printer.print_words_instead_of_symbols() ? "or_in " : "<-| ");
|
||||
case nodes::Modifier::OUT:
|
||||
printer.print(printer.print_words_instead_of_symbols() ? "out " : "-> ");
|
||||
break;
|
||||
// ---
|
||||
case nodes::Modifier::IN_OR_REF:
|
||||
printer.print(printer.print_words_instead_of_symbols() ? "in|ref "
|
||||
: "<-|<> ");
|
||||
break;
|
||||
case nodes::Modifier::IN_OR_CONST:
|
||||
printer.print(printer.print_words_instead_of_symbols() ? "in|const "
|
||||
: "<-|-- ");
|
||||
break;
|
||||
case nodes::Modifier::REF_OR_OUT:
|
||||
printer.print(printer.print_words_instead_of_symbols() ? "ref|out "
|
||||
: "<>|-> ");
|
||||
break;
|
||||
case nodes::Modifier::CONST_OR_OUT:
|
||||
printer.print(printer.print_words_instead_of_symbols() ? "const|out "
|
||||
: "--|-> ");
|
||||
break;
|
||||
case nodes::Modifier::REF_OR_CONST:
|
||||
printer.print(printer.print_words_instead_of_symbols() ? "ref|const "
|
||||
: "<>|-- ");
|
||||
break;
|
||||
case nodes::Modifier::IN_OR_OUT:
|
||||
printer.print(printer.print_words_instead_of_symbols() ? "in|out "
|
||||
: "<-|-> ");
|
||||
break;
|
||||
// ---
|
||||
case nodes::Modifier::IN_OR_REF_OR_OUT:
|
||||
printer.print(printer.print_words_instead_of_symbols() ? "in|ref|out "
|
||||
: "<-|<>|-> ");
|
||||
break;
|
||||
case nodes::Modifier::IN_OR_CONST_OR_OUT:
|
||||
printer.print(printer.print_words_instead_of_symbols() ? "in|const|out "
|
||||
: "<-|--|-> ");
|
||||
break;
|
||||
case nodes::Modifier::IN_OR_REF_OR_CONST:
|
||||
printer.print(printer.print_words_instead_of_symbols() ? "in|ref|const "
|
||||
: "<-|<>|-- ");
|
||||
break;
|
||||
case nodes::Modifier::REF_OR_CONST_OR_OUT:
|
||||
printer.print(printer.print_words_instead_of_symbols() ? "ref|const|out "
|
||||
: "<>|--|-> ");
|
||||
break;
|
||||
// ---
|
||||
case nodes::Modifier::IN_OR_REF_OR_CONST_OR_OUT:
|
||||
printer.print(printer.print_words_instead_of_symbols() ? "in|ref|const|out "
|
||||
: "<-|<>|--|-> ");
|
||||
break;
|
||||
//
|
||||
case nodes::Modifier::OPTIONAL:
|
||||
printer.print("?");
|
||||
break;
|
||||
|
|
@ -84,8 +132,12 @@ void print_annotation(const std::string &annotation, Printer &printer) {
|
|||
printer.print(annotation);
|
||||
}
|
||||
|
||||
void print_extra(const nodes::Extra &extra, Printer &printer) {
|
||||
printer.print(*extra.content());
|
||||
}
|
||||
|
||||
void print_empty_lines(const nodes::EmptyLines &empty_lines, Printer &printer) {
|
||||
for (size_t i = 0; i < empty_lines.size(); ++i) {
|
||||
for (size_t i = 0; i < empty_lines.line_count(); ++i) {
|
||||
printer.new_indent_line();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue