Documentation ¶
Overview ¶
The Tideland Go Library sml package provides a very simple markup language using a kind of LISP like notation with curly braces.
The tag only consists out of the chars 'a' to 'z', '0' to '9' and '-'. Also several parts of the tag can be seperated by colons. The package contains a kind of DOM as well as a parser and a processor. The latter is used e.g. for printing SML documents.
Index ¶
- Constants
- func IsBuilderError(err error) bool
- func IsNoRootProcessorError(err error) bool
- func IsReaderError(err error) bool
- func IsRegisteredPluginError(err error) bool
- func ReadSML(reader io.Reader, builder Builder) error
- func ValidateTag(tag string) ([]string, error)
- func WriteSML(node Node, ctx *WriterContext) error
- type Builder
- type KeyStringValueTreeBuilder
- func (tb *KeyStringValueTreeBuilder) BeginTagNode(tag string) error
- func (tb *KeyStringValueTreeBuilder) CommentNode(comment string) error
- func (tb *KeyStringValueTreeBuilder) EndTagNode() error
- func (tb *KeyStringValueTreeBuilder) RawNode(raw string) error
- func (tb *KeyStringValueTreeBuilder) TextNode(text string) error
- func (tb *KeyStringValueTreeBuilder) Tree() (collections.KeyStringValueTree, error)
- type Node
- type NodeBuilder
- type Processor
- type WriterContext
- type WriterProcessor
- type WriterProcessors
Constants ¶
const ( ErrBuilder = iota + 1 ErrReader ErrNoRootProcessor ErrRegisteredPlugin )
Variables ¶
This section is empty.
Functions ¶
func IsBuilderError ¶
IsBuilderError checks for an error during node building.
func IsNoRootProcessorError ¶
IsNoRootProcessorError checks for an unregistered root processor.
func IsReaderError ¶
IsReaderError checks for an error during SML text reading.
func IsRegisteredPluginError ¶
IsRegisteredPluginError checks for the error of an already registered plugin.
func ValidateTag ¶
validateTag checks if a tag is valid. Only the chars 'a' to 'z', '0' to '9', '-' and ':' are accepted. It also transforms it to lowercase and splits the parts at the colons.
func WriteSML ¶
func WriteSML(node Node, ctx *WriterContext) error
WriteSML uses one WriterProcessor and possible more as plugins to write the SML node to the passed writer. The prettyPrint flag controls if the writing is in a more beautiful formatted way.
Types ¶
type Builder ¶
type Builder interface { // BeginTagNode is called when new tag node begins. BeginTagNode(tag string) error // EndTagNode is called when the tag node ends. EndTagNode() error // TextNode is called for each text data. TextNode(text string) error // RawNode is called for each raw data. RawNode(raw string) error // Comment is called for each comment data inside a node. CommentNode(comment string) error }
Builder defines the callbacks for the reader to handle parts of the document.
type KeyStringValueTreeBuilder ¶
type KeyStringValueTreeBuilder struct {
// contains filtered or unexported fields
}
KeyStringValueTreeBuilder implements Builder to parse a file and create a KeyStringValueTree.
func NewKeyStringValueTreeBuilder ¶
func NewKeyStringValueTreeBuilder() *KeyStringValueTreeBuilder
NewNodeBuilder return a new nnode builder.
func (*KeyStringValueTreeBuilder) BeginTagNode ¶
func (tb *KeyStringValueTreeBuilder) BeginTagNode(tag string) error
BeginTagNode implements the Builder interface.
func (*KeyStringValueTreeBuilder) CommentNode ¶
func (tb *KeyStringValueTreeBuilder) CommentNode(comment string) error
Comment implements the Builder interface.
func (*KeyStringValueTreeBuilder) EndTagNode ¶
func (tb *KeyStringValueTreeBuilder) EndTagNode() error
EndTagNode implements the Builder interface.
func (*KeyStringValueTreeBuilder) RawNode ¶
func (tb *KeyStringValueTreeBuilder) RawNode(raw string) error
RawNode implements the Builder interface.
func (*KeyStringValueTreeBuilder) TextNode ¶
func (tb *KeyStringValueTreeBuilder) TextNode(text string) error
TextNode implements the Builder interface.
func (*KeyStringValueTreeBuilder) Tree ¶
func (tb *KeyStringValueTreeBuilder) Tree() (collections.KeyStringValueTree, error)
Tree returns the created tree.
type Node ¶
type Node interface { // Tag returns the tag in case of a tag node, otherwise nil. Tag() []string // Len returns the length of a text or the number of subnodes, // depending on the concrete type of the node. Len() int // ProcessWith is called for the processing of this node. ProcessWith(p Processor) error // String returns a simple string representation of the node. String() string }
Node represents the common interface of all nodes (tags and text).
type NodeBuilder ¶
type NodeBuilder struct {
// contains filtered or unexported fields
}
NodeBuilder creates a node structure.
func (*NodeBuilder) BeginTagNode ¶
func (nb *NodeBuilder) BeginTagNode(tag string) error
BeginTagNode implements the Builder interface.
func (*NodeBuilder) CommentNode ¶
func (nb *NodeBuilder) CommentNode(comment string) error
CommentNode implements the Builder interface.
func (*NodeBuilder) EndTagNode ¶
func (nb *NodeBuilder) EndTagNode() error
EndTagNode implements the Builder interface.
func (*NodeBuilder) RawNode ¶
func (nb *NodeBuilder) RawNode(raw string) error
RawNode implements the Builder interface.
func (*NodeBuilder) Root ¶
func (nb *NodeBuilder) Root() (Node, error)
Root returns the root node of the read document.
func (*NodeBuilder) TextNode ¶
func (nb *NodeBuilder) TextNode(text string) error
TextNode implements the Builder interface.
type Processor ¶
type Processor interface { // OpenTag is called if a tag is opened. OpenTag(tag []string) error // CloseTag is called if a tag is closed. CloseTag(tag []string) error // Text is called for each text data inside a node. Text(text string) error // Raw is called for each raw data inside a node. Raw(raw string) error // Comment is called for each comment data inside a node. Comment(comment string) error }
Processor represents any type able to process a node structure. Four callbacks then will be called with the according data.
type WriterContext ¶
type WriterContext struct {
// contains filtered or unexported fields
}
WriterContext controls the parameters of a writing.
func NewWriterContext ¶
func NewWriterContext(wp WriterProcessor, w io.Writer, pretty bool, indentStr string) *WriterContext
NewWriterContext creates a new writer context.
func (*WriterContext) Register ¶
func (ctx *WriterContext) Register(tag string, wp WriterProcessor) error
Register adds a writer processor which will be responsible for processing if the tag is matching.
func (*WriterContext) Writef ¶
func (ctx *WriterContext) Writef(format string, args ...interface{}) error
Writef writes a formatted string to the writer.
type WriterProcessor ¶
type WriterProcessor interface { // WriterProcessor is a processor itself. Processor // SetContext sets the writer context. SetContext(ctx *WriterContext) }
WriterProcessor a processor
func NewStandardSMLWriter ¶
func NewStandardSMLWriter() WriterProcessor
NewStandardMSLWriter creates a new writer for a ML document in standard notation.
func NewXMLWriter ¶
func NewXMLWriter(rawTag string) WriterProcessor
NewXMLWriter creates a new writer for a ML document in XML notation.
type WriterProcessors ¶
type WriterProcessors map[string]WriterProcessor
WriterProcessors is a map of processors that can be plugged into the used SML writer. The key is the first part of each tag.