parser

package
v0.0.0-...-9aa4175 Latest Latest
Warning

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

Go to latest
Published: May 16, 2023 License: BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package parser implements routines for reading the input files.

Index

Constants

This section is empty.

Variables

View Source
var TokenKind = struct {
	Code         TokenKindType
	Style        TokenKindType
	CommentBegin TokenKindType
	CommentWord  TokenKindType
	CommentEnd   TokenKindType
	Newline      TokenKindType
	EOF          TokenKindType
}{0, 1, 2, 3, 4, 6, 7}

TokenKind acts as a namespace for token types.

Functions

func Filter

func Filter(s string, filters []*regexp.Regexp) bool

Filter returns true if none of the filters match the word.

func FilterCommentedCode

func FilterCommentedCode(
	words []sf.Word,
	text *tui.TextBuffer,
	comments []CommentRange,
	lineBeginTokens []string,
) []sf.Word

FilterCommentedCode attemps to identify commented out code and to remove all matches words inside those comments. This is based on line ending characters and is mainly intended for languages using curly braces and/or semicolons to terminate lines. This also does not work well in continuous lines comments are used instead of block comments as they are all considered separate comments.

func IsWord

func IsWord(s string) bool

IsWord returns true if the string contains at least 2 letters and at most one aposthrophe for words like "don't".

func LexerStateInfoName

func LexerStateInfoName(info int) string

func LexerTokenKindName

func LexerTokenKindName(kind TokenKindType) string

func Parse

func Parse(
	fileName, source string,
	commentStyle CommentStyle,
	speller aspell.Speller,
	cfg *Config,
	ignoreList *IgnoreList,
	useDefaultCommentColor bool,
) sf.SourceFile

func TrimSymbols

func TrimSymbols(s string) (string, string, string)

TrimSymbols strips the string from leading and trailing ascii punctuation characters.

Types

type CommentRange

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

func (*CommentRange) Contains

func (self *CommentRange) Contains(index tui.SliceIndex) bool

type Dfa

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

func NewDfa

func NewDfa() Dfa

func (*Dfa) AddState

func (self *Dfa) AddState(info int) *DfaState

func (*Dfa) CurrentState

func (self *Dfa) CurrentState() *DfaState

func (*Dfa) ForceState

func (self *Dfa) ForceState(id State)

ForceState sets the current state and resets the token.

func (*Dfa) Process

func (self *Dfa) Process(c rune) (bool, int)

Process processes one character of input. Returns whether the current state changed and the length in runes of the token that caused the state change.

type DfaState

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

func (*DfaState) AddTransition

func (self *DfaState) AddTransition(token string, toState State)

func (*DfaState) Id

func (self *DfaState) Id() State

func (*DfaState) MakeRecursive

func (self *DfaState) MakeRecursive(descent, ascent string)

MakeRecursive turns this state into a recursive state. The descent token increases the recursion depth and ascent decreases it. Either of these do not count as state changes.

type Lexer

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

func NewLexer

func NewLexer(source string, commentStyle CommentStyle) Lexer

func (*Lexer) Next

func (self *Lexer) Next() (t Token)

Next returns the next token. If the input is exhausted all calls return EOF.

type State

type State int

State identifier

type Token

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

func (*Token) Kind

func (self *Token) Kind() TokenKindType

func (*Token) String

func (self *Token) String() string

String returns a string to display the token, use Text() to get the tokens text.

func (*Token) Text

func (self *Token) Text() string

type TokenKindType

type TokenKindType int

TokenKindType is the underlying type for the values in TokenKind.

type Transition

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳