syntax

package
v0.0.0-...-bbcbdef Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: Unlicense Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generic

type Generic struct {
	Scopes       []Scope
	Wrapped      []Wrapped
	StaticWords  map[string]theme.LanguageConstruct
	DynamicWords []Word
}

Generic understands and parses a general map of a language syntax.

func (Generic) Parse

func (g Generic) Parse(d []rune) Map

type Map

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

Map is a representation of the mapped syntax of a file. It knows about scopes and various language constructs.

func (Map) Depth

func (m Map) Depth(pos int) int

Depth returns the scope depth at pos.

func (Map) Layers

func (m Map) Layers() []text.SyntaxLayer

Layers returns all syntax layers from all nested scopes.

type Scope

type Scope struct {
	// Open is the string that opens a scope.  For example, { is a
	// common way to open a scope.
	Open string

	// Close is the string that closes a scope.  For example, } is
	// a common way to close a scope.
	Close string
}

Scope represents an opening and closing scope. These will always use the theme.ScopePair language construct.

type Syntax

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

Syntax is a type that reads Go source code to provide information on it.

func New

func New() *Syntax

New constructs a new *Syntax value with theme as its Theme field.

func (*Syntax) Layers

func (s *Syntax) Layers() []text.SyntaxLayer

Layers returns a gxui.CodeSyntaxLayer for each construct used from s.Theme when s.Parse was called. The corresponding gxui.CodeSyntaxLayer will have its foreground and background constructs set, and all positions that should be highlighted that construct will be stored.

func (*Syntax) Parse

func (s *Syntax) Parse(source string) error

Parse parses the passed in Go source code, replacing s's stored context with that of the parsed source. It returns any error encountered while parsing source, but will still store as much information as possible.

type Word

type Word struct {
	// Before is the word (without spaces) that prefixes this
	// construct.  Do not list separators (e.g. } or )).
	Before string

	// After is the word (without spaces) that suffixes this
	// construct.  Do not list separators (e.g. { or ().
	After string

	// Construct is the language construct that this word detects.
	Construct theme.LanguageConstruct
}

Word represents a word surrounded by defining characteristics which should be a certain type of language construct.

A simple example: a go function can be detected with:

syntax.Word{Before: []rune("func"), Construct: theme.Func}

TODO: for many languages, using words before and after is not sufficient; but for now, because we don't want to mess with the problems of multiple spaces, we're just going to leave it.

type Wrapped

type Wrapped struct {
	// Open is the string that opens a the wrapped type, e.g. " or '.
	Open string

	// Close is the string that closes the wrapped type.  Can be the
	// same as Open.
	Close string

	// Escapes is any way that one could escape a Close.
	Escapes []string

	// Construct is the language construct that this wrapped type
	// detects.
	Construct theme.LanguageConstruct

	// Nested tells us whether or not this type can nest itself
	Nested bool
}

Wrapped represents a wrapped type, like a string or comment block.

Jump to

Keyboard shortcuts

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