Make printed Screenplay round-trip for numerics and quoted strings - #41
Merged
Conversation
Introduce a shared StringLiteral helper holding the escape rules and the regular expression fragment for a literal body, and teach every parser that reads a quoted operand to resolve the escapes: descriptions, validation messages, screen labels and titles, seed group ids, specification errors, capture translations and separators, policy roles and claims, condition operands and tags. Only \", \\, \n, \r and \t are recognized. Any other backslash sequence is kept verbatim so regular expression operands such as matches "^\d+$" keep their meaning. The line scanners that track string state - SplitTopLevel and the comment stripper - skip the character after a backslash so an escaped quote no longer ends the string.
Printing a tree could produce text that does not compile back, breaking the inverse guarantee the printer documents. Non-double numeric literals fell through to a bare ToString(), so a decimal or float printed with the current culture's decimal separator - 5,5 on a comma-decimal machine, which then fails to parse. Route every IFormattable value through the invariant culture. String literals were interpolated between quotes with no escaping, so any value holding a " terminated the literal early. Every emission site now goes through StringLiteral.Quote: descriptions, validation messages, screen labels and titles, seed group ids, specification errors, capture translations and separators, policy roles and claims, and tags.
Cover the two defects the existing invoicing round trip cannot catch: it has no quote in any value and runs under the invariant culture. The numeric spec prints decimal, float, int and long literals with CurrentCulture set to nb-NO and asserts both the invariant output and a clean print, compile, reprint cycle. The quoted-text specs cover description, validation message, screen label and tag, and a regular expression operand proves an unknown escape survives verbatim.
Give StringLiteral a real production with the recognized escapes, note that any other backslash sequence is kept verbatim, and state on the printing page that strings are escaped and numbers are culture-invariant.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changed
\",\\,\n,\rand\t. Any other backslash sequence is kept verbatim, so regular expression operands such asmatches "^\d+$"keep their meaning. (ScreenplayPrinter emits non-round-trippable output for non-double numerics and quoted strings #25)Fixed
ScreenplayPrinterno longer emits culture-dependent numbers.decimal,float,intandlongliterals previously fell through to a culture-sensitiveToString()and printed5,5on a comma-decimal machine, producing text that failed to compile. (ScreenplayPrinter emits non-round-trippable output for non-double numerics and quoted strings #25)ScreenplayPrinternow escapes quotes and backslashes in every string it emits —description, validationmessage, screenlabelandtitle, seed group ids, specification errors, capture translations and separators, policy roles and claims, and tags. A value containing a"previously terminated the literal early and produced invalid output. (ScreenplayPrinter emits non-round-trippable output for non-double numerics and quoted strings #25)