scanner

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EOF byte = 0 // used to imitate end of file

	CommentSign             = '#'
	AnnotationDelimiterPart = '/'
	ObjectOpen              = '{'
	ArrayOpen               = '['
	ContextOpenSign         = '('
	ContextCloseSign        = ')'
	LinkSymbol              = '@'
	DoubleQuote             = '"'
	RegexDelimiter          = '/'
)

Variables

View Source
var ErrRecursionDetected = errors.New("recursion detected")

Functions

func IsNewLine

func IsNewLine(c byte) bool

Types

type Lexeme

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

func NewLexeme

func NewLexeme(type_ LexemeType, begin, end bytes.Index, file *fs.File) *Lexeme

func (Lexeme) Begin

func (lex Lexeme) Begin() bytes.Index

func (Lexeme) End

func (lex Lexeme) End() bytes.Index

func (Lexeme) File

func (lex Lexeme) File() *fs.File

func (Lexeme) String

func (lex Lexeme) String() string

func (Lexeme) Type

func (lex Lexeme) Type() LexemeType

func (Lexeme) Value

func (lex Lexeme) Value() bytes.Bytes

type LexemeEvent

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

type LexemeEventType

type LexemeEventType uint8
const (
	KeywordBegin LexemeEventType = iota
	KeywordEnd
	ParameterBegin
	ParameterEnd
	AnnotationBegin
	AnnotationEnd
	SchemaBegin
	SchemaEnd
	TextBegin
	TextEnd
	ContextOpen
	ContextClose
	EnumBegin
	EnumEnd
)

func (LexemeEventType) IsBeginning

func (e LexemeEventType) IsBeginning() bool

func (LexemeEventType) IsEnding

func (e LexemeEventType) IsEnding() bool

func (LexemeEventType) IsSingle

func (e LexemeEventType) IsSingle() bool

func (LexemeEventType) String

func (e LexemeEventType) String() string

func (LexemeEventType) ToLexemeType

func (e LexemeEventType) ToLexemeType() LexemeType

type LexemeType

type LexemeType uint8
const (
	// Keyword represent a name of Directive, i.e. URL, GET, Path, 200, etc.
	Keyword LexemeType = iota

	// Parameter represent a parameter for directive (regexp/jsight for TYPE)
	Parameter

	// Annotation represent user's annotation to directive in a free-text form.
	Annotation

	// Schema represent a jSchema inside directive's body (Body, TYPE, 200, etc).
	Schema

	// Json represents a JSON inside directive's body (CONFIG).
	Json

	// Text represents a text inside directive Description body.
	Text

	// ContextExplicitOpening represent explicitly opened context, so that it can
	// be later explicitly closed.
	ContextExplicitOpening

	// ContextExplicitClosing represents explicitly closed context.
	ContextExplicitClosing

	// Enum represents an enum body.
	Enum
)

func (LexemeType) String

func (t LexemeType) String() string

type Scanner

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

func NewJApiScanner

func NewJApiScanner(file *fs.File) *Scanner

func (*Scanner) CurrentIndex

func (s *Scanner) CurrentIndex() bytes.Index

func (*Scanner) File

func (s *Scanner) File() *fs.File

func (*Scanner) Next

func (s *Scanner) Next() (*Lexeme, *jerr.JApiError)

Next reads japi file by bytes, detects lexemes beginnings and ends and returns them as soon as they found returns false for the end of file

func (*Scanner) SetCurrentIndex

func (s *Scanner) SetCurrentIndex(i bytes.Index)

SetCurrentIndex to continue scanning from certain position

type Stack

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

Stack ths stack of scanners.

func (*Stack) AddIncludeTraceToError

func (s *Stack) AddIncludeTraceToError(je *jerr.JApiError)

AddIncludeTraceToError adds include trace to given error.

func (*Stack) Empty

func (s *Stack) Empty() bool

Empty returns true is stack is empty.

func (*Stack) Pop

func (s *Stack) Pop() *Scanner

Pop pops last add scanner.

func (*Stack) Push

func (s *Stack) Push(scanner *Scanner, at bytes.Index) error

Push pushed new scanner into stack with position in this scanner where it was pushed. This position will be necessary for creating stack trace.

func (*Stack) ToDirectiveIncludeTracer

func (s *Stack) ToDirectiveIncludeTracer() directive.IncludeTracer

ToDirectiveIncludeTracer converts this scanner stack to directive's include trace. We can't pass this stack itself 'cause it will be empty at the time when it will be necessary.

Jump to

Keyboard shortcuts

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