From a38d89cb412edc582d2ca784d6941da4f656cd6c Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 1 Mar 2014 13:49:03 -0700 Subject: [PATCH] Add fixes for parsing of inplace vectors with newlines from jespada --- .../chaiscript/language/chaiscript_parser.hpp | 23 ++++++++++++++++--- releasenotes.txt | 1 + unittests/vector_inplace_init.chai | 7 ++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index 3580c9f..0b30cc4 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -317,13 +317,21 @@ namespace chaiscript /** * Skips ChaiScript whitespace, which means space and tab, but not cr/lf + * jespada: Modified SkipWS to skip optionally CR ('\n') */ - bool SkipWS() { + bool SkipWS(bool skip_cr=false) { bool retval = false; while (has_more_input()) { - if ( char_in_alphabet(*m_input_pos,detail::white_alphabet) ) { + if ( char_in_alphabet(*m_input_pos,detail::white_alphabet) || (skip_cr && (*m_input_pos == '\n'))) { + if(*m_input_pos == '\n') { + m_col = 1; + ++m_line; + } + else { + ++m_col; + } ++m_input_pos; - ++m_col; + retval = true; } else if (SkipComment()) { @@ -1241,6 +1249,8 @@ namespace chaiscript * Reads a comma-separated list of values from input */ bool Arg_List() { + + SkipWS(true); bool retval = false; size_t prev_stack_top = m_match_stack.size(); @@ -1259,6 +1269,8 @@ namespace chaiscript build_match(AST_NodePtr(new eval::Arg_List_AST_Node()), prev_stack_top); } + SkipWS(true); + return retval; } @@ -1267,6 +1279,7 @@ namespace chaiscript */ bool Container_Arg_List() { bool retval = false; + SkipWS(true); size_t prev_stack_top = m_match_stack.size(); @@ -1301,6 +1314,8 @@ namespace chaiscript build_match(AST_NodePtr(new eval::Arg_List_AST_Node()), prev_stack_top); } + SkipWS(true); + return retval; } @@ -1917,6 +1932,7 @@ namespace chaiscript if (Char('[')) { retval = true; Container_Arg_List(); + if (!Char(']')) { throw exception::eval_error("Missing closing square bracket ']' in container initializer", File_Position(m_line, m_col), *m_filename); } @@ -2228,6 +2244,7 @@ namespace chaiscript Symbol("-=", true, true) || Symbol("*=", true, true) || Symbol("/=", true, true) || Symbol("%=", true, true) || Symbol("<<=", true, true) || Symbol(">>=", true, true) || Symbol("&=", true, true) || Symbol("^=", true, true) || Symbol("|=", true, true)) { + SkipWS(true); if (!Equation()) { throw exception::eval_error("Incomplete equation", File_Position(m_line, m_col), *m_filename); } diff --git a/releasenotes.txt b/releasenotes.txt index 9e3d8e2..c25d0dd 100644 --- a/releasenotes.txt +++ b/releasenotes.txt @@ -21,6 +21,7 @@ Notes: * Fix various string / map / vector `size` and `count` calls for compilers which have weird overloads for them. #90 #93 #95 * Make module search path relative to the currently running executable * Build and work with wstring windows builds +* fix for some new line cases in the middle of a vector initialization from jespada ### Changes since 5.1.0 * Add support for automatic conversion of arithmetic types when possible diff --git a/unittests/vector_inplace_init.chai b/unittests/vector_inplace_init.chai index e3bf6a3..56e0690 100644 --- a/unittests/vector_inplace_init.chai +++ b/unittests/vector_inplace_init.chai @@ -3,6 +3,7 @@ assert_equal(3, x.size()) + // Make sure vector elements are copied into place for consistency with // map inplace construction var i = 1; @@ -12,3 +13,9 @@ assert_equal(1, y[0]); i = 3; assert_equal(3, i); assert_equal(1, y[0]); + + +// make sure initialization with a break in the middle works as expected +var a = [0.0,0.0, + 1.0,1.0] +