The Pathfinder-Scrolls of Brannoch Vale
Every party that sets out from Bitwick into Brannoch Vale files a manifest first. A manifest is one line of text holding a list of fields: names, supplies, routes, oaths. The Cartographers' Guild writes these lines in Quillhand. The Wayfinders' Lodge at the trailhead reads only Knotscript. The Guild pays a standing bounty to any scribe who can carry a manifest from either script into the other. A line that is not properly written must not be copied at all.
A manifest is a list of one or more fields. Each field is a string, and it may be empty.
### Quillhand - Fields are separated by , characters that are not inside a quoted field. The empty line is a single empty field. - A field that begins with " is quoted. Any other field is bare. - A bare field is zero or more characters, none of which is , or ". Its value is exactly those characters. - A quoted field is read left to right after its opening ": - "" stands for one ". - A " not immediately followed by another " closes the field. - Every other character, including ,, stands for itself. - The closing " must be followed immediately by , or by the end of the line. - A line is malformed if any of these hold: - a bare field contains a "; - a quoted field is never closed; - a closing " is followed by anything other than , or the end of the line. - Writing Quillhand: quote a field if and only if its value contains , or ". Inside the quotes, write each " as "". Write every other field bare.
### Knotscript - Fields are separated by | characters that are not escaped. - A backslash \ escapes the single character after it, which must be \, | or -. So \\, \| and \- stand for \, | and -. - A backslash followed by any other character, or a backslash at the end of the line, is malformed. - A field written as exactly - (unescaped) has the empty value. Any other - is an ordinary character. - A field written with no characters at all is malformed. So the empty line, a||b, and a line that begins or ends with an unescaped | are all malformed. - Writing Knotscript: - write an empty field as -; - write a field whose value is exactly - as \-; - in every other field, write each \ as \\ and each | as \|, and leave all other characters (including hyphens) as they are.
In both scripts, every character not named above is ordinary and is carried through unchanged. That includes spaces, and nothing is trimmed.
### The commission Write transcribe(line, target). line is a string, and target is either "knot" or "quill". - If target is "knot", line is Quillhand. Return the same list of field values written in Knotscript. - If target is "quill", line is Knotscript. Return the same list of field values written in Quillhand. - If line is malformed in its source script, return null (None in Python).
The return value is a string, or null/None.
examples
- case 1
line of Rope,"Lantern, hooded",Salt with target "knot"Rope|Lantern, hooded|Salt - case 2
line of -|\-|a-b with target "quill" (an empty field, a lone hyphen, then a-b),-,a-b - case 3
line of a\\|b with target "quill" (the doubled backslash is one escaped backslash, so the bar separates)a\,b (two fields: "a\" and "b") - case 4
the empty line, once with target "knot" and once with target "quill""-" for knot (one empty field); null for quill (an empty Knotscript field is malformed)
- reward
- 540 XP
- signature
transcribe
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- quill_to_knot_basic_quoted_comma
- quill_to_knot_doubled_quotes
- quill_empty_line_is_one_empty_field
- quill_lone_comma_two_empty_fields
- quill_hyphen_cases
- quill_bar_and_backslash_get_escaped
- quill_quote_in_bare_field_malformed
- quill_unclosed_quote_malformed
- quill_text_after_closing_quote_malformed
- quill_trailing_escaped_quote_then_close
- quill_pair_swallows_would_be_close
- quill_two_quoted_empties
- knot_to_quill_basic
- knot_to_quill_quote_needs_quoting
- knot_single_dash_is_empty_line
- knot_empty_vs_escaped_hyphen
- knot_double_backslash_then_separator
- knot_escaped_bar_stays_in_field
- knot_empty_line_malformed
- knot_empty_written_field_malformed
- knot_trailing_backslash_malformed
- knot_bad_escape_malformed
- knot_escaped_hyphen_inside_field
- knot_comma_and_quote_fields