Macro-processor, comprehension: fix error message, add comments

issue#70
Sébastien Villemot 2018-09-24 18:17:28 +02:00
parent 3e5c8dd80d
commit 913bc2f8c2
2 changed files with 11 additions and 1 deletions

View File

@ -323,7 +323,7 @@ MacroDriver::possibly_add_comprehension_element(vector<MacroValuePtr> &v, MacroV
{ {
auto ival = dynamic_pointer_cast<IntMV>(test_expr); auto ival = dynamic_pointer_cast<IntMV>(test_expr);
if (!ival) if (!ival)
throw MacroValue::TypeError("In a comprehension, the expression after the 'if' must evaluate to an integer"); throw MacroValue::TypeError("In a comprehension, the expression after the semicolon must evaluate to an integer");
if (ival->value) if (ival->value)
{ {
assert(!comprehension_stack.empty()); assert(!comprehension_stack.empty());

View File

@ -129,11 +129,17 @@ private:
//! Set to true while parsing an IF statement (only the statement, not the body) //! Set to true while parsing an IF statement (only the statement, not the body)
bool reading_if_statement; bool reading_if_statement;
//! Set to true while parsing the comprehension in a new buffer
bool is_comprehension_context{false}; bool is_comprehension_context{false};
//! Counter for the current comprehension
int comprehension_iter_nb{0}; int comprehension_iter_nb{0};
//! The lexer start condition (EXPR or STMT) before entering the comprehension
int comprehension_start_condition; int comprehension_start_condition;
//! Number of nested comprehensions, used during the construction of the new lexer buffer
int nested_comprehension_nb{0}; int nested_comprehension_nb{0};
//! Temporary stores for the new lexer buffer
string comprehension_clause, comprehension_clause_tmp; string comprehension_clause, comprehension_clause_tmp;
//! Stores for the location of the comprehension clause
Macro::parser::location_type comprehension_clause_loc, comprehension_clause_loc_tmp; Macro::parser::location_type comprehension_clause_loc, comprehension_clause_loc_tmp;
//! Output the @#line declaration //! Output the @#line declaration
@ -266,9 +272,13 @@ public:
in that case it destroys the pointer given to init_loop() */ in that case it destroys the pointer given to init_loop() */
bool iter_loop() noexcept(false); bool iter_loop() noexcept(false);
//! Initializes the evaluation of a comprehension
void init_comprehension(const vector<string> &names, MacroValuePtr value); void init_comprehension(const vector<string> &names, MacroValuePtr value);
//! Iterates during the evaluation of the comprehension
void iter_comprehension(); void iter_comprehension();
//! Helper to construct the value corresponding to the comprehension
void possibly_add_comprehension_element(vector<MacroValuePtr> &v, MacroValuePtr test_expr) const; void possibly_add_comprehension_element(vector<MacroValuePtr> &v, MacroValuePtr test_expr) const;
//! Returns the size of the set over which the current comprehension iterates
int get_comprehension_iter_nb() const; int get_comprehension_iter_nb() const;
//! Begins an @#if statement //! Begins an @#if statement