File: sml.go

package info (click to toggle)
golang-github-tideland-golib 4.24.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,144 kB
  • sloc: makefile: 4
file content (81 lines) | stat: -rw-r--r-- 1,995 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Tideland Go Library - Simple Markup Language
//
// Copyright (C) 2009-2017 Frank Mueller / Tideland / Oldenburg / Germany
//
// All rights reserved. Use of this source code is governed
// by the new BSD license.

package sml

//--------------------
// IMPORTS
//--------------------

//--------------------
// PROCESSOR
//--------------------

// Processor represents any type able to process
// a node structure. Four callbacks then will be
// called with the according data.
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
}

//--------------------
// BUILDER
//--------------------

// Builder defines the callbacks for the reader
// to handle parts of the document.
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
}

//--------------------
// NODES
//--------------------

// Node represents the common interface of all nodes (tags and text).
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
}

// EOF