Skip to content

Print a string value as text that parses back as the same string - #91

Draft
jtnelson wants to merge 1 commit into
developfrom
feature/GH-79-quote-values-that-do-not-read-back
Draft

jtnelson wants to merge 1 commit into
developfrom
feature/GH-79-quote-values-that-do-not-read-back

Conversation

@jtnelson

Copy link
Copy Markdown
Member

Summary

A ValueSymbol prints its value as CCL. Concourse's Criteria.ccl() is built from that text, and RestQL's canonical query string is the CCL that ccl prints for a Criteria (cinchapi/restql#51). A string value printed without quotes unless it held a space or =. So a string that CCL reads as syntax, such as a), [a], a;b, a tab, a line break, $id$, and or where, printed as text that did not parse or that parsed as another value. A string within quotes, such as 'a', printed as is and parsed back as a. A quoted string with a backslash before a double quote or at its end parsed back with a backslash lost or added.

The CCL grammar decides whether a string can print unquoted: the lexer must read the text as one unquoted value token that spans it. Asking the lexer keeps the rule in step with the grammar, including every reserved word and operator, without a list of characters or words to maintain. Within quotes, the lexer reads a backslash as an escape for the next character, and the parser reads \" as ". So a string that holds both quote characters prints within double quotes, with \" for each double quote inside.

Part of #79. This change covers the value side of #79. The key side remains open. A KeySymbol whose key is a word that starts or joins a condition still prints as text that does not parse. Such words are where, and, or, the operator words such as eq and like, at, on, during, asc and desc. The grammar has no quoted form for a key, and #85 made only command, preposition and page words parse as keys.

Behavior

  • A string prints unquoted when the lexer reads it as one unquoted value token that spans the text, the text is not within quotes, and the parser keeps it as is. A string that printed unquoted and parsed back keeps its text, such as jeff, a.b, a* or jeff@cinchapi.com.
  • A string that starts with $ or \$ and that the lexer reads as one unquoted value prints unquoted, as a local reference or its escape. Compiler#parse(String, Multimap) resolves that text the way Compiler#parse(List, Multimap) resolves the symbol.
  • Any other string prints within quotes. So does a string that reads as a number or that backticks wrap. The quotes are single quotes when single quotes can hold the string and either it holds a double quote and no single quote, or double quotes cannot hold it. Otherwise they are double quotes.
  • A quoted string prints with the backslashes that keep it intact. Each double quote within double quotes, and each double quote that follows a backslash, gets a backslash before it. A double-quoted string that ends with a backslash gets one more at its end. For example, it's "x" prints as "it's \"x\"", and C:\Program Files\ prints as "C:\Program Files\\".
  • CCL cannot express the empty string, which prints as empty text that does not parse.
  • CCL cannot express a string that needs quotes when neither quote character can hold it. Double quotes cannot hold a string in which a double quote follows an odd number of backslashes, or that ends with an even, nonzero number of them. Single quotes cannot hold a string that holds a single quote or that ends with an odd number of backslashes. Such a string, such as it's \\, prints within double quotes, and its text does not parse back as the string.
  • The value transform can read unquoted text as a type other than a string. For example, Concourse's transform reads true as a boolean, @1 as a link and |now| as a timestamp. Such a string prints unquoted and reads back as that type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant