Remove unnecessary params
This commit is contained in:
@@ -781,58 +781,54 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Reads a number from the input, detecting if it's an integer or floating point
|
/// Reads a number from the input, detecting if it's an integer or floating point
|
||||||
bool Num(const bool t_capture = false) {
|
bool Num() {
|
||||||
SkipWS();
|
SkipWS();
|
||||||
|
|
||||||
if (!t_capture) {
|
const auto start = m_position;
|
||||||
return Hex_() || Float_();
|
if (m_position.has_more() && char_in_alphabet(*m_position, detail::float_alphabet) ) {
|
||||||
} else {
|
try {
|
||||||
const auto start = m_position;
|
if (Hex_()) {
|
||||||
if (m_position.has_more() && char_in_alphabet(*m_position, detail::float_alphabet) ) {
|
auto match = Position::str(start, m_position);
|
||||||
try {
|
auto bv = buildInt(16, match, true);
|
||||||
if (Hex_()) {
|
m_match_stack.emplace_back(make_node<eval::Constant_AST_Node<Tracer>>(std::move(match), start.line, start.col, std::move(bv)));
|
||||||
auto match = Position::str(start, m_position);
|
return true;
|
||||||
auto bv = buildInt(16, match, true);
|
|
||||||
m_match_stack.emplace_back(make_node<eval::Constant_AST_Node<Tracer>>(std::move(match), start.line, start.col, std::move(bv)));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Binary_()) {
|
|
||||||
auto match = Position::str(start, m_position);
|
|
||||||
auto bv = buildInt(2, match, true);
|
|
||||||
m_match_stack.push_back(make_node<eval::Constant_AST_Node<Tracer>>(std::move(match), start.line, start.col, std::move(bv)));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (Float_()) {
|
|
||||||
auto match = Position::str(start, m_position);
|
|
||||||
auto bv = buildFloat(match);
|
|
||||||
m_match_stack.push_back(make_node<eval::Constant_AST_Node<Tracer>>(std::move(match), start.line, start.col, std::move(bv)));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
IntSuffix_();
|
|
||||||
auto match = Position::str(start, m_position);
|
|
||||||
if (!match.empty() && (match[0] == '0')) {
|
|
||||||
auto bv = buildInt(8, match, false);
|
|
||||||
m_match_stack.push_back(make_node<eval::Constant_AST_Node<Tracer>>(std::move(match), start.line, start.col, std::move(bv)));
|
|
||||||
}
|
|
||||||
else if (!match.empty()) {
|
|
||||||
auto bv = buildInt(10, match, false);
|
|
||||||
m_match_stack.push_back(make_node<eval::Constant_AST_Node<Tracer>>(std::move(match), start.line, start.col, std::move(bv)));
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (const std::invalid_argument &) {
|
|
||||||
// error parsing number passed in to buildFloat/buildInt
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
if (Binary_()) {
|
||||||
|
auto match = Position::str(start, m_position);
|
||||||
|
auto bv = buildInt(2, match, true);
|
||||||
|
m_match_stack.push_back(make_node<eval::Constant_AST_Node<Tracer>>(std::move(match), start.line, start.col, std::move(bv)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (Float_()) {
|
||||||
|
auto match = Position::str(start, m_position);
|
||||||
|
auto bv = buildFloat(match);
|
||||||
|
m_match_stack.push_back(make_node<eval::Constant_AST_Node<Tracer>>(std::move(match), start.line, start.col, std::move(bv)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
IntSuffix_();
|
||||||
|
auto match = Position::str(start, m_position);
|
||||||
|
if (!match.empty() && (match[0] == '0')) {
|
||||||
|
auto bv = buildInt(8, match, false);
|
||||||
|
m_match_stack.push_back(make_node<eval::Constant_AST_Node<Tracer>>(std::move(match), start.line, start.col, std::move(bv)));
|
||||||
|
}
|
||||||
|
else if (!match.empty()) {
|
||||||
|
auto bv = buildInt(10, match, false);
|
||||||
|
m_match_stack.push_back(make_node<eval::Constant_AST_Node<Tracer>>(std::move(match), start.line, start.col, std::move(bv)));
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (const std::invalid_argument &) {
|
||||||
|
// error parsing number passed in to buildFloat/buildInt
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads an identifier from input which conforms to C's identifier naming conventions, without skipping initial whitespace
|
/// Reads an identifier from input which conforms to C's identifier naming conventions, without skipping initial whitespace
|
||||||
@@ -1188,92 +1184,88 @@ namespace chaiscript
|
|||||||
|
|
||||||
|
|
||||||
/// Reads (and potentially captures) a quoted string from input. Translates escaped sequences.
|
/// Reads (and potentially captures) a quoted string from input. Translates escaped sequences.
|
||||||
bool Quoted_String(const bool t_capture = false) {
|
bool Quoted_String() {
|
||||||
SkipWS();
|
SkipWS();
|
||||||
|
|
||||||
if (!t_capture) {
|
const auto start = m_position;
|
||||||
return Quoted_String_();
|
|
||||||
} else {
|
|
||||||
const auto start = m_position;
|
|
||||||
|
|
||||||
if (Quoted_String_()) {
|
if (Quoted_String_()) {
|
||||||
std::string match;
|
std::string match;
|
||||||
const auto prev_stack_top = m_match_stack.size();
|
const auto prev_stack_top = m_match_stack.size();
|
||||||
|
|
||||||
bool is_interpolated = [&]()->bool {
|
bool is_interpolated = [&]()->bool {
|
||||||
Char_Parser<std::string> cparser(match, true);
|
Char_Parser<std::string> cparser(match, true);
|
||||||
|
|
||||||
|
|
||||||
auto s = start + 1, end = m_position - 1;
|
auto s = start + 1, end = m_position - 1;
|
||||||
|
|
||||||
while (s != end) {
|
while (s != end) {
|
||||||
if (cparser.saw_interpolation_marker) {
|
if (cparser.saw_interpolation_marker) {
|
||||||
if (*s == '{') {
|
if (*s == '{') {
|
||||||
//We've found an interpolation point
|
//We've found an interpolation point
|
||||||
|
|
||||||
m_match_stack.push_back(make_node<eval::Constant_AST_Node<Tracer>>(match, start.line, start.col, const_var(match)));
|
m_match_stack.push_back(make_node<eval::Constant_AST_Node<Tracer>>(match, start.line, start.col, const_var(match)));
|
||||||
|
|
||||||
if (cparser.is_interpolated) {
|
if (cparser.is_interpolated) {
|
||||||
//If we've seen previous interpolation, add on instead of making a new one
|
//If we've seen previous interpolation, add on instead of making a new one
|
||||||
build_match<eval::Binary_Operator_AST_Node<Tracer>>(prev_stack_top, "+");
|
build_match<eval::Binary_Operator_AST_Node<Tracer>>(prev_stack_top, "+");
|
||||||
}
|
|
||||||
|
|
||||||
//We've finished with the part of the string up to this point, so clear it
|
|
||||||
match.clear();
|
|
||||||
|
|
||||||
std::string eval_match;
|
|
||||||
|
|
||||||
++s;
|
|
||||||
while ((s != end) && (*s != '}')) {
|
|
||||||
eval_match.push_back(*s);
|
|
||||||
++s;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*s == '}') {
|
|
||||||
cparser.is_interpolated = true;
|
|
||||||
++s;
|
|
||||||
|
|
||||||
const auto tostr_stack_top = m_match_stack.size();
|
|
||||||
|
|
||||||
m_match_stack.push_back(make_node<eval::Id_AST_Node<Tracer>>("to_string", start.line, start.col));
|
|
||||||
|
|
||||||
const auto ev_stack_top = m_match_stack.size();
|
|
||||||
|
|
||||||
try {
|
|
||||||
m_match_stack.push_back(parse_instr_eval(eval_match));
|
|
||||||
} catch (const exception::eval_error &e) {
|
|
||||||
throw exception::eval_error(e.what(), File_Position(start.line, start.col), *m_filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
build_match<eval::Arg_List_AST_Node<Tracer>>(ev_stack_top);
|
|
||||||
build_match<eval::Fun_Call_AST_Node<Tracer>>(tostr_stack_top);
|
|
||||||
build_match<eval::Binary_Operator_AST_Node<Tracer>>(prev_stack_top, "+");
|
|
||||||
} else {
|
|
||||||
throw exception::eval_error("Unclosed in-string eval", File_Position(start.line, start.col), *m_filename);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
match.push_back('$');
|
|
||||||
}
|
}
|
||||||
cparser.saw_interpolation_marker = false;
|
|
||||||
} else {
|
//We've finished with the part of the string up to this point, so clear it
|
||||||
cparser.parse(*s, start.line, start.col, *m_filename);
|
match.clear();
|
||||||
|
|
||||||
|
std::string eval_match;
|
||||||
|
|
||||||
++s;
|
++s;
|
||||||
|
while ((s != end) && (*s != '}')) {
|
||||||
|
eval_match.push_back(*s);
|
||||||
|
++s;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*s == '}') {
|
||||||
|
cparser.is_interpolated = true;
|
||||||
|
++s;
|
||||||
|
|
||||||
|
const auto tostr_stack_top = m_match_stack.size();
|
||||||
|
|
||||||
|
m_match_stack.push_back(make_node<eval::Id_AST_Node<Tracer>>("to_string", start.line, start.col));
|
||||||
|
|
||||||
|
const auto ev_stack_top = m_match_stack.size();
|
||||||
|
|
||||||
|
try {
|
||||||
|
m_match_stack.push_back(parse_instr_eval(eval_match));
|
||||||
|
} catch (const exception::eval_error &e) {
|
||||||
|
throw exception::eval_error(e.what(), File_Position(start.line, start.col), *m_filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
build_match<eval::Arg_List_AST_Node<Tracer>>(ev_stack_top);
|
||||||
|
build_match<eval::Fun_Call_AST_Node<Tracer>>(tostr_stack_top);
|
||||||
|
build_match<eval::Binary_Operator_AST_Node<Tracer>>(prev_stack_top, "+");
|
||||||
|
} else {
|
||||||
|
throw exception::eval_error("Unclosed in-string eval", File_Position(start.line, start.col), *m_filename);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
match.push_back('$');
|
||||||
}
|
}
|
||||||
|
cparser.saw_interpolation_marker = false;
|
||||||
|
} else {
|
||||||
|
cparser.parse(*s, start.line, start.col, *m_filename);
|
||||||
|
++s;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cparser.is_interpolated;
|
|
||||||
}();
|
|
||||||
|
|
||||||
m_match_stack.push_back(make_node<eval::Constant_AST_Node<Tracer>>(match, start.line, start.col, const_var(match)));
|
|
||||||
|
|
||||||
if (is_interpolated) {
|
|
||||||
build_match<eval::Binary_Operator_AST_Node<Tracer>>(prev_stack_top, "+");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return cparser.is_interpolated;
|
||||||
} else {
|
}();
|
||||||
return false;
|
|
||||||
|
m_match_stack.push_back(make_node<eval::Constant_AST_Node<Tracer>>(match, start.line, start.col, const_var(match)));
|
||||||
|
|
||||||
|
if (is_interpolated) {
|
||||||
|
build_match<eval::Binary_Operator_AST_Node<Tracer>>(prev_stack_top, "+");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1306,35 +1298,31 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Reads (and potentially captures) a char group from input. Translates escaped sequences.
|
/// Reads (and potentially captures) a char group from input. Translates escaped sequences.
|
||||||
bool Single_Quoted_String(const bool t_capture = false) {
|
bool Single_Quoted_String() {
|
||||||
SkipWS();
|
SkipWS();
|
||||||
|
|
||||||
if (!t_capture) {
|
const auto start = m_position;
|
||||||
return Single_Quoted_String_();
|
if (Single_Quoted_String_()) {
|
||||||
} else {
|
std::string match;
|
||||||
const auto start = m_position;
|
|
||||||
if (Single_Quoted_String_()) {
|
|
||||||
std::string match;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
// scope for cparser destructor
|
// scope for cparser destructor
|
||||||
Char_Parser<std::string> cparser(match, false);
|
Char_Parser<std::string> cparser(match, false);
|
||||||
|
|
||||||
for (auto s = start + 1, end = m_position - 1; s != end; ++s) {
|
for (auto s = start + 1, end = m_position - 1; s != end; ++s) {
|
||||||
cparser.parse(*s, start.line, start.col, *m_filename);
|
cparser.parse(*s, start.line, start.col, *m_filename);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match.size() != 1) {
|
|
||||||
throw exception::eval_error("Single-quoted strings must be 1 character long", File_Position(m_position.line, m_position.col), *m_filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_match_stack.push_back(make_node<eval::Constant_AST_Node<Tracer>>(match, start.line, start.col, const_var(char(match.at(0)))));
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return false;
|
if (match.size() != 1) {
|
||||||
|
throw exception::eval_error("Single-quoted strings must be 1 character long", File_Position(m_position.line, m_position.col), *m_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_match_stack.push_back(make_node<eval::Constant_AST_Node<Tracer>>(match, start.line, start.col, const_var(char(match.at(0)))));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2088,7 +2076,7 @@ namespace chaiscript
|
|||||||
bool retval = false;
|
bool retval = false;
|
||||||
|
|
||||||
const auto prev_stack_top = m_match_stack.size();
|
const auto prev_stack_top = m_match_stack.size();
|
||||||
if (Lambda() || Num(true) || Quoted_String(true) || Single_Quoted_String(true) ||
|
if (Lambda() || Num() || Quoted_String() || Single_Quoted_String() ||
|
||||||
Paren_Expression() || Inline_Container() || Id(false))
|
Paren_Expression() || Inline_Container() || Id(false))
|
||||||
{
|
{
|
||||||
retval = true;
|
retval = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user