tksk / jing-trang

Automatically exported from code.google.com/p/jing-trang
0 stars 0 forks source link

RNC trailing comments associated with next item #173

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Steps to reproduce.
1. Create a RNC test file that has comments on the same line as an item, 
trailing it. (see below for example)
2. Convert the test file to RNG

EXPECTED: XML comments in RNG are associated the element/attribute
ACTUAL: XML comments appear with the next element/attribute

Trang version 20091111

Example RNC:
grammar {
  start = element test {             # Root is a <test> element
    attribute version  {"1.0"},      # This schema describes test version 1.0
    attribute name     {text}?,      # Friendly name to show (default:filename)
    attribute desc     {text}?,      # Optional long description
    AlphaElement?,                   # <alpha> is optional,
    BetaElement                      # but <beta> is required
  }

  AlphaElement = element alpha {
    attribute a1       {text}?,      # The a1 attribute description
    attribute a2       {text}?       # The a2 attribute description
  }

  BetaElement = element beta {       # Describes the final phase of bonking
    attribute b1       {text},       # The b1 attribute description (required)
    attribute b2       {text}?       # The b2 attribute description
  }
}

Resulting RNG:
<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
  <start>
    <element name="test">
      <group>
        <!-- Root is a <test> element -->
        <attribute name="version">
          <value>1.0</value>
        </attribute>
        <optional>
          <!-- This schema describes test version 1.0 -->
          <attribute name="name"/>
        </optional>
        <optional>
          <!-- Friendly name to show (default:filename) -->
          <attribute name="desc"/>
        </optional>
        <optional>
          <!-- Optional long description -->
          <ref name="AlphaElement"/>
        </optional>
        <!-- <alpha> is optional, -->
        <ref name="BetaElement"/>
      </group>
      <!-- but <beta> is required -->
    </element>
  </start>
  <define name="AlphaElement">
    <element name="alpha">
      <group>
        <optional>
          <attribute name="a1"/>
        </optional>
        <optional>
          <!-- The a1 attribute description -->
          <attribute name="a2"/>
        </optional>
      </group>
      <!-- The a2 attribute description -->
    </element>
  </define>
  <define name="BetaElement">
    <element name="beta">
      <group>
        <!-- Describes the final phase of bonking -->
        <attribute name="b1"/>
        <optional>
          <!-- The b1 attribute description (required) -->
          <attribute name="b2"/>
        </optional>
      </group>
      <!-- The b2 attribute description -->
    </element>
  </define>
</grammar>

A nice heuristic would apply a comment to the following line if the comment is 
preceded only by ^\s*, but apply to the current line (previous content) if the 
comment is on the same line as that content.

Original issue reported on code.google.com by Phrog...@gmail.com on 13 Aug 2013 at 4:03

GoogleCodeExporter commented 9 years ago
The spec requires that ## comments apply to the following item. I don't think 
it would be a good idea to make normal comments behave differently.

Original comment by j...@jclark.com on 14 Aug 2013 at 1:31