package directives

import "shirakumo.org/markless/directives"

This package holds the various syntax pieces of Markless documents, called Directive s. In many ways this is the primary element of the parsing machinery.

Typically you will only interact with the Constructor s of this package to assemble valid directives in the parser. This is also where the Parser interface is specified.

Index

Constants

const (
	ShowLines  = 0
	HideLines  = 1
	SpaceLines = 2
)

Functions

func BeginSurrounding

func BeginSurrounding(d Directive, c components.Component, line string, cursor int) int

Checks if the top directive is already this directive, in which case a recursive match would occur and it instead ends this one.

func Fail

func Fail(err string, line int)

Construct an Error and panic with it.

func NewError

func NewError(err string, line int) error

Types

type AlignLeft

type AlignLeft struct {
	BlockDirective
}

func (*AlignLeft) Begin

func (d *AlignLeft) Begin(line string, cursor int) int

func (*AlignLeft) ConsumePrefix

func (d *AlignLeft) ConsumePrefix(c components.Component, line string, cursor int) int

func (*AlignLeft) Name

func (d *AlignLeft) Name() string

func (*AlignLeft) String

func (d *AlignLeft) String() string

type AlignRight

type AlignRight struct {
	BlockDirective
}

func (*AlignRight) Begin

func (d *AlignRight) Begin(line string, cursor int) int

func (*AlignRight) ConsumePrefix

func (d *AlignRight) ConsumePrefix(c components.Component, line string, cursor int) int

func (*AlignRight) Name

func (d *AlignRight) Name() string

func (*AlignRight) String

func (d *AlignRight) String() string

type BaseDirective

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

Base mixin for all Directive s. Handles common method implementations to complete the interface. After deriving, you should at least implement [Name], [Kind], and the relevant [Begin], [Invoke], [End], [ConsumePrefix], and [ConsumeEnd].

func (*BaseDirective) Begin

func (d *BaseDirective) Begin(line string, cursor int) int

Called when the prefix BaseDirective.Test has matched and the directive is selected to start parsing. It may then still decide whether to actually match or not. If the match should fail, -1 is to be returned. Otherwise the directive should manipulate the parser stack via [Parser.Commit] and return the new cursor position after consuming input.

func (*BaseDirective) ConsumeEnd

func (d *BaseDirective) ConsumeEnd(component components.Component, line string, cursor int) int

Called to determine if an inline directive should end its processing. Returning -1 will let it continue.

func (*BaseDirective) ConsumePrefix

func (d *BaseDirective) ConsumePrefix(component components.Component, line string, cursor int) int

Called on successive lines when a block directive should consume any prefix it might have on that line. Returning -1 will fail the match and cause the processing stack to unwind.

func (*BaseDirective) Enabled

func (d *BaseDirective) Enabled() bool

Returns whether the directive is enabled or not. Disabled directives cannot match.

func (*BaseDirective) End

func (d *BaseDirective) End(component components.Component)

Called if the directive is aborted and should "undo" its match by manipulating the current [Top].

func (*BaseDirective) Invoke

func (d *BaseDirective) Invoke(component components.Component, line string, cursor int) int

Called when the directive should process input on successive lines after its initial match. Typically directives will simply defer to [Parser.ParseBlock] or [Parser.ParseInline].

func (*BaseDirective) Kind

func (d *BaseDirective) Kind() components.Kind

Used to determine if the directive is a [Block] or [Inline].

func (*BaseDirective) Name

func (d *BaseDirective) Name() string

The user-facing name of the directive, used for things such as the enable and disable instructions.

func (*BaseDirective) Parser

func (d *BaseDirective) Parser() Parser

Returns the parser that manages this directive. Used to access the parser state.

func (*BaseDirective) Prefix

func (d *BaseDirective) Prefix() *regexp.Regexp

Used to match whether the directive should begin.

func (*BaseDirective) SetEnabled

func (d *BaseDirective) SetEnabled(enabled bool)

func (*BaseDirective) Test

func (d *BaseDirective) Test(line string, cursor int) bool

A shorthand function to test the [Prefix] against the string starting at a specific cursor.

type BlockDirective

type BlockDirective struct {
	BaseDirective
}

Mixin for all block directives. Implements [Kind] and [Invoke] appropriately.

func (*BlockDirective) Invoke

func (d *BlockDirective) Invoke(component components.Component, line string, cursor int) int

func (*BlockDirective) Kind

func (d *BlockDirective) Kind() components.Kind

type Blockquote

type Blockquote struct {
	BlockDirective
}

func (*Blockquote) Begin

func (d *Blockquote) Begin(line string, cursor int) int

func (*Blockquote) ConsumePrefix

func (d *Blockquote) ConsumePrefix(c components.Component, line string, cursor int) int

func (*Blockquote) Name

func (d *Blockquote) Name() string

func (*Blockquote) String

func (d *Blockquote) String() string

type BlockquoteHeader

type BlockquoteHeader struct {
	BlockDirective
}

func (*BlockquoteHeader) Begin

func (d *BlockquoteHeader) Begin(line string, cursor int) int

func (*BlockquoteHeader) ConsumeEnd

func (d *BlockquoteHeader) ConsumeEnd(c components.Component, line string, cursor int) int

func (*BlockquoteHeader) ConsumePrefix

func (d *BlockquoteHeader) ConsumePrefix(c components.Component, line string, cursor int) int

func (*BlockquoteHeader) Invoke

func (d *BlockquoteHeader) Invoke(c components.Component, line string, cursor int) int

func (*BlockquoteHeader) Name

func (d *BlockquoteHeader) Name() string

func (*BlockquoteHeader) String

func (d *BlockquoteHeader) String() string

type Bold

type Bold struct {
	InlineDirective
}

func (*Bold) Begin

func (d *Bold) Begin(line string, cursor int) int

func (*Bold) End

func (d *Bold) End(c components.Component)

func (*Bold) Name

func (d *Bold) Name() string

func (*Bold) String

func (d *Bold) String() string

type Center

type Center struct {
	BlockDirective
}

func (*Center) Begin

func (d *Center) Begin(line string, cursor int) int

func (*Center) ConsumePrefix

func (d *Center) ConsumePrefix(c components.Component, line string, cursor int) int

func (*Center) Name

func (d *Center) Name() string

func (*Center) String

func (d *Center) String() string

type Code

type Code struct {
	InlineDirective
}

func (*Code) Begin

func (d *Code) Begin(line string, cursor int) int

func (*Code) End

func (d *Code) End(c components.Component)

func (Code) Invoke

func (d Code) Invoke(c components.Component, line string, cursor int) int

func (*Code) Name

func (d *Code) Name() string

func (*Code) String

func (d *Code) String() string

type CodeBlock

type CodeBlock struct {
	BlockDirective
}

func (*CodeBlock) Begin

func (d *CodeBlock) Begin(line string, cursor int) int

func (*CodeBlock) ConsumePrefix

func (d *CodeBlock) ConsumePrefix(c components.Component, line string, cursor int) int

func (*CodeBlock) Invoke

func (d *CodeBlock) Invoke(c components.Component, line string, cursor int) int

func (*CodeBlock) Name

func (d *CodeBlock) Name() string

func (*CodeBlock) String

func (d *CodeBlock) String() string

type Comment

type Comment struct {
	BlockDirective
}

func (*Comment) Begin

func (d *Comment) Begin(line string, cursor int) int

func (*Comment) End

func (d *Comment) End(c components.Component)

func (*Comment) Name

func (d *Comment) Name() string

func (*Comment) String

func (d *Comment) String() string

type Compound

type Compound struct {
	InlineDirective
}

func (*Compound) Begin

func (d *Compound) Begin(line string, cursor int) int

func (*Compound) ConsumeEnd

func (d *Compound) ConsumeEnd(c components.Component, line string, cursor int) int

func (*Compound) End

func (d *Compound) End(c components.Component)

func (*Compound) Invoke

func (d *Compound) Invoke(c components.Component, line string, cursor int) int

func (*Compound) Name

func (d *Compound) Name() string

func (*Compound) String

func (d *Compound) String() string

type Constructor

type Constructor func(parser Parser) Directive

type Dashes

type Dashes struct {
	InlineDirective
}

func (*Dashes) Begin

func (d *Dashes) Begin(line string, cursor int) int

func (*Dashes) End

func (d *Dashes) End(c components.Component)

func (*Dashes) Name

func (d *Dashes) Name() string

func (*Dashes) String

func (d *Dashes) String() string

type Directive

type Directive interface {
	Parser() Parser
	Name() string
	Kind() components.Kind
	Enabled() bool
	SetEnabled(enabled bool)
	Prefix() *regexp.Regexp
	Test(line string, cursor int) bool
	Begin(line string, cursor int) int
	Invoke(component components.Component, line string, cursor int) int
	End(component components.Component)
	ConsumePrefix(component components.Component, line string, cursor int) int
	ConsumeEnd(component components.Component, line string, cursor int) int
}

The primary interface for directives used by the Parser.

Typically you will want to at least rely on the BaseDirective mixin to simplify this interface down and handle common options, or even the BlockDirective, SingularLineDirective, or InlineDirective for more specific kinds of directives.

For specification of what the methods should do, please see the BaseDirective implementation.

func NewAlignLeft

func NewAlignLeft(parser Parser) Directive

func NewAlignRight

func NewAlignRight(parser Parser) Directive

func NewBlockquote

func NewBlockquote(parser Parser) Directive

func NewBlockquoteHeader

func NewBlockquoteHeader(parser Parser) Directive

func NewBold

func NewBold(parser Parser) Directive

func NewCenter

func NewCenter(parser Parser) Directive

func NewCode

func NewCode(parser Parser) Directive

func NewCodeBlock

func NewCodeBlock(parser Parser) Directive

func NewComment

func NewComment(parser Parser) Directive

func NewCompound

func NewCompound(parser Parser) Directive

func NewDashes

func NewDashes(parser Parser) Directive

func NewEmbed

func NewEmbed(parser Parser) Directive

func NewFootnote

func NewFootnote(parser Parser) Directive

func NewFootnoteReference

func NewFootnoteReference(parser Parser) Directive

func NewHeader

func NewHeader(parser Parser) Directive

func NewHorizontalRule

func NewHorizontalRule(parser Parser) Directive

func NewInstruction

func NewInstruction(parser Parser) Directive

func NewItalic

func NewItalic(parser Parser) Directive

func NewJustify

func NewJustify(parser Parser) Directive

func NewNewline

func NewNewline(parser Parser) Directive

func NewOrderedList

func NewOrderedList(parser Parser) Directive

func NewParagraph

func NewParagraph(parser Parser) Directive

func NewRoot

func NewRoot(parser Parser) Directive

func NewStrikethrough

func NewStrikethrough(parser Parser) Directive

func NewSubtext

func NewSubtext(parser Parser) Directive

func NewSupertext

func NewSupertext(parser Parser) Directive

func NewURL

func NewURL(parser Parser) Directive

func NewUnderline

func NewUnderline(parser Parser) Directive

func NewUnorderedList

func NewUnorderedList(parser Parser) Directive

type Embed

type Embed struct {
	BlockDirective
}

func (*Embed) Begin

func (d *Embed) Begin(line string, cursor int) int

func (*Embed) Invoke

func (d *Embed) Invoke(c components.Component, line string, cursor int) int

func (*Embed) Name

func (d *Embed) Name() string

func (*Embed) String

func (d *Embed) String() string

type EmbedType

type EmbedType interface {
	Name() string
	Create(target string, options []components.Option) *components.Embed
}

type Error

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

Error type for errors made in the document itself. This is used to signal documents that are invalid as per the Markless specification. The line number included indicates the line in the document on which the error occurred.

func (Error) Error

func (e Error) Error() string

type Footnote

type Footnote struct {
	BlockDirective
}

func (*Footnote) Begin

func (d *Footnote) Begin(line string, cursor int) int

func (*Footnote) Invoke

func (d *Footnote) Invoke(c components.Component, line string, cursor int) int

func (*Footnote) Name

func (d *Footnote) Name() string

func (*Footnote) String

func (d *Footnote) String() string

type FootnoteReference

type FootnoteReference struct {
	InlineDirective
}

func (*FootnoteReference) Begin

func (d *FootnoteReference) Begin(line string, cursor int) int

func (*FootnoteReference) End

func (d *FootnoteReference) End(c components.Component)

func (*FootnoteReference) Name

func (d *FootnoteReference) Name() string

func (*FootnoteReference) String

func (d *FootnoteReference) String() string
type Header struct {
	BlockDirective
}

func (*Header) Begin

func (d *Header) Begin(line string, cursor int) int

func (*Header) End

func (d *Header) End(c components.Component)

func (*Header) Invoke

func (d *Header) Invoke(c components.Component, line string, cursor int) int

func (*Header) Name

func (d *Header) Name() string

func (*Header) String

func (d *Header) String() string

type HorizontalRule

type HorizontalRule struct {
	BlockDirective
}

func (*HorizontalRule) Begin

func (d *HorizontalRule) Begin(line string, cursor int) int

func (*HorizontalRule) Name

func (d *HorizontalRule) Name() string

func (*HorizontalRule) String

func (d *HorizontalRule) String() string

type InlineDirective

type InlineDirective struct {
	BaseDirective
}

Mixin for all inline directives. Implements [Kind], [Invoke], and [End] appropriately. For surrounding inline directives whose end matches the same as their prefix, please see BeginSurrounding.

func (*InlineDirective) ConsumePrefix

func (d *InlineDirective) ConsumePrefix(component components.Component, line string, cursor int) int

func (*InlineDirective) End

func (d *InlineDirective) End(component components.Component)

func (*InlineDirective) Invoke

func (d *InlineDirective) Invoke(component components.Component, line string, cursor int) int

func (*InlineDirective) Kind

func (d *InlineDirective) Kind() components.Kind

type Instruction

type Instruction struct {
	BlockDirective
}

func (*Instruction) Begin

func (d *Instruction) Begin(line string, cursor int) int

func (*Instruction) End

func (d *Instruction) End(c components.Component)

func (*Instruction) Invoke

func (d *Instruction) Invoke(c components.Component, line string, cursor int) int

func (*Instruction) Name

func (d *Instruction) Name() string

func (*Instruction) String

func (d *Instruction) String() string

type InstructionType

type InstructionType interface {
	Name() string
	Create(arguments string) *components.Instruction
	Execute(c *components.Instruction, p Parser)
}

type Italic

type Italic struct {
	InlineDirective
}

func (*Italic) Begin

func (d *Italic) Begin(line string, cursor int) int

func (*Italic) End

func (d *Italic) End(c components.Component)

func (*Italic) Name

func (d *Italic) Name() string

func (*Italic) String

func (d *Italic) String() string

type Justify

type Justify struct {
	BlockDirective
}

func (*Justify) Begin

func (d *Justify) Begin(line string, cursor int) int

func (*Justify) ConsumePrefix

func (d *Justify) ConsumePrefix(c components.Component, line string, cursor int) int

func (*Justify) Name

func (d *Justify) Name() string

func (*Justify) String

func (d *Justify) String() string

type LineBreakMode

type LineBreakMode int

Representation of the line break handling behaviour in the parser. Can be either ShowLines, SpaceLines, or HideLines

type Newline

type Newline struct {
	InlineDirective
}

func (*Newline) Begin

func (d *Newline) Begin(line string, cursor int) int

func (*Newline) End

func (d *Newline) End(c components.Component)

func (*Newline) Name

func (d *Newline) Name() string

func (*Newline) String

func (d *Newline) String() string

type Noop

type Noop struct {
	BlockDirective
}

func (*Noop) Invoke

func (d *Noop) Invoke(c components.Component, line string, cursor int) int

type OptionType

type OptionType interface {
	Name() string
	Create(args string, p Parser) components.Option
}

type OrderedList

type OrderedList struct {
	BlockDirective
}

func (*OrderedList) Begin

func (d *OrderedList) Begin(line string, cursor int) int

func (*OrderedList) ConsumePrefix

func (d *OrderedList) ConsumePrefix(c components.Component, line string, cursor int) int

func (*OrderedList) Name

func (d *OrderedList) Name() string

func (*OrderedList) String

func (d *OrderedList) String() string

type Paragraph

type Paragraph struct {
	BlockDirective
}

func (*Paragraph) Begin

func (d *Paragraph) Begin(line string, cursor int) int

func (*Paragraph) ConsumePrefix

func (d *Paragraph) ConsumePrefix(c components.Component, line string, cursor int) int

func (*Paragraph) Invoke

func (d *Paragraph) Invoke(c components.Component, line string, cursor int) int

func (*Paragraph) Name

func (d *Paragraph) Name() string

func (*Paragraph) String

func (d *Paragraph) String() string

type Parser

type Parser interface {
	Embed(name string) (EmbedType, error)
	EmbedOption(name string) (OptionType, error)
	CompoundOption(name string) (OptionType, error)
	Instruction(name string) (InstructionType, error)
	Directive(name string) (Directive, error)
	LineBreakMode() LineBreakMode
	SetLineBreakMode(mode LineBreakMode)
	SetLabel(label string, c components.Component) Parser
	GetLabel(label string) components.Component
	LineNumber() int
	Push(d Directive, c components.Component) Parser
	Pop() StackEntry
	Peek() StackEntry
	Top() StackEntry
	Bottom() StackEntry
	StackLength() int
	Root() *components.Root
	Commit(d Directive, c components.Component) Parser
	Unwind(until int) Parser
	ParseLine(line string) Parser
	DispatchBlock(line string, cursor int) Directive
	ReadBlock(line string, cursor int) int
	ReadInline(line string, cursor int, end byte) int
	Parse(in io.Reader) Parser
}

The primary interface for parsers as used by Directive s.

Typically you won't need to implement this yourself and can instead rely on the standard implementation in shirakumo.org/markless/parser. Please see the documentation of that type for the expected behaviour of the interface functions.

type Root

type Root struct {
	BaseDirective
}

func (*Root) Invoke

func (d *Root) Invoke(component components.Component, line string, cursor int) int

func (*Root) Name

func (d *Root) Name() string

func (*Root) String

func (d *Root) String() string

type SingularLineDirective

type SingularLineDirective struct {
	BaseDirective
}

Mixin for single line block directives. Implements [Kind] and [Invoke] appropriately.

func (*SingularLineDirective) Invoke

func (d *SingularLineDirective) Invoke(component components.Component, line string, cursor int) int

func (*SingularLineDirective) Kind

func (d *SingularLineDirective) Kind() components.Kind

type StackEntry

type StackEntry struct {
	Directive Directive
	Component components.Component
}

type Strikethrough

type Strikethrough struct {
	InlineDirective
}

func (*Strikethrough) Begin

func (d *Strikethrough) Begin(line string, cursor int) int

func (*Strikethrough) ConsumeEnd

func (d *Strikethrough) ConsumeEnd(c components.Component, line string, cursor int) int

func (*Strikethrough) End

func (d *Strikethrough) End(c components.Component)

func (*Strikethrough) Invoke

func (d *Strikethrough) Invoke(c components.Component, line string, cursor int) int

func (*Strikethrough) Name

func (d *Strikethrough) Name() string

func (*Strikethrough) String

func (d *Strikethrough) String() string

type Subtext

type Subtext struct {
	InlineDirective
}

func (*Subtext) Begin

func (d *Subtext) Begin(line string, cursor int) int

func (*Subtext) ConsumeEnd

func (d *Subtext) ConsumeEnd(c components.Component, line string, cursor int) int

func (*Subtext) End

func (d *Subtext) End(c components.Component)

func (*Subtext) Invoke

func (d *Subtext) Invoke(c components.Component, line string, cursor int) int

func (*Subtext) Name

func (d *Subtext) Name() string

func (*Subtext) String

func (d *Subtext) String() string

type Supertext

type Supertext struct {
	InlineDirective
}

func (*Supertext) Begin

func (d *Supertext) Begin(line string, cursor int) int

func (*Supertext) ConsumeEnd

func (d *Supertext) ConsumeEnd(c components.Component, line string, cursor int) int

func (*Supertext) End

func (d *Supertext) End(c components.Component)

func (*Supertext) Invoke

func (d *Supertext) Invoke(c components.Component, line string, cursor int) int

func (*Supertext) Name

func (d *Supertext) Name() string

func (*Supertext) String

func (d *Supertext) String() string

type URL

type URL struct {
	InlineDirective
}

func (*URL) Begin

func (d *URL) Begin(line string, cursor int) int

func (*URL) ConsumePrefix

func (d *URL) ConsumePrefix(c components.Component, line string, cursor int) int

func (*URL) End

func (d *URL) End(c components.Component)

func (*URL) Invoke

func (d *URL) Invoke(c components.Component, line string, cursor int) int

func (*URL) Name

func (d *URL) Name() string

func (*URL) String

func (d *URL) String() string

type Underline

type Underline struct {
	InlineDirective
}

func (*Underline) Begin

func (d *Underline) Begin(line string, cursor int) int

func (*Underline) End

func (d *Underline) End(c components.Component)

func (*Underline) Name

func (d *Underline) Name() string

func (*Underline) String

func (d *Underline) String() string

type UnorderedList

type UnorderedList struct {
	BlockDirective
}

func (*UnorderedList) Begin

func (d *UnorderedList) Begin(line string, cursor int) int

func (*UnorderedList) ConsumePrefix

func (d *UnorderedList) ConsumePrefix(c components.Component, line string, cursor int) int

func (*UnorderedList) Name

func (d *UnorderedList) Name() string

func (*UnorderedList) String

func (d *UnorderedList) String() string