Bug 4447 - Simplify the '?:' grammar and semantics (5.7)
Simplify the '?:' grammar and semantics (5.7)
Product: jbatch
Classification: Unclassified
Component: source
All All
: P5 normal
: ---
Assigned To: cvignola
Depends on:
  Show dependency treegraph
Reported: 2012-12-20 19:46 UTC by kmukher
Modified: 2013-01-16 16:05 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description kmukher 2012-12-20 19:46:07 UTC
Is the '?:' intended to operate against an entire value expression or just an operator expression. As the current grammar is written the '?:' operator can be associated with more than one property or value expression so it is unclear what to replace with the default value. Also, any part of the string after the '?:' is considered part of the default value since there is no end delimiter so it limits the use of the '?:' operator to once per attribute.

I think we need to define the semantics of what the '?:' operates on and in what conditions the default value is used. I propose using the grammar below which will disambiguate the current grammar:

<attribute-value> ::= ' " ' <value-expression> ' " '
<value-expression> ::= "#{"<operator-expression>"}" [ "?:" <value-expression> ";"] | <string-literal> [ <value-expression> ]
<operator-expression> ::= <operator1> | <operator2> | <operator3> | <operator4>
<operator1> ::= "jobParameters" "[" <single-quoted-string-literal> "]"
<operator2> ::= "jobProperties" "[" <single-quoted-string-literal> "]"
<operator3> ::= "systemProperties" "[" <single-quoted-string-literal> "]"
<operator4> ::= "partitionPlan" "[" <single-quoted-string-literal> "]"
<single-quoted-string-literal> ::= " ' " <string-literal> " ' "
<string-literal> is a valid XML string value.

This grammar directly associates each '?:' with one property or '#'. It also includes an end delimiter of ';' to mark the end of the default value. This also simplifies the semantics of when to use the default value and exactly what gets replaced by having a one-to-one relationship. So we can say if a property resolves to 'null' then we evaluate the expression between '?:' and ';' and associated with that property and default to the value of that expression.

This allows us to support cases like the one below where we only want to use the default value for the filename portion and not the entire path. And the spec doesn't have to define what happens in cases where only part of a value expression resolves or if we consider an expression resolved if there are there are string literals, etc...:

Comment 1 cvignola 2013-01-14 16:24:41 UTC
The syntax prescribed in this bug has been adopted into the proposed final draft of the spec.