mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-05 22:48:43 +00:00
or_in or_out references added
This commit is contained in:
parent
fc114ff959
commit
68463509d8
9 changed files with 29 additions and 12 deletions
2
deps/tree-sitter-lang
vendored
2
deps/tree-sitter-lang
vendored
|
|
@ -1 +1 @@
|
|||
Subproject commit a75ea8012d6b104fb26efcd17e5ebc02ab49f7af
|
||||
Subproject commit 9c44228eec3d81caf1c1708a2f4d181037b85c16
|
||||
|
|
@ -18,6 +18,8 @@
|
|||
<item>out</item>
|
||||
<item>in</item>
|
||||
<item>ref</item>
|
||||
<item>or_out</item>
|
||||
<item>or_in</item>
|
||||
<item>let</item>
|
||||
<item>var</item>
|
||||
<item>lambda</item>
|
||||
|
|
@ -48,7 +50,7 @@
|
|||
|
||||
<RegExpr String="\@[a-z_][a-z0-9_]*(?![a-z0-9_])" attribute="Annotation" context="#stay"/>
|
||||
|
||||
<RegExpr String="(\:\=)|(\=\:)|\%|\\|\$|(\:\:)|(\-\>)|(<\-)|(<\>)|^" attribute="Keyword" context="#stay"/>
|
||||
<RegExpr String="(\:\=)|(\=\:)|\%|\\|\$|(\:\:)|(\|?\-\>)|(<\-\|?)|(<\>)|^" attribute="Keyword" context="#stay"/>
|
||||
|
||||
<RegExpr String="\@|\:|(\?\?)|(\!\!)|(\=\>)" attribute="Control Flow" context="#stay"/>
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,9 @@ namespace nodes {
|
|||
enum class Modifier {
|
||||
OUT, // -> x
|
||||
IN, // <- x
|
||||
REF, // <> x
|
||||
REF, // <> x // IN and OUT
|
||||
OR_OUT, // |-> // OUT or NONE
|
||||
OR_IN, // <-| // IN or NONE
|
||||
OPTIONAL, // x?
|
||||
RESULT, // x!
|
||||
NONE,
|
||||
|
|
|
|||
|
|
@ -52,8 +52,13 @@ nodes::Modifier build_modifier(parser::ParseTree::Node parser_node) {
|
|||
return nodes::Modifier::IN;
|
||||
} else if (modifier == "<>" || modifier == "ref") {
|
||||
return nodes::Modifier::REF;
|
||||
} else if (modifier == "|->" || modifier == "or_out") {
|
||||
return nodes::Modifier::OR_OUT;
|
||||
} else if (modifier == "<-|" || modifier == "or_in") {
|
||||
return nodes::Modifier::OR_IN;
|
||||
} else {
|
||||
return nodes::Modifier::NONE;
|
||||
}
|
||||
return nodes::Modifier::NONE;
|
||||
}
|
||||
|
||||
nodes::Node build_node(parser::ParseTree::Node parser_node) {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,13 @@ void print_modifier(const nodes::Modifier &modifier, Printer &printer) {
|
|||
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 "
|
||||
: "|-> ");
|
||||
break;
|
||||
case nodes::Modifier::OR_IN:
|
||||
printer.print(printer.print_words_instead_of_symbols() ? "or_in " : "<-| ");
|
||||
break;
|
||||
case nodes::Modifier::OPTIONAL:
|
||||
printer.print("?");
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ void print_condition(const nodes::Condition &expression,
|
|||
}
|
||||
|
||||
void print_loop(const nodes::Loop &expression, printers::Printer &printer) {
|
||||
printer.print(printer.print_words_instead_of_symbols() ? "for " : "@");
|
||||
printer.print(printer.print_words_instead_of_symbols() ? "for" : "@");
|
||||
|
||||
switch (expression.get_type()) {
|
||||
case nodes::Loop::LOOP:
|
||||
|
|
@ -330,9 +330,8 @@ void print_loop_control(const nodes::LoopControl &expression,
|
|||
|
||||
void print_modifier_expression(const nodes::ModifierExpression &expression,
|
||||
printers::Printer &printer) {
|
||||
if (expression.get_modifier() == nodes::Modifier::OUT ||
|
||||
expression.get_modifier() == nodes::Modifier::IN ||
|
||||
expression.get_modifier() == nodes::Modifier::REF) {
|
||||
if (expression.get_modifier() != nodes::Modifier::OPTIONAL &&
|
||||
expression.get_modifier() != nodes::Modifier::RESULT) {
|
||||
print_modifier(expression.get_modifier(), printer);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,6 @@ int main(int argc, char **argv) {
|
|||
auto statements = builders::build_source_file(
|
||||
parse_tree.get_root(), expression_storage, type_storage, name_tree);
|
||||
|
||||
printers::Printer printer(std::cout, 2, 80, false);
|
||||
printers::Printer printer(std::cout, 2, 80, true);
|
||||
printers::print_source_file(statements, printer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -297,9 +297,8 @@ build_function_definition(parser::ParseTree::Node parser_node,
|
|||
last_before_modifier = build_modifier(maybe_reference_node);
|
||||
|
||||
// only out, in, ref allowed
|
||||
if (last_before_modifier != nodes::Modifier::OUT &&
|
||||
last_before_modifier != nodes::Modifier::IN &&
|
||||
last_before_modifier != nodes::Modifier::REF) {
|
||||
if (last_before_modifier == nodes::Modifier::OPTIONAL ||
|
||||
last_before_modifier == nodes::Modifier::RESULT) {
|
||||
last_before_modifier = nodes::Modifier::NONE;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -214,3 +214,6 @@ parse_number : Unit! = {
|
|||
number.print;
|
||||
bring ();
|
||||
}
|
||||
|
||||
: example of or_in and or_out usage for template operators
|
||||
( & ) |-> 'a |-> 'b <-| 'x <-| 'y = (|-> 'a := <-| 'x) && (|-> 'b := <-| 'y);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue