Skip to content

langs 实验性 ​

实验性

本包属于实验层:任何 0.x 版本都可能有不兼容变化(docs/release.md「API 稳定性」)。

go
import "github.com/tangoui/tango/ui/editor/langs"

本页由 site/tools/apigen 从源码注释生成(按 darwin 构建标签选文件),请勿手改。

Package langs embeds the built-in language data of the code editor: Monaco Monarch grammars, language configurations and file associations, plus the four Monaco base themes.

The JSON under data/ is generated from monaco-editor@0.56.0 by gen/export.mjs (see gen/README.md and NOTICE); nothing here depends on JavaScript at run time. Regular expressions are stored as {"$regex": source, "flags": flags} and decode to RegexSpec.

Experimental: this package's API may change in any 0.x release (see docs/release.md, "API 稳定性").

函数 ​

func BaseThemes ​

go
func BaseThemes() map[string]json.RawMessage

BaseThemes returns Monaco's base themes "vs", "vs-dark", "hc-black" and "hc-light", each as JSON {base, inherit, rules, colors}. The map is shared; callers must not modify it.

类型 ​

Conf ​

go
type Conf struct {
	LineComment      string
	BlockComment     [2]string
	Brackets         [][2]string
	AutoClosingPairs []Pair
	SurroundingPairs []Pair
	WordPattern      *RegexSpec
	Indentation      struct{ Increase, Decrease, IndentNextLine, Unindented *RegexSpec }
	Folding          struct {
		OffSide    bool
		Start, End *RegexSpec
	}
	// OnEnterRules are the language's onEnterRules, in order (the first
	// rule whose patterns all match wins).
	OnEnterRules []OnEnterRule
	// AutoCloseBefore is the language's autoCloseBefore: the characters
	// before which a pair is auto-closed when the auto-closing options are
	// "languageDefined". Empty when the language sets none (Monaco then
	// uses its defaults); no built-in language sets it to "".
	AutoCloseBefore string
	// ColorizedBracketPairs is the language's colorizedBracketPairs, nil
	// when it sets none (Monaco then colorizes its brackets).
	ColorizedBracketPairs [][2]string
}

Conf is the subset of Monaco's LanguageConfiguration the editor uses.

func (*Conf) UnmarshalJSON ​

go
func (c *Conf) UnmarshalJSON(b []byte) error

EnterAction ​

go
type EnterAction struct {
	Indent     string
	AppendText string
	RemoveText int
}

EnterAction is what an onEnter rule does (Monaco's EnterAction). Indent is the IndentAction as a string: "none" (keep the indentation), "indent" (one level deeper), "indentOutdent" (an indented line for the caret and the rest on a line at the old indentation) or "outdent" (one level shallower). AppendText is appended after the new line's indentation; RemoveText removes that many characters from it.

Language ​

go
type Language struct {
	ID               string
	Extensions       []string
	Filenames        []string
	FilenamePatterns []string
	Aliases          []string
	MimeTypes        []string
	// FirstLine is a JavaScript regular expression source matched against the
	// first line of a file ("" when the language declares none).
	FirstLine string
	// Grammar is the Monarch language definition, verbatim from the export.
	Grammar json.RawMessage
	// Conf is the decoded subset of the language configuration.
	Conf Conf
	// ConfRaw is the full language configuration, verbatim from the export
	// (Monaco's LanguageConfiguration JSON, regular expressions as
	// {"$regex", "flags"}). It includes fields Conf does not model.
	ConfRaw json.RawMessage
	// contains filtered or unexported fields
}

Language is one registered language id with its grammar and configuration.

func Builtin ​

go
func Builtin() []*Language

Builtin returns all built-in languages sorted by ID. The slice and its elements are shared; callers must not modify them.

func ByID ​

go
func ByID(id string) *Language

ByID returns the built-in language with the given id, or nil.

func ForFilename ​

go
func ForFilename(name string) *Language

ForFilename returns the language associated with a file name or path, or nil. It follows Monaco's association rules: the path is compared case-insensitively; an exact file name match beats a filename pattern, which beats an extension; among patterns and extensions the longest match wins; remaining ties go to the language registered last.

OnEnterRule ​

go
type OnEnterRule struct {
	BeforeText, AfterText, PreviousLineText *RegexSpec
	Action                                  EnterAction
}

OnEnterRule is one of Monaco's onEnterRules: when the text before the caret matches BeforeText and, when set, the text after it matches AfterText and the line above matches PreviousLineText, Enter applies Action.

func (*OnEnterRule) UnmarshalJSON ​

go
func (r *OnEnterRule) UnmarshalJSON(b []byte) error

Pair ​

go
type Pair struct {
	Open, Close string
	NotIn       []string
}

Pair is an auto-closing or surrounding pair. NotIn lists token scopes ("string", "comment") in which an auto-closing pair is not inserted.

func (*Pair) UnmarshalJSON ​

go
func (p *Pair) UnmarshalJSON(b []byte) error

RegexSpec ​

go
type RegexSpec struct {
	Source, Flags string
}

RegexSpec is a JavaScript regular expression as exported from Monaco: JSON {"$regex": source, "flags": flags}.

func (RegexSpec) MarshalJSON ​

go
func (r RegexSpec) MarshalJSON() ([]byte, error)

func (*RegexSpec) UnmarshalJSON ​

go
func (r *RegexSpec) UnmarshalJSON(b []byte) error

以 MIT 许可发布