lextwt

package module
v0.0.0-...-fd6362e Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2024 License: AGPL-3.0 Imports: 18 Imported by: 8

README

go.yarn.social/lextwt

go.yarn.social/lextwt is the Go library used by Yarn's main software component yarnd and several other components as a dependency to parse Twtxt feeds.

Quick Start

TBD

License

go.yarn.social/lextwt is licensed under the terms of the AGPLv3

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 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) IsBlock

func (n *Code) IsBlock() bool

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) Clone

func (n Comment) Clone() Elem

func (Comment) Format

func (n Comment) Format(f fmt.State, verb rune)

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) FollowMap

func (lis Comments) FollowMap() map[string]types.Twter

func (Comments) Following

func (lis Comments) Following() []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

func (Comments) Values

func (lis Comments) Values() url.Values

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 NewMedia

func NewMedia(alt, target, title string) *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) IsNaked

func (n *Link) IsNaked() bool

func (*Link) IsNil

func (n *Link) IsNil() bool

func (*Link) IsPlain

func (n *Link) IsPlain() bool

func (*Link) IsStandard

func (n *Link) IsStandard() 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

func (*Link) TextToTitle

func (n *Link) TextToTitle()

func (*Link) Title

func (n *Link) Title() 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) FormatAS

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

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 Salty

type Salty interface {
	Literal() string
	// contains filtered or unexported methods
}

func ParseSalty

func ParseSalty(line string) (Salty, error)

type SaltyEvent

type SaltyEvent struct {
	Command string   `json:"cmd"`
	Args    []string `json:"args"`
}

func NewSaltyEvent

func NewSaltyEvent(cmd string, args ...string) *SaltyEvent

func (*SaltyEvent) Clone

func (e *SaltyEvent) Clone() Elem

func (*SaltyEvent) Format

func (e *SaltyEvent) Format(f fmt.State, verb rune)

func (*SaltyEvent) IsNil

func (e *SaltyEvent) IsNil() bool

func (*SaltyEvent) Literal

func (s *SaltyEvent) Literal() string

type SaltyText

type SaltyText struct {
	Timestamp *DateTime
	User      SaltyUser
	Msg       []Elem
	Mentions  []*Mention
	Tags      []*Tag
	Links     []*Link
	Events    []*SaltyEvent
	// contains filtered or unexported fields
}

func NewSaltyText

func NewSaltyText(dt *DateTime, u SaltyUser, elems ...Elem) *SaltyText

func (*SaltyText) Hash

func (s *SaltyText) Hash(options ...types.HashOption) string

func (*SaltyText) Literal

func (s *SaltyText) Literal() string

func (*SaltyText) LiteralText

func (s *SaltyText) LiteralText() string

func (*SaltyText) MarshalJSON

func (s *SaltyText) MarshalJSON() ([]byte, error)

type SaltyUser

type SaltyUser struct {
	Nick   string
	Domain string
}

func NewSaltyUser

func NewSaltyUser(nick, domain string) SaltyUser

func (SaltyUser) HashURI

func (s SaltyUser) HashURI() string

URI returns the Well-Known URI for this Addr

func (SaltyUser) Literal

func (s SaltyUser) Literal() string

func (SaltyUser) String

func (s SaltyUser) String() string

func (SaltyUser) URI

func (s SaltyUser) URI() string

URI returns the Well-Known URI for this Addr

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) Subject

func (n *Subject) Subject() 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 = `\`
	TokSQUOTE TokType = "'"
	TokDQUOTE 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) Attrs

func (twt *Twt) Attrs() types.KV

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) ExpandMentions

func (twt *Twt) ExpandMentions(opts types.FmtOpts, lookup types.FeedLookup)

func (*Twt) ExpandTags

func (twt *Twt) ExpandTags(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(options ...types.HashOption) 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

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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