lextwt

package
v0.0.0-...-7609c90 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const EOF rune = -(iota + 1)

EOF represents an end of file.

Variables

View Source
var ErrParseElm = errors.New("error parsing element")
View Source
var ErrParseToken = errors.New("error parsing digit")

Functions

func DecodeJSON

func DecodeJSON(data []byte) (types.Twt, error)

func DefaultTwtManager

func DefaultTwtManager()

func NewLexer

func NewLexer(r io.Reader) *lexer

NewLexer tokenizes input for parser.

func NewParser

func NewParser(l *lexer) *parser

func NewTwtFile

func NewTwtFile(twter types.Twter, comments Comments, twts types.Twts) *lextwtFile

func ParseFile

func ParseFile(r io.Reader, twter types.Twter) (types.TwtFile, error)

ParseFile and return time & count limited twts + comments

func ParseLine

func ParseLine(line string, twter types.Twter) (twt types.Twt, err error)

Types

type Code

type Code struct {
	// contains filtered or unexported fields
}

func NewCode

func NewCode(text string, codeType CodeType) *Code

func (*Code) Clone

func (n *Code) Clone() Elem

func (*Code) Format

func (n *Code) Format(state fmt.State, r rune)

func (*Code) FormatMarkdown

func (n *Code) FormatMarkdown(out io.Writer)

func (*Code) IsNil

func (n *Code) IsNil() bool

func (*Code) Literal

func (n *Code) Literal() string

func (*Code) String

func (n *Code) String() string

String replaces line separator with newlines

type CodeType

type CodeType int
const (
	CodeInline CodeType = iota + 1
	CodeBlock
)

type Comment

type Comment struct {
	// contains filtered or unexported fields
}

func NewComment

func NewComment(comment string) *Comment

func NewCommentValue

func NewCommentValue(comment, key, value string) *Comment

func (Comment) IsNil

func (n Comment) IsNil() bool

func (Comment) Key

func (n Comment) Key() string

func (Comment) Literal

func (n Comment) Literal() string

func (Comment) String

func (n Comment) String() string

func (Comment) Value

func (n Comment) Value() string

type Comments

type Comments []*Comment

func (Comments) Followers

func (lis Comments) Followers() []types.Twter

func (Comments) GetAll

func (lis Comments) GetAll(prefix string) []types.Value

func (Comments) GetN

func (lis Comments) GetN(key string, n int) (types.Value, bool)

func (Comments) String

func (lis Comments) String() string

type DateTime

type DateTime struct {
	// contains filtered or unexported fields
}

func NewDateTime

func NewDateTime(dt time.Time, lit string) *DateTime

func (*DateTime) CloneDateTime

func (n *DateTime) CloneDateTime() *DateTime

func (*DateTime) DateTime

func (n *DateTime) DateTime() time.Time

func (*DateTime) IsNil

func (n *DateTime) IsNil() bool

func (*DateTime) Literal

func (n *DateTime) Literal() string

func (*DateTime) String

func (n *DateTime) String() string

type Elem

type Elem interface {
	IsNil() bool     // A typed nil will fail `elem == nil` We need to unbox to test.
	Literal() string // value as read from input.
	Clone() Elem     // clone element.

	fmt.Formatter
}
var LineSeparator Elem = &lineSeparator{}

func ParseText

func ParseText(text string) ([]Elem, error)

type Line

type Line interface {
	IsNil() bool     // A typed nil will fail `elem == nil` We need to unbox to test.
	Literal() string // value as read from input.
}
type Link struct {
	// contains filtered or unexported fields
}
func NewLink(text, target string, linkType LinkType) *Link

func (*Link) Clone

func (n *Link) Clone() Elem

func (*Link) Format

func (n *Link) Format(state fmt.State, r rune)

func (*Link) IsMedia

func (n *Link) IsMedia() bool

func (*Link) IsNil

func (n *Link) IsNil() bool

func (*Link) Literal

func (n *Link) Literal() string

func (*Link) String

func (n *Link) String() string

func (*Link) Target

func (n *Link) Target() string

func (*Link) Text

func (n *Link) Text() string

type LinkType

type LinkType int
const (
	LinkStandard LinkType = iota + 1
	LinkMedia
	LinkPlain
	LinkNaked
)

type ListError

type ListError []error

func (ListError) Error

func (e ListError) Error() string

type Mention

type Mention struct {
	// contains filtered or unexported fields
}

func NewMention

func NewMention(name, target string) *Mention

func (*Mention) Clone

func (n *Mention) Clone() Elem

func (*Mention) Domain

func (n *Mention) Domain() string

func (*Mention) Err

func (n *Mention) Err() error

func (*Mention) Format

func (n *Mention) Format(state fmt.State, r rune)

func (*Mention) FormatCompact

func (n *Mention) FormatCompact(out io.Writer)

func (*Mention) FormatHTML

func (n *Mention) FormatHTML(out io.Writer)

func (*Mention) FormatMarkdown

func (n *Mention) FormatMarkdown(out io.Writer)

func (*Mention) FormatText

func (n *Mention) FormatText(out io.Writer)

func (*Mention) IsNil

func (n *Mention) IsNil() bool

func (*Mention) Literal

func (n *Mention) Literal() string

func (*Mention) Name

func (n *Mention) Name() string

func (*Mention) SetTarget

func (n *Mention) SetTarget(target string)

func (*Mention) String

func (n *Mention) String() string

func (*Mention) Target

func (n *Mention) Target() string

func (*Mention) Twter

func (n *Mention) Twter() types.Twter

func (*Mention) URL

func (n *Mention) URL() *url.URL

type Subject

type Subject struct {
	// contains filtered or unexported fields
}

func NewSubject

func NewSubject(text string) *Subject

func NewSubjectTag

func NewSubjectTag(tag, target string) *Subject

func (*Subject) Clone

func (n *Subject) Clone() Elem

func (*Subject) Format

func (n *Subject) Format(state fmt.State, r rune)

func (*Subject) IsNil

func (n *Subject) IsNil() bool

func (*Subject) Literal

func (n *Subject) Literal() string

func (*Subject) String

func (n *Subject) String() string

func (*Subject) Tag

func (n *Subject) Tag() types.TwtTag

func (*Subject) Text

func (n *Subject) Text() string

type Tag

type Tag struct {
	// contains filtered or unexported fields
}

func NewTag

func NewTag(tag, target string) *Tag

func (*Tag) Clone

func (n *Tag) Clone() Elem

func (*Tag) CloneTag

func (n *Tag) CloneTag() *Tag

func (*Tag) Format

func (n *Tag) Format(state fmt.State, r rune)

func (*Tag) FormatCompact

func (n *Tag) FormatCompact(out io.Writer)

func (*Tag) FormatHTML

func (n *Tag) FormatHTML(out io.Writer)

func (*Tag) FormatMarkdown

func (n *Tag) FormatMarkdown(out io.Writer)

func (*Tag) FormatText

func (n *Tag) FormatText(out io.Writer)

func (*Tag) IsNil

func (n *Tag) IsNil() bool

func (*Tag) Literal

func (n *Tag) Literal() string

func (*Tag) String

func (n *Tag) String() string

func (*Tag) Target

func (n *Tag) Target() string

func (*Tag) Text

func (n *Tag) Text() string

func (*Tag) URL

func (n *Tag) URL() (*url.URL, error)

type Text

type Text struct {
	// contains filtered or unexported fields
}

func NewText

func NewText(txt string) *Text

func (*Text) Clone

func (n *Text) Clone() Elem

func (*Text) Format

func (n *Text) Format(state fmt.State, r rune)

func (*Text) IsNil

func (n *Text) IsNil() bool

func (*Text) IsSpace

func (n *Text) IsSpace() bool

func (*Text) Literal

func (n *Text) Literal() string

func (*Text) String

func (n *Text) String() string

type TokType

type TokType string

TokType passed to parser.

const (
	TokILLEGAL TokType = "ILLEGAL" // Illegal UTF8
	TokEOF     TokType = "EOF"     // End-of-File

	TokNUMBER TokType = "NUMBER" // Digit 0-9
	TokLS     TokType = "LS"     // Unicode Line Separator
	TokNL     TokType = "NL"     // New Line
	TokSTRING TokType = "STRING" // String
	TokCODE   TokType = "CODE"   // Code Block
	TokSPACE  TokType = "SPACE"  // White Space
	TokTAB    TokType = "TAB"    // Tab
	TokSCHEME TokType = "://"    // URL Scheme

	TokCOLON  TokType = ":"
	TokHYPHEN TokType = "-"
	TokDOT    TokType = "."
	TokPLUS   TokType = "+"
	TokT      TokType = "T"
	TokZ      TokType = "Z"

	TokHASH  TokType = "#"
	TokEQUAL TokType = "="

	TokAT     TokType = "@"
	TokLT     TokType = "<"
	TokGT     TokType = ">"
	TokLPAREN TokType = "("
	TokRPAREN TokType = ")"
	TokLBRACK TokType = "["
	TokRBRACK TokType = "]"
	TokBANG   TokType = "!"
	TokBSLASH TokType = `\`
)

TokType values

type Token

type Token struct {
	Type    TokType
	Literal []rune
}

func (Token) String

func (t Token) String() string

type Twt

type Twt struct {
	// contains filtered or unexported fields
}

func NewTwt

func NewTwt(twter types.Twter, dt *DateTime, elems ...Elem) *Twt

func (Twt) Clone

func (twt Twt) Clone() types.Twt

func (Twt) CloneTwt

func (twt Twt) CloneTwt() *Twt

func (Twt) Created

func (twt Twt) Created() time.Time

func (*Twt) Elems

func (twt *Twt) Elems() []Elem
func (twt *Twt) ExpandLinks(opts types.FmtOpts, lookup types.FeedLookup)

func (*Twt) FilePos

func (twt *Twt) FilePos() int

func (Twt) Format

func (twt Twt) Format(state fmt.State, c rune)

func (Twt) FormatText

func (twt Twt) FormatText(mode types.TwtTextFormat, opts types.FmtOpts) string

func (Twt) FormatTwt

func (twt Twt) FormatTwt() string

func (*Twt) GobDecode

func (twt *Twt) GobDecode(data []byte) error

func (*Twt) GobEncode

func (twt *Twt) GobEncode() ([]byte, error)

func (Twt) Hash

func (twt Twt) Hash() string

func (*Twt) IsNil

func (twt *Twt) IsNil() bool

func (*Twt) IsZero

func (twt *Twt) IsZero() bool
func (twt Twt) Links() types.LinkList

func (*Twt) Literal

func (twt *Twt) Literal() string

func (*Twt) LiteralText

func (twt *Twt) LiteralText() string

func (Twt) MarshalJSON

func (twt Twt) MarshalJSON() ([]byte, error)

func (Twt) Mentions

func (twt Twt) Mentions() types.MentionList

func (Twt) String

func (twt Twt) String() string

func (Twt) Subject

func (twt Twt) Subject() types.Subject

func (Twt) Tags

func (twt Twt) Tags() types.TagList

func (*Twt) Text

func (twt *Twt) Text() string

func (Twt) Twter

func (twt Twt) Twter() types.Twter

type Twts

type Twts []*Twt

Twts typedef to be able to attach sort methods

func (Twts) Len

func (twts Twts) Len() int

func (Twts) Less

func (twts Twts) Less(i, j int) bool

func (Twts) Swap

func (twts Twts) Swap(i, j int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL