| Copyright | (c) gram-data 2024 |
|---|---|
| License | BSD3 |
| Maintainer | gram-data |
| Stability | experimental |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Gram.Parse
Description
This module provides parsers for gram notation, converting text into Pattern and Subject data structures.
Anonymous Subject Handling
The default fromGram function preserves anonymous subjects as 'Symbol ""'
to enable round-trip compatibility. Anonymous subjects in gram notation
(e.g., (), ()-[]->()) will be represented with empty identity.
If you need unique IDs assigned to anonymous subjects, use fromGramWithIds
instead, which assigns sequential IDs (e.g., #1, #2) to all anonymous
subjects.
String Value Syntax
The parser supports multiple string formats:
Double-quoted strings
Standard strings with escape sequences:
{ name: "Alice" }
Single-quoted strings
Literal strings without escape processing:
{ pattern: '[a-z]+' }
Codefence strings (multiline)
Triple-backtick delimited strings for multiline content:
{ content: ```
This content spans
multiple lines.
``` }
Tagged codefence strings
Codefence with a tag indicating the content type:
{ doc: ```md
# Markdown Title
Some **bold** text.
``` }
Tagged codefences are parsed as VTaggedString values with the tag
and content stored separately.
Synopsis
- fromGram :: String -> Either ParseError (Pattern Subject)
- fromGramWithIds :: String -> Either ParseError (Pattern Subject)
- parseGram :: Parser Gram
- data ParseError = ParseError String
Documentation
fromGram :: String -> Either ParseError (Pattern Subject) Source #
Parse gram notation string into a 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
fromGramWithIds instead.
fromGramWithIds :: String -> Either ParseError (Pattern Subject) Source #
Parse gram notation string into a Pattern Subject with ID assignment.
This function is equivalent to applying assignIdentities to the
result of fromGram. 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 fromGram instead, which preserves
anonymity.
data ParseError Source #
Parse error type for gram notation parsing.
Constructors
| ParseError String |
Instances
| Show ParseError Source # | |
Defined in Gram.Parse Methods showsPrec :: Int -> ParseError -> ShowS # show :: ParseError -> String # showList :: [ParseError] -> ShowS # | |
| Eq ParseError Source # | |
Defined in Gram.Parse | |