parser

package
v0.0.0-...-7578981 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	RED    = "\x1b[31m"
	GREEN  = "\x1b[32m"
	BLUE   = "\x1b[34m"
	YELLOW = "\x1b[33m"
	CYAN   = "\x1b[36m"

	RESET = "\x1b[0m"
)
View Source
const ATOM = 57348
View Source
const LEXERROR = 57352
View Source
const NUMBER = 57350
View Source
const OPQUERY = 57347
View Source
const OPRULE = 57346
View Source
const STRING = 57349
View Source
const VARIABLE = 57351
View Source
const VERSION = "0.8.6"

Variables

View Source
var (
	// Not a Number, normalized.
	NaN = Number{
		Num:        1,
		Den:        0,
		Normalized: true,
	}
	// Min Number value
	MinNumber = Number{
		Num:        int(math.MinInt64) + 1,
		Den:        1,
		Normalized: true,
	}
	// Max Number value
	MaxNumber = Number{
		Num:        int(math.MaxInt64),
		Den:        1,
		Normalized: true,
	}
	ZeroNumber = Number{
		Num:        0,
		Den:        1,
		Normalized: true,
	}
	OneNumber = Number{
		Num:        1,
		Den:        1,
		Normalized: true,
	}
)
View Source
var (
	FLOATFORMAT = "%.2f"
)

Functions

func Gcd

func Gcd(a, b int) int

Compute Gcd of 2 numbers. Gcd is always positive. It is 0 only if both args are 0.

func NewLexer

func NewLexer(input io.Reader, sourcename string) *myLex

NewLexer from io.Reader

Types

type Atom

type Atom struct {
	Value string
}

Atom is immutable

func (Atom) Clone

func (t Atom) Clone() Term

Clone implements Term.

func (Atom) CloneNsp

func (t Atom) CloneNsp(nsp int) Term

CloneNsp implements Term.

func (Atom) Pretty

func (s Atom) Pretty() string

Pretty implements AtomicTerm.

func (Atom) String

func (s Atom) String() string

type CompoundTerm

type CompoundTerm struct {
	Functor  string
	Children []Term
}

a compound term is a Term with children. A compound term withoutout children remains a compound term, different from an Atom.

func (CompoundTerm) Clone

func (t CompoundTerm) Clone() Term

func (CompoundTerm) CloneNsp

func (t CompoundTerm) CloneNsp(nsp int) Term

CloneNsp implements Term.

func (CompoundTerm) Pretty

func (c CompoundTerm) Pretty() string

Pretty implements Term.

func (CompoundTerm) String

func (c CompoundTerm) String() string

type Number

type Number struct {
	Num        int
	Den        int
	Normalized bool
}

Number are immutable Number can silently overflow, when exceeding int64 capacity.

func (Number) Ceil

func (n Number) Ceil() Number

Return the smallest integer Number that is greater or equal to n. n can be negative or positive.

func (Number) ChSign

func (n Number) ChSign() Number

func (Number) Clone

func (n Number) Clone() Term

Clone implements Term.

func (Number) CloneNsp

func (n Number) CloneNsp(nsp int) Term

CloneNsp implements Term.

func (Number) Eq

func (n Number) Eq(t Term) bool

Check if the provided Term is a Number and is Equal to n. No unification, no variable, no underscore accepted here.

func (Number) Floor

func (n Number) Floor() Number

Return the largest integer Number that is less or equal to n. n can be negative or positive.

func (Number) Greater

func (n Number) Greater(r Number) bool

Check if n is strictly greater than r

func (Number) IsInteger

func (n Number) IsInteger() bool

func (Number) IsNaN

func (n Number) IsNaN() bool

Check if Nan. Notice that 0/0 is valid, as it would normalize to 0/1, ie 0.

func (Number) IsZero

func (n Number) IsZero() bool

func (Number) Less

func (n Number) Less(r Number) bool

Check if n is strictly less than r

func (Number) Minus

func (n Number) Minus(r Number) Number

result = n - r

func (Number) Normalize

func (n Number) Normalize() Number

Normalize the internal representation of a number. 0/0 is normalized as 0/1.

func (Number) Plus

func (n Number) Plus(r Number) Number

result = n + r

func (Number) Pretty

func (n Number) Pretty() string

Pretty implements Term. Tries to be clever ...

func (Number) String

func (n Number) String() string

String implements Term. Dump internal data.

func (Number) Times

func (n Number) Times(r Number) Number

result = n * r

func (Number) ToInt

func (n Number) ToInt() int

Return the integer immediately below n if n >= 0 or immediatly GREATER than n if n < 0. Integer are left unchanged. Same behavior as in : i = int(float64(x)) Panic if n is NaN.

type String

type String struct {
	Value string
}

String is immutable

func (String) Clone

func (t String) Clone() Term

Clone implements Term.

func (String) CloneNsp

func (t String) CloneNsp(nsp int) Term

CloneNsp implements Term.

func (String) Pretty

func (t String) Pretty() string

Pretty implements AtomicTerm.

func (String) String

func (s String) String() string

type Term

type Term interface {
	String() string // String() is the string representation of the entire term
	// Strings are neither quoted nor escaped internally, they are stored without the start/end " or `
	Pretty() string        // Pretty() is the string representation of the term, pretty printing lists and rules and queries.
	Clone() Term           // Clone() returns a deep copy of the term
	CloneNsp(nsp int) Term // CloneNsp() returns a deep copy of the term with a new name space
}

func MustParseString

func MustParseString(input string, sourcename string) []Term

func Parse

func Parse(rdr io.Reader, sourcename string) ([]Term, error)

func ParseFile

func ParseFile(filename string) ([]Term, error)

func ParseString

func ParseString(input string, sourcename string) ([]Term, error)

type Underscore

type Underscore struct{}

func (Underscore) Clone

func (Underscore) Clone() Term

Clone implements Term.

func (Underscore) CloneNsp

func (Underscore) CloneNsp(nsp int) Term

CloneNsp implements Term.

func (Underscore) Pretty

func (u Underscore) Pretty() string

Pretty implements Term.

func (Underscore) String

func (u Underscore) String() string

type Variable

type Variable struct {
	Name string
	Nsp  int // name space
}

Variable are immutable

func (Variable) Clone

func (t Variable) Clone() Term

Clone implements Term.

func (Variable) CloneNsp

func (t Variable) CloneNsp(nsp int) Term

CloneNsp implements Term.

func (Variable) Compare

func (v Variable) Compare(w Variable) int

Ordering of variables is defined by their name space and name.

func (Variable) Eq

func (v Variable) Eq(t Term) bool

True if and only if t is a Variable and t Name and Nsp are identical to V

func (Variable) Pretty

func (t Variable) Pretty() string

Pretty implements Term.

func (Variable) String

func (v Variable) String() string

Jump to

Keyboard shortcuts

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