Dynamo: Code Block with string value not upgrading properly to 1.3.0

Created on 12 May 2017  ยท  7Comments  ยท  Source: DynamoDS/Dynamo

Dynamo version

1.3.0.875

Operating system

Windows 7

What did you do?

I opened a definition that worked fine in 1.2.1 and noticed errors in the code blocks.

What did you expect to see?

The code block string should not have resulted in this error (see below). Also there were code blocks that contained strings of text and were frozen and worked fine in 1.2.1 but result in the same red node and error in 1.3.0.

What did you see instead?

Code block disconnected (no longer has an output port) and reports "Error: EOF expected". In the meantime I'll have to change these nodes with a String node instead. (The string was a lengthy Regular Expression: "[a-zA-Z]{1,5}?[\d]{1,4}?[^ '\t\n\r\f\v\w]+[\w]{1,5}?[^ '\t\n\r\f\v\w][\w]{0,4}[^ '\t\n\r\f\v\w][\w]{0,4}|[a-zA-Z]{1,5}[^ '\t\n\r\f\v\w][\d]{1,5}[a-zA-Z]";)

codeblockstring

1.x bug needs more info priority

All 7 comments

Here's another before (1.2.1)

codeblock-1 2 1

and after (1.3.0):

codeblock-1 3 0

Looks like it's due to the \ characters. What has changed with respect to this?

cc: @kronz @samuelcwl @ke-yu Looks like a regression guys. Can we get this fixed?

This is expected behaviour and is not a bug. There are only certain characters that can be escaped as shown here for C# (and DesignScript tries to be close to C#): https://blogs.msdn.microsoft.com/csharpfaq/2004/03/12/what-character-escape-sequences-are-available/
You'll notice that the same strings you've used in your code blocks above do not work in C#.
Namely the following characters can be escaped:

\' โ€“ single quote, needed for character literals
\" โ€“ double quote, needed for string literals
\\ โ€“ backslash
\0 โ€“ Unicode character 0
\a โ€“ Alert (character 7)
\b โ€“ Backspace (character 8)
\f โ€“ Form feed (character 12)
\n โ€“ New line (character 10)
\r โ€“ Carriage return (character 13)
\t โ€“ Horizontal tab (character 9)
\v โ€“ Vertical quote (character 11)
\uxxxx โ€“ Unicode escape sequence for character with hex value xxxx

You can see them hardcoded in our grammar here:
https://github.com/DynamoDS/Dynamo/blob/0622384b0bbffd5a2de617b8d4a8ad3aaeb72396/src/Engine/ProtoCore/Parser/atg/Start.atg#L665

In the script that you're using above, you're trying to escape characters like w that are not "escapable" and you'll therefore see the syntax error unless you use \\w. The fact that it was working in 1.2 was really a bug as it was inconsistent with escape character rules.

FYI: @Racel

Thanks for the explanation. Unfortunately this complicates matters for non-coders unnecessarily IMO. If one is using certain syntax for a regular expression, it becomes unnecessarily complicated to have to know what characters need to be escaped with an additional \ and which don't since they don't work consistently across the board. This makes the tool very frustrating to deal with.

@dbaldacchino that is why we have the String node in addition to code block nodes. Strictly speaking code block strings allow for certain characters to be escaped so as to codify the strings that they wish to create including things like whitespaces, etc. DesignScript doesn't have anything for string literals in its syntax, which is what you're looking for but that is exactly what the String node is for. See the difference in the graph below. The code block string generates a string preview with tabs and newlines in it but the string node output preserves the input string:
image

Understood, I appreciate your explanation. String node from now on when this use case arises :) Have a great weekend!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

erfajo picture erfajo  ยท  3Comments

JarodSchultz picture JarodSchultz  ยท  5Comments

LuisaCPBR picture LuisaCPBR  ยท  4Comments

ThomasMahon picture ThomasMahon  ยท  9Comments

askgrkumar picture askgrkumar  ยท  4Comments