Skip to content

Add automatic linking from grammar term references to their definitions #79

@lefticus

Description

@lefticus

Feature Request

Automatically link \\grammarterm{term} references to their \\nontermdef{term} definitions, similar to how section cross-references work.

Example

Current behavior:

  • \\grammarterm{statement}*statement* (just italicized text)

Proposed behavior:

  • \\grammarterm{statement}[*statement*][term.statement] with link to the section containing \\nontermdef{statement}

Benefits

  1. Easier navigation through grammar productions - readers can quickly jump to the definition of any grammar term
  2. Consistent behavior with existing section cross-reference system
  3. Better understanding of grammar structure and relationships

Implementation Considerations

Critical: Namespace Prefix

MUST use term. prefix, NOT gram.

The gram. namespace is already used by existing grammar summary sections:

  • gram.general - Grammar Summary General section
  • gram.key - Keywords section
  • Historically: gram.stmt, gram.expr, gram.dcl, etc.

Using gram. would cause namespace collision and break existing cross-file links.

Technical Requirements

  1. Handle malformed patterns gracefully: Must handle \\grammarterm{}{text} (empty first arg) pattern in n3337/n4140 sources (see \\grammarterm{}{text} with empty first argument causes malformed output #78)
  2. Use proper Pandoc AST: Use pandoc.Link() elements, not RawInline markdown strings (which don't get re-parsed)
  3. Build grammar term index: Similar to LabelIndexer, scan for \\nontermdef{}, \\fmtnontermdef{}, \\renontermdef{} and map terms → sections
  4. Generate link reference table: Add entries like [term.statement]: basic.md#stmt.pre at document end
  5. Test across all versions: Must work correctly for n3337, n4140, n4659, n4861, n4950, and trunk

Example Index Mapping

translation-unit  → basic.link
statement         → stmt.pre
expression        → expr.comma
class-name        → class.pre

Related Issues

Cross-reference linking issues:

Priority

ENHANCEMENT - This is a feature request to improve navigation, not a bug fix.

Notes from Failed Implementation Attempt

A previous implementation attempt was reverted due to:

  1. Using gram. prefix (namespace collision)
  2. Using RawInline markdown (doesn't work with Pandoc's processing model)
  3. Not handling malformed \\grammarterm{}{} patterns gracefully
  4. Insufficient testing across standard versions

Any future implementation should address these issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions