dialogos-project / dialogos

The DialogOS dialog system.
https://www.dialogos.app
GNU General Public License v3.0
21 stars 8 forks source link

More than one space in a string variable is reduced to zero spaces #189

Closed chrikoehn closed 5 years ago

chrikoehn commented 5 years ago

This code in a script node

string text;
text = "s          e";
print(text);
text = "Plenty of whitespace:'" + text + "'";
print(text);
print("s" + " " + " " + "e");

results in the following output (1&2 wrong, 3 correct):

se
Plenty of whitespace:'se'
s  e

This also affects speech synthesis nodes since using several spaces can result in something which cannot be spoken.

timobaumann commented 5 years ago

this is a bug in the lexer. however, I don't know anything about what's going on in there.

timobaumann commented 5 years ago

sequences of more than 1 NONNEWLINE_WHITE_SPACE_CHAR (tested space and tab) are reduced to nothing.

    @Test public void testStringParser() throws Exception {
        String testString = " s e ";
        Expression expr = Parser.parseExpression("\"" + testString + "\"", null);
        assertTrue(expr.evaluate() instanceof StringValue);
        assertEquals(expr.evaluate(), new StringValue(testString));
    }
timobaumann commented 5 years ago

line 362 in script.lex looks quite suspicious:

{NONNEWLINE_WHITE_SPACE_CHAR}+  { text(); }

although this is defined at the bottom and all the special stuff (e.g. string handling) is handled above.

timobaumann commented 5 years ago

see also: https://stackoverflow.com/questions/6736610/order-of-precedence-for-token-matching-in-flex

alexanderkoller commented 5 years ago

Great! Mention it in the CHANGELOG too?