brassica-1.0.0: Featureful sound change applier
CopyrightSee LICENSE file
LicenseBSD3
MaintainerBrad Neimann
Safe HaskellSafe-Inferred
LanguageHaskell2010

Brassica.SFM.SFM

Description

This module implements basic support for the SIL Standard Format Marker (SFM) format, used by dictionary software such as FieldWorks. This format forms the basis of standards such as Multi-Dictionary Formatter (MDF), implemented here in Brassica.SFM.MDF.

Synopsis

Linear SFM documents

data Field Source #

A single field of an SFM file.

Constructors

Field 

Fields

Instances

Instances details
Show Field Source # 
Instance details

Defined in Brassica.SFM.SFM

Methods

showsPrec :: Int -> Field -> ShowS #

show :: Field -> String #

showList :: [Field] -> ShowS #

type SFM = [Field] Source #

An SFM file, being a list of fields.

parseSFM Source #

Arguments

:: String

Name of source file

-> String

Input SFM data to parse

-> Either (ParseErrorBundle String Void) SFM 

Parse an SFM file to an SFM value.

exactPrintField :: Field -> String Source #

Print a single field as String.

exactPrintSFM :: SFM -> String Source #

Given an SFM, reconstruct the original file. A trivial wrapper around exactPrintField.

stripSourcePos :: Field -> Field Source #

Set the fieldSourcePos of a Field to Nothing. Useful for making debug output shorter.

Hierarchies

type Hierarchy = Map String String Source #

The hierarchy underlying an SFM document, defined as a map from field names to their parents. Fields which are absent from the map are treated as roots.

data SFMTree Source #

Rose tree describing a hierarchical SFM document.

Constructors

Root [SFMTree]

Root node

Filled Field [SFMTree]

A Field with zero or more children.

Missing String [SFMTree]

A missing level of the hierarchy: a marker which is inferred from the presence of its children.

Instances

Instances details
Show SFMTree Source # 
Instance details

Defined in Brassica.SFM.SFM

toTree :: Hierarchy -> SFM -> SFMTree Source #

Generate a tree structure from an SFM document according to the given Hierarchy. Fields are converted to Filled nodes, containing as many following nodes as possible, until the next node which is at the same level of the hierarchy or lower. Missing nodes are created for any missing levels of the hierarchy.

fromTree :: SFMTree -> SFM Source #

Inverse of toTree: convert an SFMTree back into a linear SFM document.

mapField :: (Field -> Field) -> SFMTree -> SFMTree Source #

Map a function over all the Fields in an SFMTree.

searchField :: (Field -> Maybe a) -> SFMTree -> [a] Source #

Depth-first search for fields under an SFMTree which satisfy the given predicate.