sexpr

package module
v0.0.0-...-9c3d4f4 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: MIT Imports: 4 Imported by: 1

README

sexpr

Go Report Card

Symbolic-expression parser in golang.

go get gitlab.com/mae.earth/pkg/sexpr
root,_ := ParseString("(+ 1 2)",nil)
out,_ := OutputString(root)
fmt.Printf("%s",out)
(+ 1 2)
package main

import (
	"fmt"
	"gitlab.com/mae.earth/pkg/sexpr"
	"gitlab.com/mae.earth/pkg/sexpr/cell"
)

type value string

func (v value) String() string {
	return fmt.Sprintf("%s", string(v))
}

func main() {

	c := cell.New(cell.List(value("+"), value("1"), value("2")),nil)

	str,err := sexpr.OutputString(c)
	if err != nil {
		panic(err)
	}

	root,err := sexpr.ParseString(str,nil)
	if err != nil {
		panic(err)
	}

	if root.IsList() {
		list := root.List()
		fmt.Printf("%d atoms in the list\n",cell.Count(list))

		head := cell.First(list)
		fmt.Printf("operation %s\n",head.Value())
	
		rest := cell.Rest(list)

		for {
			if rest == nil {
				break
			}
			fmt.Printf("\t%s\n",rest.Value())

			rest = rest.Next()	
		}
		
	}
}
3 atoms in the list
operation +
	1
	2

Documentation

Overview

mae.earth/pkg/sexpr/helper.go

mae.earth/pkg/sexpr/outputer.go

mae.earth/pkg/sexpr/parser.go

Package sexpr symbolic expression parser

Index

Constants

View Source
const (
	DefaultBufferSize = 1024
	Whitespace        = " "
)

Variables

View Source
var (
	/* ErrZeroStack */
	ErrZeroStack = fmt.Errorf("Zero Stack")
	/* ErrNoSource */
	ErrNoSource = fmt.Errorf("No Source")
	/* ErrRootIsNil */
	ErrRootIsNil = fmt.Errorf("Root is nil")
)

Functions

func Fuzz

func Fuzz(data []byte) int

Fuzz see https://github.com/dvyukov/go-fuzz

func OutputString

func OutputString(root *cell.Cell) (string, error)

OutputString

func Parse

func Parse(reader io.Reader, config *Configuration) (*cell.Cell, error)

Parse

func ParseString

func ParseString(s string, config *Configuration) (*cell.Cell, error)

ParseString

Types

type Configuration

type Configuration struct {
	Verbose    bool
	Annotate   bool
	BufferSize int
}

Configuration

type Literal

type Literal string

Literal

func (Literal) String

func (l Literal) String() string

String

type String

type String string

String

func (String) String

func (s String) String() string

String

Directories

Path Synopsis
mae.earth/pkg/sexpr/cell/cell.go mae.earth/pkg/sexpr/cell/functions.go
mae.earth/pkg/sexpr/cell/cell.go mae.earth/pkg/sexpr/cell/functions.go

Jump to

Keyboard shortcuts

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