Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 10, 2025

Summary

This PR implements optional right-to-left mode with arrow syntax support as requested in issue #63.

Features Added

  • Arrow Syntax Support: New support for directional arrow operators ( and ) in both single-line and multiline formats
  • Expression Equivalence: Implements the equivalence mentioned in the issue:
    • (2 ← 1) = (1 → 2) = (2 1)
  • Flexible Formatting: Links can now be formatted with arrow syntax using the new arrowMode parameter
  • Comprehensive Grammar: Updated PEG.js grammar with proper precedence to handle arrow operators

Technical Implementation

  1. Grammar Updates (grammar.pegjs):

    • Added arrowLink and multiLineArrowLink rules
    • Excluded arrow characters from referenceSymbol to prevent conflicts
    • Proper transformation of directional expressions
  2. Parser Enhancement:

    • Arrow expressions are parsed into standard link structures
    • 2 ← 1 transforms to { values: [1, 2] } (right points to left)
    • 1 → 2 transforms to { values: [1, 2] } (left points to right)
  3. Link Class Extensions:

    • Added arrowMode parameter to format() method
    • New arrow formatting for 2-element links: link.format(false, false, true)"1 → 2"
    • Backward compatible with existing formatting modes
  4. Test Coverage:

    • Comprehensive test suite covering all arrow syntax scenarios
    • Tests for parsing equivalence between different formats
    • Tests for arrow formatting mode
    • Tests for complex expressions with quoted references

Examples

import { Parser, Link } from '@linksplatform/protocols-lino';

const parser = new Parser();

// All of these produce the same result: { values: [Link(1), Link(2)] }
parser.parse('1 → 2');       // Left arrow
parser.parse('2 ← 1');       // Right arrow  
parser.parse('(1 → 2)');     // Multiline left arrow
parser.parse('(2 1)');       // Standard format

// Arrow formatting
const link = new Link(null, [new Link('1'), new Link('2')]);
link.format(false, false, true);  // Returns: "1 → 2"

Test Results

All tests pass including:

  • 8 new arrow syntax tests
  • All existing 80+ tests continue to pass
  • No breaking changes to existing functionality

Fixes #63

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #63
@konard konard self-assigned this Sep 10, 2025
konard and others added 2 commits September 10, 2025 11:06
Add support for arrow syntax (← and →) in Lino protocol:
- Updated grammar to recognize arrow operators in both single and multiline formats
- Modified parser to transform arrow expressions into standard link structures
- Enhanced Link class with arrow formatting mode capability
- Added comprehensive test suite for arrow syntax functionality

Fixes #63

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@konard konard changed the title [WIP] Optional right to left mode Implement optional right-to-left mode with arrow syntax Sep 10, 2025
@konard konard marked this pull request as ready for review September 10, 2025 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optional right to left mode

2 participants