compiler

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func DefaultIoProvider

func DefaultIoProvider() *ioProvider

func Execute

func Execute(text string, iop *ioProvider) error

func NewCloser

func NewCloser() *closer

func NewPipe added in v0.1.1

func NewPipe() (io.WriteCloser, io.ReadCloser)

func TestIoProvider

func TestIoProvider(stdin string) (*ioProvider, *strings.Builder, *strings.Builder)

func WrapReadFakeCloser added in v0.1.1

func WrapReadFakeCloser(r io.Reader) io.ReadCloser

func WrapWriteFakeCloser added in v0.1.1

func WrapWriteFakeCloser(w io.Writer) io.WriteCloser

Types

type Command

type Command struct {
	Executable string
	Arguments  []string
	Background bool
	Stdout     **io.WriteCloser
	Stderr     **io.WriteCloser
	Stdin      **io.Reader
	And        *Command
	Or         *Command
}

func Parse

func Parse(text string, tokens []LexicalToken, iop *ioProvider) ([]*Command, error)

func (*Command) Execute

func (c *Command) Execute() error

func (*Command) String

func (c *Command) String() string

type CompilerError

type CompilerError struct {
	Line    int
	Column  int
	Comment string
	Kind    CompilerErrorKind
}

func (CompilerError) Error

func (e CompilerError) Error() string

func (*CompilerError) Wrap

func (e *CompilerError) Wrap(kind CompilerErrorKind, comment string) *CompilerError

type CompilerErrorKind

type CompilerErrorKind uint8
const (
	CompilerErrorLexical CompilerErrorKind = iota
	CompilerErrorParser
)

func (CompilerErrorKind) String

func (k CompilerErrorKind) String() string

type LexicalToken

type LexicalToken struct {
	Content string
	// Index is the position of the token in the text.
	// This is not 100% accurate because it doesn't take quotation into account.
	// It's good enough for error messages.
	// Index is always the position of the first character of the token or within the token (in case of quotation).
	Index int
	Kind  LexicalTokenKind
}

func LexicalAnalysis

func LexicalAnalysis(text string, iop *ioProvider) ([]LexicalToken, error)

LexicalAnalysis performs lexical analysis on the given text and returns a slice of tokens. If an error gets returned it will be of type CompilerError.

func (LexicalToken) String

func (t LexicalToken) String() string

type LexicalTokenBuilder

type LexicalTokenBuilder struct {
	Content strings.Builder
	Index   int
	Kind    LexicalTokenKind
}

func (*LexicalTokenBuilder) Build

func (b *LexicalTokenBuilder) Build() LexicalToken

func (*LexicalTokenBuilder) IsPresent

func (t *LexicalTokenBuilder) IsPresent() bool

func (*LexicalTokenBuilder) Reset

func (t *LexicalTokenBuilder) Reset()

func (*LexicalTokenBuilder) SetIndex

func (b *LexicalTokenBuilder) SetIndex(i int)

func (*LexicalTokenBuilder) SetIndexIfEmpty

func (b *LexicalTokenBuilder) SetIndexIfEmpty(i int)

func (*LexicalTokenBuilder) SetKind

func (t *LexicalTokenBuilder) SetKind(kind LexicalTokenKind)

func (*LexicalTokenBuilder) WriteChar

func (b *LexicalTokenBuilder) WriteChar(c byte, i int)

func (*LexicalTokenBuilder) WriteRune

func (b *LexicalTokenBuilder) WriteRune(r rune, i int)

func (*LexicalTokenBuilder) WriteString

func (b *LexicalTokenBuilder) WriteString(s string, i int)

type LexicalTokenKind

type LexicalTokenKind uint8
const (
	// program name, command, argument, variable
	LexicalIdentifier LexicalTokenKind = iota
	// ;
	LexicalStop
	// &
	LexicalBackground
	// |
	LexicalPipeStdout
	// >
	LexicalFileStdout
	// >>
	LexicalFileAppendStdout
	// 2>
	LexicalFileStderr
	// 2>>
	LexicalFileAppendStderr
	// &>
	LexicalFileStdoutAndStderr
	// &>>
	LexicalFileAppendStdoutAndStderr
	// 2>&1
	LexicalStderrToStdout
	// 1>&2
	LexicalStdoutToStderr
	// <
	LexicalRedirectStdin
	// <<
	LexicalHereDocument
	// &&
	LexicalAnd
	// ||
	LexicalOr
)

func (LexicalTokenKind) String

func (k LexicalTokenKind) String() string

Jump to

Keyboard shortcuts

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