scanner

package
v0.2.0-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

much of this code was inspired (meaning copied) from craftinginterpreters

Index

Constants

View Source
const (
	ModeNone                 = 0           // nothing special
	ModeStrictCapitalization = (1 << iota) // report capitalization errors
	ModeAlias                              // interpret the tokens as alias (enables *arg syntax)
)

Variables

This section is empty.

Functions

func Scan

func Scan(options Options) ([]token.Token, error)

scan the provided ddp-source-code from the given Options if an error occured the resulting tokens are nil

func ScanAlias

func ScanAlias(alias token.Token, errorHandler ddperror.Handler) ([]token.Token, error)

scans the provided source as a function alias expects the alias without the enclosing ""

Types

type Mode

type Mode uint32

type Options

type Options struct {
	// Optional Filename to name the source
	// this file is read if Source is nil
	FileName string
	// Optional ddp-source-code
	// if nil, FileName is read
	Source []byte
	// the mode used during scanning
	ScannerMode Mode
	// ErrorHandler used during scanning
	// May be nil
	ErrorHandler ddperror.Handler
}

Options on where to get the source-tokens from

type Scanner

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

func New

func New(filePath string, src []byte, errorHandler ddperror.Handler, mode Mode) (*Scanner, error)

returns a new scanner, or error if one could not be created prefers src, but if src is nil it attempts to read the source-code from filePath

func (*Scanner) Mode

func (s *Scanner) Mode() Mode

func (*Scanner) NextToken

func (s *Scanner) NextToken() token.Token

scan the next token from source if all tokens were scanned it returns EOF

func (*Scanner) ScanAll

func (s *Scanner) ScanAll() []token.Token

scan all tokens in the scanners source until EOF occurs

Jump to

Keyboard shortcuts

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