Skip to content

Commit 1500f00

Browse files
petertsengkytrinyx
andauthored
sgf-parsing: Replace incorrect info with correct info (#2114)
* sgf-parsing: improve description flow There is a bit of opinion on what makes better flow. The main opinion of this commit: High-level description of the goal should come earlier; that way the high-level goal can be kept in mind when reading the details below. So two pieces of text are moved: First, the overall goal of the exercise. Second, that all property values are Text. * sgf-parsing: Replace incorrect info with correct info 285d2e6 added outright incorrect info ("Incorrect" means it violates the specification found at https://www.red-bean.com/sgf/sgf4.html#text). It is replaced with correct info. As follows: * Newlines are treated differently based on whether they come after a \ * SGF does **not** have escape sequences for whitespace characters, so it doesn't make sense to talk about escaped forms for them. * There is no need or expectation for parentheses or semicolons to be escaped, so remove the sentence about that. All statements in this commit are already being tested by tests added in 3c33c24, so no additional tests need be added. Co-authored-by: Katrina Owen <[email protected]>
1 parent fb1da70 commit 1500f00

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

exercises/sgf-parsing/description.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ tree of nodes where each node is a property list. The property list
99
contains key value pairs, each key can only occur once but may have
1010
multiple values.
1111

12+
The exercise will have you parse an SGF string and return a tree structure of properties.
13+
1214
An SGF file may look like this:
1315

1416
```text
@@ -52,17 +54,16 @@ A key can have multiple values associated with it. For example:
5254

5355
Here `AB` (add black) is used to add three black stones to the board.
5456

55-
According the the SGF specification `\` is the escape character. When `\` is
56-
encountered during parsing, it indicates that the following character should be
57-
printed as is. The exception to this is whitespace, with newline, carriage
58-
return and tab encoded as `"\n"`, `"\r"` and `"\t"` respectively. When parsing
59-
you can expect some characters to _always_ be escaped, including parentheses,
60-
square brackets, semicolons and colons.
57+
All property values will be the [SGF Text type][sgf-text].
58+
You don't need to implement any other value type.
59+
Although you can read the [full documentation of the Text type][sgf-text], a summary of the important points is below:
6160

62-
When parsing SGF files whitespace gets special handling, with the exception of
63-
newlines any whitespace character encountered is replaced with a single space
64-
character irrespective of if the original character is found in its escaped
65-
from or its unescaped from.
61+
- Newlines are removed if they come immediately after a `\`, otherwise they remain as newlines.
62+
- All whitespace characters other than newline are converted to spaces.
63+
- `\` is the escape character.
64+
Any non-whitespace character after `\` is inserted as-is.
65+
Any whitespace character after `\` follows the above rules.
66+
Note that SGF does **not** have escape sequences for whitespace characters such as `\t` or `\n`.
6667

6768
Be careful not to get confused between:
6869

@@ -78,10 +79,5 @@ that. Furthermore you may assume that all newlines are unix style (`\n`,
7879
no `\r` or `\r\n` will be in the tests) and that no optional whitespace
7980
between properties, nodes, etc will be in the tests.
8081

81-
The exercise will have you parse an SGF string and return a tree
82-
structure of properties. You do not need to encode knowledge about the
83-
data types of properties, just use the rules for the
84-
[text][sgf-text] type everywhere.
85-
8682
[sgf]: https://en.wikipedia.org/wiki/Smart_Game_Format
8783
[sgf-text]: http://www.red-bean.com/sgf/sgf4.html#text

0 commit comments

Comments
 (0)