Documentation ¶
Overview ¶
Package parser provides function to parse hranoprovod formatted files
Index ¶
Examples ¶
Constants ¶
const ( DefaultDateFormat = "2006/01/02" DefaultCommentChar = '#' )
Variables ¶
This section is empty.
Functions ¶
func ParseFileCallback ¶
func ParseFileCallback(fileName string, c Config, callback ParseCallback) error
func ParseStreamCallback ¶
func ParseStreamCallback(reader io.Reader, c Config, callback ParseCallback) error
ParseStreamCallback parses stream and calls callback on node or error
Types ¶
type Config ¶
type Config struct { // CommentChar contains the character used to indicate that the line is a comment CommentChar uint8 }
Config contains the parser configuration
func NewDefaultConfig ¶
func NewDefaultConfig() Config
NewDefaultConfig returns the default set of parser configuration
type ErrorBadSyntax ¶
ErrorBadSyntax used when the stream contains bad syntax
func NewErrorBadSyntax ¶
func NewErrorBadSyntax(lineNumber int, line string) *ErrorBadSyntax
NewErrorBadSyntax creates new ErrorBadSyntax error
func (*ErrorBadSyntax) Error ¶
func (e *ErrorBadSyntax) Error() string
Error returns the error message
type ErrorConversion ¶
type ErrorConversion struct { Text string LineNumber int Line string // contains filtered or unexported fields }
ErrorConversion raised when the element value cannot be parsed as float
func NewErrorConversion ¶
func NewErrorConversion(err error, text string, lineNumber int, line string) *ErrorConversion
NewErrorConversion creates new ErrorConversion error
func (*ErrorConversion) Error ¶
func (e *ErrorConversion) Error() string
Error returns the error message
type ErrorIO ¶
type ErrorIO struct { FileName string // contains filtered or unexported fields }
ErrorIO raised on IO issue
func NewErrorIO ¶
NewErrorIO creates new IO Error
type ParseCallback ¶
type ParseCallback func(n *shared.ParserNode, err error) (stop bool, cbError error)
ParseCallback is called on node or error event when parsing the stream
type Parser ¶
type Parser struct { Nodes chan *shared.ParserNode Errors chan error Done chan bool // contains filtered or unexported fields }
Parser is the parser data structure
func (Parser) ParseStream ¶
ParseStream parses the contents of stream
Example ¶
package main import ( "fmt" "strings" "github.com/aquilax/hranoprovod-cli/v3/parser" ) func main() { p := parser.NewParser(parser.NewDefaultConfig()) file := `2011/07/17: el1: 1.22 ел 2: 4 el/3: 3 2011/07/18: el1: 1.33 ел 5: 5 el/7: 4 el1: 1.35 ` go p.ParseStream(strings.NewReader(file)) func() { for { select { case node := <-p.Nodes: fmt.Println(node.Header) case <-p.Errors: return case <-p.Done: return } } }() }
Output: 2011/07/17 2011/07/18