asciigoat's core library https://asciigoat.org/core
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Alejandro Mery 7e0b7cfb47 reflective: introduce UnmarshalTypeError{} 1 year ago
lexer lexer: add Hint to Error, which is expanded as "%s" instead of "%q" 1 year ago
reflective reflective: introduce UnmarshalTypeError{} 1 year ago
tools build-sys: import build system from darvaza.org/core 1 year ago
.editorconfig
.gitignore
LICENCE.txt
Makefile build-sys: import build system from darvaza.org/core 1 year ago
README.md README: add initial description of the package 1 year ago
docs.go
go.mod build-sys: import build system from darvaza.org/core 1 year ago
go.sum build-sys: import build system from darvaza.org/core 1 year ago
readcloser.go

README.md

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