gram
Safe HaskellSafe-Inferred
LanguageHaskell2010

Gram.Serialize

Description

Serialization of Pattern Subject to gram notation.

This module provides functions to convert Pattern Subject data structures into gram notation text format. The serialization handles all aspects of gram notation including:

Synopsis

Documentation

toGram :: Pattern Subject -> String Source #

Serialize a Pattern Subject to gram notation.

Converts a Pattern Subject data structure into its gram notation string representation. The output follows the gram notation specification: - Patterns with elements use subject syntax: `[attributes | elements]` - Patterns without elements use node syntax: (attributes)

Examples

Simple node (no elements):

>>> import Pattern.Core (Pattern(..))
>>> import Subject.Core (Subject(..), Symbol(..))
>>> import Data.Set (Set)
>>> import qualified Data.Set as Set
>>> let s = Subject (Symbol "n") (Set.fromList ["Person"]) empty
>>> let p = Pattern { value = s, elements = [] }
>>> toGram p
"(n:Person)"

Node with properties (no elements):

>>> import Data.Map (fromList)
>>> import Subject.Value (VString)
>>> let s = Subject (Symbol "n") (Set.fromList ["Person"]) (fromList [("name", VString "Alice")])
>>> let p = Pattern { value = s, elements = [] }
>>> toGram p
"(n:Person {name:\"Alice\"})"

Subject with nested elements:

>>> let inner1 = Pattern (Subject (Symbol "a") Set.empty empty) []
>>> let inner2 = Pattern (Subject (Symbol "b") Set.empty empty) []
>>> let outer = Pattern (Subject (Symbol "g") Set.empty empty) [inner1, inner2]
>>> toGram outer
"[g | a, b]"

codefenceThreshold :: Int Source #

Character threshold for codefence serialization.

Strings with length greater than this value will be serialized using codefence format (triple-backticks). Length is measured as total character count including newline characters.

Strings of this length or fewer use standard quote-delimited format.

Examples

>>> codefenceThreshold
120
>>> length "short string" <= codefenceThreshold
True