Documentation ¶
Overview ¶
Package parser provides function to parse hranoprovod formatted files
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseStreamCallback ¶
func ParseStreamCallback(reader io.Reader, commentChar uint8, callback ParseCallback)
ParseStreamCallback parses stream and calls callback on node or error
Types ¶
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 ¶
ErrorConversion raised when the element value cannot be parsed as float
func NewErrorConversion ¶
func NewErrorConversion(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 Options ¶
type Options struct { // CommentChar contains the character used to indicate that the line is a comment CommentChar uint8 }
Options contains the parser related options
func NewDefaultOptions ¶
func NewDefaultOptions() *Options
NewDefaultOptions returns the default set of parser options
type ParseCallback ¶
type ParseCallback func(n *shared.ParserNode, err error) (stop bool)
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/v2/parser" ) func main() { p := parser.NewParser(parser.NewDefaultOptions()) 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