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

@jtnelson jtnelson commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Background

A ValueSymbol prints its value as CCL, and a caller that prints a condition from its symbols relies on that text parsing back as the same condition. Concourse's Criteria.ccl() prints its CCL this way, and RestQL's canonical query string is the CCL that ccl prints for a Criteria (cinchapi/restql#51).

Before this change, a string value printed without quotes unless it read as a number, backticks wrapped it, or it contained a space or =. So a string that contains a character CCL reads as syntax, such as a), [a], a;b or one with a tab, printed as text that did not parse or that parsed as another value. The same happened to a string that CCL reads as a token of its own, such as $id$, and or where. A string that was already within quotes, such as 'a', printed as is and parsed back without its quotes. And a string that printed within quotes did not parse back as the same string when it had a backslash before a double quote or at its end.

This change fixes the value side of #79, which stays open for keys. The grammar has no quoted form for a key, and #85 made only command, preposition and page words parse as keys, so a key spelled like where or and still prints as text that does not parse.

Change

A ValueSymbol prints a string unquoted only when CCL reads the unquoted text back as the same string. Otherwise it prints the string within quotes, with the backslashes that keep it intact. A string whose text already parsed back keeps that text. For example, here is the CCL that a Criteria with three string values prints before and after this change.

Criteria criteria = Criteria.where()
        .key("name").operator(Operator.EQUALS).value("a;b")
        .or().key("name").operator(Operator.EQUALS).value("where")
        .or().key("name").operator(Operator.EQUALS).value("jeff")
        .build();
criteria.ccl();
// Before: name = a;b OR name = where OR name = jeff
// After:  name = "a;b" OR name = "where" OR name = jeff

To decide whether a string can print unquoted, ValueSymbol asks the CCL lexer whether it reads the whole text as one unquoted value. So the rule follows the grammar, including every reserved word and operator, and there is no list of characters or words to keep in step with it.

Semantics

  • A string prints unquoted when the lexer reads the whole text as one unquoted value and that value is the same string, such as jeff, a.b, a* or jeff@cinchapi.com.
  • A string that starts with $ or \$, such as $target, prints unquoted whenever the lexer reads it as one unquoted value. The parser then reads it as a reference to local data or as the escape for one, so Compiler#parse(String, Multimap) resolves the text the way Compiler#parse(List, Multimap) resolves the symbol.
  • Every other string prints within quotes, such as a;b, where, $id$ or 'a'. A string that reads as a number, such as 1, or that backticks wrap also prints within quotes, so that it reads back as a string rather than as a number or a Tag.
  • A quoted string prints with the backslashes that keep it intact. For example, it's "x" prints as "it's \"x\"", and C:\Program Files\ prints as "C:\Program Files\\".
  • Even with those backslashes, 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 contains a single quote or that ends with an odd number of backslashes.
  • A string that needs quotes prints within single quotes when single quotes can hold it and either it contains a double quote and no single quote, or double quotes cannot hold it. Otherwise it prints within double quotes.
  • CCL cannot express the empty string, which prints as empty text that does not parse.
  • CCL also cannot express a string that needs quotes when neither quote character can hold it, such as it's \\. Such a string prints within double quotes, and its text does not parse back as the string.
  • The Compiler's value parser, which turns the text of a value into an object, can read unquoted text as a type other than a string. For example, Concourse's value parser reads true as a boolean, @1 as a link and |now| as a timestamp, so a string with that text 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