mirror of
https://github.com/ValKmjolnir/Nasal-Interpreter.git
synced 2026-05-02 02:40:47 +08:00
✨ mark in_curve in expr node
Signed-off-by: ValKmjolnir <lhk101lhk101@qq.com>
This commit is contained in:
@@ -61,15 +61,18 @@ class expr {
|
||||
protected:
|
||||
span nd_loc;
|
||||
expr_type nd_type;
|
||||
bool in_curve;
|
||||
|
||||
public:
|
||||
expr(const span& location, expr_type node_type):
|
||||
nd_loc(location), nd_type(node_type) {}
|
||||
nd_loc(location), nd_type(node_type), in_curve(false) {}
|
||||
virtual ~expr() = default;
|
||||
void set_begin(u64 line, u64 column) {
|
||||
nd_loc.begin_line = line;
|
||||
nd_loc.begin_column = column;
|
||||
}
|
||||
void set_in_curve() { in_curve = true; }
|
||||
auto get_in_curve() const { return in_curve; }
|
||||
const auto& get_location() const { return nd_loc; }
|
||||
const auto get_line() const { return nd_loc.begin_line; }
|
||||
auto get_type() const { return nd_type; }
|
||||
|
||||
@@ -151,19 +151,25 @@ bool ast_format::visit_parameter(parameter* node) {
|
||||
|
||||
bool ast_format::visit_ternary_operator(ternary_operator* node) {
|
||||
dump_formating_node_info(node, "ternary operator");
|
||||
out << "(";
|
||||
if (node->get_in_curve()) {
|
||||
out << "(";
|
||||
}
|
||||
node->get_condition()->accept(this);
|
||||
out << " ? ";
|
||||
node->get_left()->accept(this);
|
||||
out << " : ";
|
||||
node->get_right()->accept(this);
|
||||
out << ")";
|
||||
if (node->get_in_curve()) {
|
||||
out << ")";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ast_format::visit_binary_operator(binary_operator* node) {
|
||||
dump_formating_node_info(node, "binary operator");
|
||||
out << "(";
|
||||
if (node->get_in_curve()) {
|
||||
out << "(";
|
||||
}
|
||||
node->get_left()->accept(this);
|
||||
switch(node->get_operator_type()) {
|
||||
case binary_operator::kind::add: out << " + "; break;
|
||||
@@ -185,18 +191,26 @@ bool ast_format::visit_binary_operator(binary_operator* node) {
|
||||
case binary_operator::kind::null_chain: out << " ?? "; break;
|
||||
}
|
||||
node->get_right()->accept(this);
|
||||
out << ")";
|
||||
if (node->get_in_curve()) {
|
||||
out << ")";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ast_format::visit_unary_operator(unary_operator* node) {
|
||||
dump_formating_node_info(node, "unary operator");
|
||||
if (node->get_in_curve()) {
|
||||
out << "(";
|
||||
}
|
||||
switch(node->get_operator_type()) {
|
||||
case unary_operator::kind::negative: out << "-"; break;
|
||||
case unary_operator::kind::logical_not: out << "!"; break;
|
||||
case unary_operator::kind::bitwise_not: out << "~"; break;
|
||||
}
|
||||
node->get_value()->accept(this);
|
||||
if (node->get_in_curve()) {
|
||||
out << ")";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef __nasver__
|
||||
#define __nasver__ "11.3.3"
|
||||
#define __nasver__ "11.3.4"
|
||||
#endif
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
@@ -730,6 +730,7 @@ expr* parse::scalar() {
|
||||
match(tok::tk_lcurve);
|
||||
node = calc();
|
||||
node->set_begin(loc.begin_line, loc.begin_column);
|
||||
node->set_in_curve();
|
||||
update_location(node);
|
||||
match(tok::tk_rcurve);
|
||||
} else if (lookahead(tok::tk_var)) {
|
||||
|
||||
Reference in New Issue
Block a user