Make selections ignore \r in input
authorTeemu Murtola <teemu.murtola@gmail.com>
Sun, 6 Jul 2014 04:04:57 +0000 (07:04 +0300)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Tue, 8 Jul 2014 13:09:53 +0000 (15:09 +0200)
Now the selection engine treats \r (as well as various other space
characters) the same as a space.  Added a unit test for this.
There is an extra trailing space in some cases that may be more common
with \r\n than otherwise, but that is a separate, mostly cosmetic
issue.

Fixes #1555

Change-Id: I78dfe8e477133b98a98fecf1fad243262f9b30c8

src/gromacs/selection/scanner.cpp
src/gromacs/selection/scanner.l
src/gromacs/selection/tests/selectioncollection.cpp

index 64fba395a0167a7f0d1aa40ab5739db078feb12e..84eadc60b30b69641eb4a7850e5caf5b8cef40a5 100644 (file)
@@ -379,7 +379,7 @@ static yyconst flex_int16_t yy_accept[76] =
 static yyconst flex_int32_t yy_ec[256] =
     {   0,
         1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
-        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        2,    2,    2,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    2,    4,    5,    6,    1,    1,    7,    1,    1,
         1,    1,    8,    1,    8,    9,    1,   10,   10,   10,
@@ -418,14 +418,14 @@ static yyconst flex_int32_t yy_meta[33] =
 
 static yyconst flex_int16_t yy_base[80] =
     {   0,
-        0,    0,   89,   88,   10,   12,    0,    0,  111,  114,
-      108,  114,   96,   32,    0,  101,   97,   29,  114,   93,
-       92,    0,  101,   94,   79,   75,   76,   73,   74,   73,
-       64,   19,   71,   29,   74,   91,  114,   37,  114,   87,
-        0,  114,   36,   44,   48,   82,   52,    0,  114,   71,
-       65,   60,    0,    0,   61,  114,    0,   58,   64,    0,
-       57,   57,   73,   60,    0,   53,    0,    0,    0,   71,
-       66,   62,   41,    0,  114,   70,   74,   76,   43
+        0,    0,   93,   92,   10,   12,    0,    0,  115,  118,
+       35,   37,  101,   37,    0,  106,  102,   35,  118,   98,
+       97,    0,  106,   99,   84,   80,   81,   78,   79,   78,
+       69,   25,   76,   26,   79,   54,  118,   43,  118,   93,
+        0,  118,   48,   50,   52,   88,   65,    0,  118,   77,
+       71,   66,    0,    0,   67,  118,    0,   64,   70,    0,
+       63,   56,   79,   67,    0,   59,    0,    0,    0,   73,
+       69,   61,   44,    0,  118,   77,   81,   83,   50
     } ;
 
 static yyconst flex_int16_t yy_def[80] =
@@ -440,44 +440,44 @@ static yyconst flex_int16_t yy_def[80] =
        75,   75,   79,   79,    0,   75,   75,   75,   75
     } ;
 
-static yyconst flex_int16_t yy_nxt[147] =
+static yyconst flex_int16_t yy_nxt[151] =
     {   0,
        10,   11,   12,   13,   14,   15,   16,   10,   17,   18,
        19,   20,   21,   22,   22,   23,   24,   25,   22,   22,
        22,   26,   27,   28,   22,   22,   22,   29,   22,   30,
-       22,   31,   33,   34,   33,   34,   39,   44,   45,   57,
-       35,   39,   35,   47,   53,   43,   48,   40,   47,   59,
-       62,   60,   40,   43,   53,   62,   44,   45,   62,   63,
-       75,   64,   47,   62,   70,   74,   71,   47,   75,   64,
-       38,   72,   38,   38,   41,   71,   41,   41,   46,   46,
-       71,   73,   72,   60,   69,   67,   68,   67,   66,   65,
-       75,   38,   36,   61,   58,   56,   55,   54,   53,   52,
-
-       51,   50,   75,   49,   37,   37,   43,   42,   37,   36,
-       75,   32,   32,    9,   75,   75,   75,   75,   75,   75,
+       22,   31,   33,   34,   33,   34,   36,   36,   36,   36,
+       35,   39,   35,   44,   45,   57,   59,   39,   60,   47,
+       53,   53,   40,   48,   47,   36,   36,   43,   40,   43,
+       44,   45,   62,   70,   62,   71,   47,   62,   74,   62,
+       72,   47,   63,   75,   64,   75,   64,   38,   71,   38,
+       38,   41,   71,   41,   41,   46,   46,   73,   72,   60,
+       69,   67,   68,   67,   66,   65,   75,   38,   61,   58,
+
+       56,   55,   54,   53,   52,   51,   50,   75,   49,   37,
+       37,   43,   42,   37,   75,   32,   32,    9,   75,   75,
        75,   75,   75,   75,   75,   75,   75,   75,   75,   75,
        75,   75,   75,   75,   75,   75,   75,   75,   75,   75,
-       75,   75,   75,   75,   75,   75
+       75,   75,   75,   75,   75,   75,   75,   75,   75,   75
     } ;
 
-static yyconst flex_int16_t yy_chk[147] =
+static yyconst flex_int16_t yy_chk[151] =
     {   0,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    5,    5,    6,    6,   14,   18,   18,   32,
-        5,   38,    6,   18,   32,   43,   79,   14,   18,   34,
-       43,   34,   38,   44,   34,   43,   45,   45,   44,   47,
-       47,   47,   45,   44,   62,   73,   62,   45,   64,   64,
-       76,   72,   76,   76,   77,   71,   77,   77,   78,   78,
-       70,   66,   63,   61,   59,   58,   55,   52,   51,   50,
-       46,   40,   36,   35,   33,   31,   30,   29,   28,   27,
-
-       26,   25,   24,   23,   21,   20,   17,   16,   13,   11,
-        9,    4,    3,   75,   75,   75,   75,   75,   75,   75,
+        1,    1,    5,    5,    6,    6,   11,   11,   12,   12,
+        5,   14,    6,   18,   18,   32,   34,   38,   34,   18,
+       32,   34,   14,   79,   18,   36,   36,   43,   38,   44,
+       45,   45,   43,   62,   44,   62,   45,   43,   73,   44,
+       72,   45,   47,   47,   47,   64,   64,   76,   71,   76,
+       76,   77,   70,   77,   77,   78,   78,   66,   63,   61,
+       59,   58,   55,   52,   51,   50,   46,   40,   35,   33,
+
+       31,   30,   29,   28,   27,   26,   25,   24,   23,   21,
+       20,   17,   16,   13,    9,    4,    3,   75,   75,   75,
        75,   75,   75,   75,   75,   75,   75,   75,   75,   75,
        75,   75,   75,   75,   75,   75,   75,   75,   75,   75,
-       75,   75,   75,   75,   75,   75
+       75,   75,   75,   75,   75,   75,   75,   75,   75,   75
     } ;
 
 /* The intent behind this definition is that it'll catch
@@ -1004,6 +1004,7 @@ YY_RULE_SETUP
 { return _gmx_sel_lexer_process_identifier(yylval, yytext, yyleng, state); }
        YY_BREAK
 case 18:
+/* rule 18 can match eol */
 YY_RULE_SETUP
 #line 160 "scanner.l"
 { _gmx_sel_lexer_add_token(" ", 1, state); }
@@ -1023,7 +1024,7 @@ YY_RULE_SETUP
 #line 163 "scanner.l"
 YY_FATAL_ERROR( "flex scanner jammed" );
        YY_BREAK
-#line 1027 "scanner.cpp"
+#line 1028 "scanner.cpp"
 
        case YY_END_OF_BUFFER:
                {
index bc8ebe8a3bd5e4763447526115a02fa8e1bcd608..df784001f5e0e990b72e4272baa83a1a41344d21 100644 (file)
@@ -157,6 +157,6 @@ not|"!"         { ADD_TOKEN; return NOT; }
 
 {IDENTIFIER}    { return _gmx_sel_lexer_process_identifier(yylval, yytext, yyleng, state); }
 
-[[:blank:]]+    { _gmx_sel_lexer_add_token(" ", 1, state); }
+[[:space:]]+    { _gmx_sel_lexer_add_token(" ", 1, state); }
 [_[:alnum:]]+   { yylval->str = gmx_strndup(yytext, yyleng); ADD_TOKEN; return STR; }
 .               { ADD_TOKEN; return yytext[0]; }
index e4c10b132a402120f45c34dcf20e87cba5608007..d299a2b56c2e110b334c0c66bf0069be7a0b111e 100644 (file)
@@ -416,6 +416,15 @@ TEST_F(SelectionCollectionTest, ParsesSelectionsFromFile)
     EXPECT_STREQ("resname RB RC", sel_[1].selectionText());
 }
 
+TEST_F(SelectionCollectionTest, HandlesAtypicalWhitespace)
+{
+    ASSERT_NO_THROW_GMX(sel_ = sc_.parseFromString("atomnr\n1\r\nto\t10;\vatomnr 3\f to 14\r"));
+    ASSERT_EQ(2U, sel_.size());
+    EXPECT_STREQ("atomnr 1 to 10", sel_[0].selectionText());
+    // TODO: Get rid of the trailing whitespace.
+    EXPECT_STREQ("atomnr 3 to 14 ", sel_[1].selectionText());
+}
+
 TEST_F(SelectionCollectionTest, HandlesInvalidRegularExpressions)
 {
     ASSERT_NO_FATAL_FAILURE(loadTopology("simple.gro"));