question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

extend condition syntax

See original GitHub issue

Is your feature request related to a problem? Please describe.

Condition statements in official CSL take a single “match” attribute, which determines how the tests will be combined. The match attribute (all, any, none) applies to all tests within the statement: grouping of tests with separate match values is not possible. This makes combining different conditions unnecessarily complicated and often leads to highly nested and unreadable structures inside cs:if.

Describe the solution you’d like

CSL-M has introduced an optional extended syntax for condition statement:

The alternative syntax may be applied to cs:if or cs:else-if elements (the “parent node” in this description). The parent node must have no attributes, and a single cs:conditions node as its first child element. The cs:conditions node must have one or more cs:condition children. The cs:condition children each define a conditional statement with attributes specified in the CSL 1.0.1 schema and in this Supplement. The cs:condition statements are joined according to a mandatory “match” attribute on cs:conditions.

Example:

<choose>
  <if>
    <conditions match="any">
      <condition type="chapter"/>
      <condition variable="container-title collection-title" match="nand"/>
    </conditions>
    <text macro="some-chapter-mac"/>
  </if>
</choose>

CSL-M also adds match="nand" which tests true if at least one of the tests or condition statements to which it applies returns false.

I suggest we implement this solution, or something similar.

** Current capabilities

Apart from match="nand", most (all?) tests can be done with standard CSL, but they may be less readable. This

<choose>
  <if>
    <conditions match="any">
      <condition type="chapter"/>
      <condition variable="container-title collection-title" match="nand"/>
    </conditions>
    <text macro="some-chapter-mac"/>
  </if>
</choose>

needs a construction like this:

<choose>
  <if type="chapter"/>
    <text macro="some-chapter-mac"/>
  </if>
  <else-if variable="container-title collection-title" match="nand">
    <text macro="some-chapter-mac"/>
  <else-if>
</choose>

Now a real example (taken from chicago-note-bibliography.csl):

  <macro name="collection-title">
    <choose>
      <if match="none" type="article-journal">
        <choose>
          <if match="none" is-numeric="collection-number">
            <group delimiter=", ">
              <text variable="collection-title" text-case="title"/>
              <text variable="collection-number"/>
            </group>
          </if>
          <else>
            <group delimiter=" ">
              <text variable="collection-title" text-case="title"/>
              <text variable="collection-number"/>
            </group>
          </else>
        </choose>
      </if>
    </choose>
  </macro>

With the extended syntax that’s a bit simpler:

<macro name="collection-title">
<choose>
  <if>
    <conditions match="all">
      <condition match="none" type="article-journal"/>
      <condition match="none" is-numeric="collection-number">
    </conditions>
    <group delimiter=", ">
      <text variable="collection-title" text-case="title"/>
      <text variable="collection-number"/>
    </group>
  </if>
  <else>
    <group delimiter=" ">
      <text variable="collection-title" text-case="title"/>
      <text variable="collection-number"/>
    </group>
  </else>
<choose>
</macro>

Note that this extended syntax is not necessarily shorter. But it will be with a third condition, and I’d also say it is more readable and maintainability is better due to DRY (the example above needs to call the same macro twice).

Additional context see CSL-M supplement from where I have copied this request almost verbatim.

** Addendum: Possible extension of the extension: We could go even further and allow multiple cs:conditions. Think of: if ((x = 5 or y = 10) and ((a = 1 not b = 2) not (c = 3 or d = 4)))

<choose>
  <if match="all">
    <conditions match="any">
      <condition type="chapter"/>
      <condition variable="container-title collection-title" match="nand"/>
    </conditions>
    <conditions match="any">
      <condition has-day="issued"/>
      <condition date-range-variable"'issued" date-range-end='1900'/>
    </conditions>
    <text macro="some-other-mac"/>
  </if>
</choose>

@bdarcus @bwiernik @adam3smith Thoughts?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19 (19 by maintainers)

github_iconTop GitHub Comments

2reactions
fbennettcommented, Jun 26, 2020

Ah, fair point. That will work.

2reactions
bwiernikcommented, Jun 17, 2020

conditions would be a child element of if and else-if, not of choose

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extension (syntax)
Extension (syntax) ... 1. the entity or set of entities to which an expression refers. The extension of a proper name or definite...
Read more >
The simplest possible condition syntax should be used ...
Extend S3240: The simplest possible condition syntax should be used · […] · using the ternary operator ?: for assignment to a single...
Read more >
Python List extend()
Syntax of List extend(). The syntax of the extend() method is: list1.extend(iterable). Here, all the elements of iterable are added to the end...
Read more >
CAS LX 522 Syntax I
The Extension Condition: A syntactic derivation can only be continued by applying operations to the root projection of a tree. Feature checking.
Read more >
Indexing Pipeline Extension Condition Syntax Reference
Indexing pipeline extension conditions are essentially built with metadata, metadata values, and operators. Metadata syntax: %[metadataName].
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found