parser

package
v0.0.0-...-186a780 Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package parser implements an in-memory representation of text/gemini, as well as a simple Pratt parser which can read a string containing the same and generate this representation.

text/gemini is documented here: https://gemini.circumlunar.space/docs/gemtext.gmi

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DontMergeWhitespace if true will cause the parser to preserve any
	// whitespace. Normally, all spaces between non-whitespace characters
	// are collapsed into a single space character. This flag disables
	// this behavior.
	DontMergeWhitespace bool

	// Continue if true will cause the parser to ignore any errors and
	// continue parsing anyway.
	Continue bool
}

Config allows the parser to be configured to behave in different ways. The defaults are usually fine.

type Gemtext

type Gemtext struct {
	// Elements represents an ordered list of elements. They can be of any
	// of the below element types. The type of a specific element in this
	// list can be determined using a type assertion.
	Elements []interface{}
}

Gemtext represents an entire text/gemini document.

func Parse

func Parse(input string, config Config) (*Gemtext, error)

Parse parses an input stream of text/gemini, and returns a Gemtext object, and possibly an error.

If a syntax error is encountered, then unless the Continue flag is set in the Config, the parser will halt and return nil and a SyntaxError.

type Heading

type Heading struct {
	// Text contains the header text, not including any # characters or
	// leading or trailing whitespace.
	Text string

	// Level is an integer between 1 and 3 inclusive which represents
	// the depth of the header.
	Level int
}

Heading represents a single heading element.

type Link struct {
	// URL represents the URL part of the link.
	URL string

	// Label represents the label part of the link.
	Label string
}

Link represents a single link element.

type List

type List struct {
	// Items is a list of the list elements, not including any * characters
	// or leading or trailing whitespace.
	Items []string
}

List represents a single list element.

type Preformatted

type Preformatted struct {
	// Text contains the text of the preformatted block, but without any
	// leading or trailing “`. Any text between these lines is preserved
	// including whitespace.
	Text string

	// Alt is any text after the leading “`, up til the first newline.
	Alt string
}

Preformatted represents a pre-formatted text block.

type Quote

type Quote struct {
	// Text is the text which is quoted, not including the > character or
	// any leading or trailing whitespace.
	Text string
}

Quote represents a block-quote element.

type SyntaxError

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

SyntaxError represents a syntax error in the input text/gemini.

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

Error implements the Error interface on SyntaxError.

type Text

type Text struct {
	// Text represents the contents of the text element.
	Text string
}

Text represents a single text element, usually a paragraph.

Jump to

Keyboard shortcuts

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