token

package
v0.0.0-...-08dbdac Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package token package contains all the data abound the tokens. It is divided in token.go, which contains single and general tokens, line.go, which contains the line tokens and paragraph.go, which contains the paragraph tokens

Index

Constants

View Source
const (
	//TypeUndefined is an undefined token
	TypeUndefined = iota
	//TypeBold is an bold starting/ending token
	TypeBold = '*'
	//TypeItalic is an italic starting/ending token
	TypeItalic = '/'

	//TypeNewLine is a newline
	TypeNewLine = '\n'
	//TypeTab is a tab
	TypeTab = '\t'

	//TypeHeader is the token used in an header
	TypeHeader = '+'

	//TypeLess is the token used for subtitle and for divisor
	TypeLess = '-'

	//TypeEqual is the token used for title
	TypeEqual = '='

	TypeSBracketOpen  = '['
	TypeSBracketClose = ']'
	TypeEscape        = '\\'

	//TypeText is a text token
	TypeText = -1

	TypePipe  = '|'
	TypeQuote = '"'
	TypeAt    = '@'

	TypeParagraphHeader
	TypeParagraphText
	TypeParagraphDivisor
	TypeParagraphTitle
	TypeParagraphSubtitle
	TypeParagraphList
	TypeCheckBox
)

Types definition They can rapresent the rapresented char but it is not mandatory

Variables

View Source
var WhitespaceEscape = []Type{
	TypeBold,
	TypeItalic,
	TypeTab,
	TypeLess,
}

WhitespaceEscape is a slice of types that can be escaped from the EscapeToken

Functions

func EscapeString

func EscapeString(str string) string

EscapeString escapes the current string from charachetrs like * or /

Types

type AtToken

type AtToken struct{ SimpleToken }

AtToken is a simple token rapresenting a @ token

func (AtToken) Char

func (t AtToken) Char() rune

Char returns @

func (AtToken) Type

func (p AtToken) Type() Type

Type returns the type of the Token

type BoldToken

type BoldToken struct{ SimpleToken }

BoldToken rapresent a / token

func (BoldToken) Char

func (t BoldToken) Char() rune

Char returns *

func (BoldToken) Type

func (t BoldToken) Type() Type

Type returns the type of the Token

type CheckBoxToken

type CheckBoxToken struct {
	Token
	Char rune
}

CheckBoxToken rapresent a checkbox, it is composed by [Char] (SBRacketOpenToken,TextToken,SBRacketCloseToken)

func (CheckBoxToken) Type

func (p CheckBoxToken) Type() Type

Type returns the type of the Token

type CodeLine

type CodeLine struct {
	LineToken
	Lang string
}

CodeLine is a line containing the language name for CodeParagraph

func (CodeLine) String

func (l CodeLine) String() string

type CodeParagraph

type CodeParagraph struct {
	ParagraphToken
	Lang string
	Text TextParagraph
}

CodeParagraph is a paragraph containing code

type DivisorLine

type DivisorLine struct {
	LineToken
}

DivisorLine rapresent a header line

func (DivisorLine) String

func (l DivisorLine) String() string

type DivisorParagraph

type DivisorParagraph struct {
	ParagraphToken
}

DivisorParagraph is a pragraph containing a divisor line

func (DivisorParagraph) Type

func (p DivisorParagraph) Type() Type

Type returns the type of the Token

type EqualLine

type EqualLine struct {
	LineToken
	Indentation int
	Length      int
}

EqualLine rapresent a line containing only EqualToken EqualLine is used for Titles(Main and not)

func (EqualLine) String

func (l EqualLine) String() string

type EqualToken

type EqualToken struct{ SimpleToken }

EqualToken rapresent a - token

func (EqualToken) Char

func (t EqualToken) Char() rune

Char returns =

func (EqualToken) Type

func (t EqualToken) Type() Type

Type returns the type of the Token

type EscapeToken

type EscapeToken struct{ SimpleToken }

EscapeToken is a special toekn used for escpaing other tokens, it rapresent a \ token

func (EscapeToken) Type

func (p EscapeToken) Type() Type

Type returns the type of the Token

type HeaderLine

type HeaderLine struct {
	LineToken
	Tokens []Token
}

HeaderLine rapresent a header line

func (HeaderLine) String

func (l HeaderLine) String() string

type HeaderParagraph

type HeaderParagraph struct {
	ParagraphToken
	sMark.Options
}

HeaderParagraph is a pragraph containing header info

func (HeaderParagraph) Type

func (p HeaderParagraph) Type() Type

Type returns the type of the Token

type HeaderToken

type HeaderToken struct{ SimpleToken }

HeaderToken rapresent a + token

func (HeaderToken) Char

func (t HeaderToken) Char() rune

Char returns +

func (HeaderToken) Type

func (t HeaderToken) Type() Type

Type returns the type of the Token

type ItalicToken

type ItalicToken struct{ SimpleToken }

ItalicToken rapresent a / token

func (ItalicToken) Char

func (t ItalicToken) Char() rune

Char returns /

func (ItalicToken) Type

func (t ItalicToken) Type() Type

Type returns the type of the Token

type LessLine

type LessLine struct {
	LineToken
	Indentation int
	Length      int
}

LessLine rapresent a line containing only LessToken

func (LessLine) String

func (l LessLine) String() string

type LessToken

type LessToken struct{ SimpleToken }

LessToken rapresent a - token

func (LessToken) Char

func (t LessToken) Char() rune

Char returns -

func (LessToken) Type

func (t LessToken) Type() Type

Type returns the type of the Token

type LineContainer

type LineContainer struct {
	LineToken
	Indentation int
	Tokens      []Token

	//Attribute
	Quote bool
}

LineContainer is a token which rappresent a list of Tokens with some attributes

func LineContainerFromString

func LineContainerFromString(txt string) LineContainer

LineContainerFromString generate a LineContainer from a given text, it parses the tab and add them.

func (LineContainer) String

func (t LineContainer) String() string

String returns a string of the line with all tokens

func (LineContainer) StringNoTab

func (t LineContainer) StringNoTab() string

StringNoTab returns a string of the line with all tokens without tab

type LineToken

type LineToken interface {
	IsToken()
	fmt.Stringer
}

LineToken is a special interface that indicates a line

type ListLine

type ListLine struct {
	LineToken
	Text        LineContainer
	Indentation int
}

ListLine rapresent an element of a list

func (ListLine) String

func (l ListLine) String() string

type ListParagraph

type ListParagraph struct {
	ParagraphToken
	Items []ListLine
}

ListParagraph is a paragraph rapresenting a List

func (ListParagraph) Type

func (p ListParagraph) Type() Type

Type returns the type of the Token

type NewLineToken

type NewLineToken struct{ SimpleToken }

NewLineToken rapresent a \n token

func (NewLineToken) Char

func (t NewLineToken) Char() rune

Char returns \n

func (NewLineToken) Type

func (t NewLineToken) Type() Type

Type returns the type of the Token

type ParagraphToken

type ParagraphToken interface {
	Token
	IsParagraph()
}

ParagraphToken is a special interface that indicates a paragraph

type PipeToken

type PipeToken struct{ SimpleToken }

PipeToken is a simple token, rapresenting a | token

func (PipeToken) Char

func (t PipeToken) Char() rune

Char returns |

func (PipeToken) Type

func (p PipeToken) Type() Type

Type returns the type of the Token

type QuoteToken

type QuoteToken struct{ SimpleToken }

QuoteToken is a simple token rapresenting a " token

func (QuoteToken) Char

func (t QuoteToken) Char() rune

Char returns "

func (QuoteToken) Type

func (p QuoteToken) Type() Type

Type returns the type of the Token

type SBracketCloseToken

type SBracketCloseToken struct{ SimpleToken }

SBracketCloseToken rapresent a ] token

func (SBracketCloseToken) Char

func (t SBracketCloseToken) Char() rune

Char returns ]

func (SBracketCloseToken) Type

func (p SBracketCloseToken) Type() Type

Type returns the type of the Token

type SBracketOpenToken

type SBracketOpenToken struct{ SimpleToken }

SBracketOpenToken rapresent a [ token

func (SBracketOpenToken) Char

func (t SBracketOpenToken) Char() rune

Char returns [

func (SBracketOpenToken) Type

func (p SBracketOpenToken) Type() Type

Type returns the type of the Token

type SimpleToken

type SimpleToken interface {
	Token
	Char() rune
}

SimpleToken is a generic interface for implementing simple tokens, a token is a rune which is divided by normal text

type SubtitleParagraph

type SubtitleParagraph struct {
	ParagraphToken
	Text        string
	Indentation int
}

SubtitleParagraph is a paragraph rapresenting a Subtitle, it is similar to TitleParagraph

func (SubtitleParagraph) Type

func (p SubtitleParagraph) Type() Type

Type returns the type of the Token

type TabToken

type TabToken struct{ SimpleToken }

TabToken rapresent a \t token

func (TabToken) Char

func (t TabToken) Char() rune

Char returns \t

func (TabToken) Type

func (t TabToken) Type() Type

Type returns the type of the Token

type TextParagraph

type TextParagraph struct {
	ParagraphToken
	Indentation int
	Lines       []LineContainer
}

TextParagraph rapresent a single paragraph

func (TextParagraph) Type

func (p TextParagraph) Type() Type

Type returns the type of the Token

type TextToken

type TextToken struct {
	Token

	Indentation int
	Text        string

	//Attributes
	Bold   bool
	Italic bool
	Strike bool
	Link   string
	Image  image.Image
}

TextToken is a complex token which contains text and some attribute.

func (TextToken) String

func (t TextToken) String() string

String creates a string with the content of the TextToken It respect attributes

func (TextToken) StringEscape

func (t TextToken) StringEscape() string

StringEscape creates a string with the content of the TextToken It respect attributes, it escapes with backslash if it find escaped char

func (TextToken) Type

func (t TextToken) Type() Type

Type returns the type of the Token

type TitleParagraph

type TitleParagraph struct {
	ParagraphToken
	Text        string
	Indentation int
}

TitleParagraph is a paragraph rapresenting a Title

func (TitleParagraph) Type

func (p TitleParagraph) Type() Type

Type returns the type of the Token

type Token

type Token interface {
	IsToken()

	//Type returns the Type of the token
	//It is used for recognizing the Token
	Type() Type
}

Token is an interface for simple and complex tokens

type Type

type Type int

Type rappresent a type of token

Jump to

Keyboard shortcuts

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