core

package module
v0.3.9 Latest Latest
Warning

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

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

README

asciigoat's core library

Go Reference Go Report Card

This package contains the basics for writing simple parsers of text languages heavily inspired by Rob Pike's talk on Lexical Scanning in Go in 2011 which you can watch online to get better understanding of the ideas behind asciigoat.

asciigoat is MIT licensed.

Lexer

lexer.Reader

The lexer package provides lexer.Reader which is actually an io.RuneScanner that buffers accepted runes until you are ready to emit or discard.

lexer.Position

lexer.Position is a (Line, Column) pair with methods to facilitate tracking your position on the source Reader.

lexer.Error

lexer.Error is an unwrappable error with a token position and hint attached.

lexer.StateFn

At the heart of asciigoat we have state functions as proposed on Rob Pike's famous talk which return the next state function parsing is done. Additionally there is a Run() helper that implements the loop.

rune checkers

Rune checkers are simple functions that tell if a rune is of a class or it's not. Fundamental checkers are provided by the unicode package.

Our lexer.Reader uses them on its Accept() and AcceptAll() methods to make it easier to consume the source document.

To facilitate the declaration of rune classes in the context of asciigoat powered parsers we include a series of rune checker factories.

  • NewIsIn(string)
  • NewIsInRunes(...rune)
  • NewIsNot(checker)
  • NewIsOneOf(...checker)

Others

ReadCloser

ReadCloser assists in providing a io.Closer to Readers or buffers without on, or unearthing one if available so io.ReadCloser can be fulfilled.

See also

Documentation

Overview

Package core provides the foundations of asciigoat packages

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewReadCloser

func NewReadCloser(r io.Reader) io.ReadCloser

NewReadCloser wraps a io.Reader to satisfy io.ReadCloser if needed

func NewReadCloserBytes

func NewReadCloserBytes(b []byte) io.ReadCloser

NewReadCloserBytes wraps a bytes slice to implement a io.ReadCloser

func NewReadCloserString

func NewReadCloserString(s string) io.ReadCloser

NewReadCloserString wraps a string to implement a io.ReadCloser

Types

type ReadCloser

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

ReadCloser adds a Close() to Readers without one

func (*ReadCloser) Close

func (rc *ReadCloser) Close() error

Close attempts to Close the underlying io.Reader, or remove it if it doesn't support Close() and fail if closed twice

func (*ReadCloser) Read

func (rc *ReadCloser) Read(b []byte) (int, error)

Read passes the Read() call to the underlying io.Reader and fail if it was Closed()

Directories

Path Synopsis
Package lexer provides basic helpers to implement parsers
Package lexer provides basic helpers to implement parsers

Jump to

Keyboard shortcuts

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