| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Gram.Transform
Description
Transformation of CST (Concrete Syntax Tree) to Pattern Subject.
This module provides functions to transform parsed gram notation (CST) into the core Pattern Subject representation. The default behavior preserves anonymous subjects as 'Symbol ""' to enable round-trip compatibility, while optional functions are available for explicit ID assignment when needed.
Design Decision: Anonymity Preservation by Default
The default transformGram function preserves anonymous subjects
(represented as 'Symbol ""') rather than assigning generated IDs.
This enables true round-trip compatibility: parsing and serializing
anonymous patterns preserves their anonymous nature.
When to Use ID Assignment
Use transformGramWithIds or assignIdentities when:
- You need unique identifiers for graph algorithms
- You need to distinguish between anonymous instances
- You're working with external systems that require explicit IDs
Use transformGram (default) when:
- You need round-trip compatibility
- You want to preserve the original gram notation structure
- Anonymous subjects should remain anonymous
Examples
>>>transformGram (parseGram "()")Pattern with Subject {identity = Symbol "", ...}
>>>transformGramWithIds (parseGram "() ()")Pattern with two subjects having identities Symbol "#1" and Symbol "#2"
Synopsis
Documentation
transformGram :: Gram -> Pattern Subject Source #
Transform a CST Gram into a Core Pattern Subject.
This function preserves anonymous subjects as 'Symbol ""' to enable
round-trip compatibility. Anonymous subjects in the gram notation
(e.g., (), ()-[]->()) will be represented with empty identity.
If you need unique IDs assigned to anonymous subjects, use
transformGramWithIds instead.
transformGramWithIds :: Gram -> Pattern Subject Source #
Transform a CST Gram into a Core Pattern Subject with ID assignment.
This function is equivalent to applying assignIdentities to the result
of transformGram. It assigns unique sequential IDs (e.g., #1, #2)
to all anonymous subjects in the parsed pattern.
Use this function when you need unique identifiers for anonymous subjects, such as for graph algorithms or when distinguishing between anonymous instances is important.
For round-trip compatibility, use transformGram instead, which preserves
anonymity.
assignIdentities :: Pattern Subject -> Pattern Subject Source #
Assign unique sequential IDs to anonymous subjects in a Pattern.
This function recursively traverses a pattern and assigns IDs of the form
#N to all subjects with empty identity ('Symbol ""'). The counter starts
from the maximum existing #N-style ID found in the pattern plus one,
ensuring no collisions.
Named subjects (non-empty identity) are left unchanged.