Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

71%
+3 −0
Q&A Syntax summaries use brackets for optional elements; how do I represent literal brackets in a way readers will understand?

In our documentation of SQL functions and statements, we include a BNF-style syntax summary. As is conventional, we indicate optional elements in square brackets, like this: CREATE [IF NOT EXISTS]...

4 answers  ·  posted 4y ago by Monica Cellio‭  ·  last activity 4y ago by Derek Elkins‭

#2: Post edited by user avatar Monica Cellio‭ · 2020-10-30T13:10:37Z (about 4 years ago)
switched gears on the first example halfway through and left bogus SQL; I realize it's just an example but still...
  • In our documentation of SQL functions and statements, we include a BNF-style syntax summary. As is conventional, we indicate optional elements in square brackets, like this:
  • CREATE [OR REPLACE] TABLE [schema.]table-name (column-definition[,...]) ...
  • There's more to it, but that's the idea. To unpack this a bit: "OR REPLACE" is optional, including a schema is optional, and you must include at least one column definition and may include more. (A column definition is further expanded as a name and a data type.)
  • This has worked fine for us for years... until now, when I need to show syntax summaries that have *literal* square brackets. An array declaration must include a data type and may include a maximum number of elements, like this:
  • ARRAY[INT,10]
  • Or just:
  • ARRAY[INT]
  • Is there a way, that won't confuse readers, to indicate that the second item in the first example, the element count, is optional?
  • Even though we had the square-bracket problem as soon as we had to document arrays, I think readers understood that `ARRAY[data-type]` wasn't saying you could omit the data type; people understand that arrays use square brackets. But `ARRAY[data-type[, count]]` feels confusing, because I'm using the same symbols in two different ways in the same statement.
  • Am I going to need to escape the literal square brackets somehow, to disambiguate? Or is there a better way to approach this problem? Currently I'm punting on a single syntax summary in favor of separate descriptions of the three different ways to declare arrays (there's another dimension of optionality that I have not shown here). That might be the best approach, but I'd like to know if there are other options.
  • In our documentation of SQL functions and statements, we include a BNF-style syntax summary. As is conventional, we indicate optional elements in square brackets, like this:
  • CREATE [IF NOT EXISTS] TABLE [schema.]table-name (column-definition[,...]) ...
  • There's more to it, but that's the idea. To unpack this a bit: "IF NOT EXISTS" is optional, including a schema is optional, and you must include at least one column definition and may include more. (A column definition is further expanded as a name and a data type.)
  • This has worked fine for us for years... until now, when I need to show syntax summaries that have *literal* square brackets. An array declaration must include a data type and may include a maximum number of elements, like this:
  • ARRAY[INT,10]
  • Or just:
  • ARRAY[INT]
  • Is there a way, that won't confuse readers, to indicate that the second item in the first example, the element count, is optional?
  • Even though we had the square-bracket problem as soon as we had to document arrays, I think readers understood that `ARRAY[data-type]` wasn't saying you could omit the data type; people understand that arrays use square brackets. But `ARRAY[data-type[, count]]` feels confusing, because I'm using the same symbols in two different ways in the same statement.
  • Am I going to need to escape the literal square brackets somehow, to disambiguate? Or is there a better way to approach this problem? Currently I'm punting on a single syntax summary in favor of separate descriptions of the three different ways to declare arrays (there's another dimension of optionality that I have not shown here). That might be the best approach, but I'd like to know if there are other options.
#1: Initial revision by user avatar Monica Cellio‭ · 2020-10-30T01:35:52Z (about 4 years ago)
Syntax summaries use brackets for optional elements; how do I represent literal brackets in a way readers will understand?
In our documentation of SQL functions and statements, we include a BNF-style syntax summary.  As is conventional, we indicate optional elements in square brackets, like this:

    CREATE [OR REPLACE] TABLE [schema.]table-name (column-definition[,...]) ...

There's more to it, but that's the idea.  To unpack this a bit: "OR REPLACE" is optional, including a schema is optional, and you must include at least one column definition and may include more.  (A column definition is further expanded as a name and a data type.)

This has worked fine for us for years... until now, when I need to show syntax summaries that have *literal* square brackets.  An array declaration must include a data type and may include a maximum number of elements, like this:

    ARRAY[INT,10]

Or just:

    ARRAY[INT]

Is there a way, that won't confuse readers, to indicate that the second item in the first example, the element count, is optional?  

Even though we had the square-bracket problem as soon as we had to document arrays, I think readers understood that `ARRAY[data-type]` wasn't saying you could omit the data type; people understand that arrays use square brackets.  But `ARRAY[data-type[, count]]` feels confusing, because I'm using the same symbols in two different ways in the same statement.

Am I going to need to escape the literal square brackets somehow, to disambiguate?  Or is there a better way to approach this problem?  Currently I'm punting on a single syntax summary in favor of separate descriptions of the three different ways to declare arrays (there's another dimension of optionality that I have not shown here).  That might be the best approach, but I'd like to know if there are other options.