lang

package
v0.0.0-...-643d18f Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package lang 各类语言解析和管理。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(data []byte, blocks []Blocker, h *errors.Handler) map[int][]byte

Parse 分析 data 中的内容,并以行号作为键名,代码块作为键值返回

Types

type Blocker

type Blocker interface {
	// 确定 l 的当前位置是否匹配 blocker 的起始位置。
	BeginFunc(l *lexer) bool

	// 确定 l 的当前位置是否匹配 blocker 的结束位置,若匹配则返回中间的字符串。
	// 返回内容以行为单位进行分割。
	//
	// 如果不使用返回的内容,可以返回空值。
	// 比如字符串,只需要返回 true,以确保找到了结束位置,但是内容可以直接返回 nil。
	//
	// 如果在到达文件末尾都没有找到结束符,则应该返回 nil, false
	EndFunc(l *lexer) ([][]byte, bool)
}

Blocker 接口定义了解析代码块的所有操作。 通过 BeginFunc 查找匹配的起始位置, 通过 EndFunc 查找结束位置,并返回所有的块内容。

type Language

type Language struct {
	DisplayName string    // 显示友好的名称
	Name        string    // 语言唯一名称,一律小写
	Blocks      []Blocker // 注释块的解析规则定义
	Exts        []string  // 扩展名列表,必须以 . 开头且小写
}

Language 语言模块的定义

func Get

func Get(name string) *Language

Get 获取指定语言的定义信息

若不存在,则返回 nil

func GetByExt

func GetByExt(ext string) *Language

GetByExt 根据扩展名获取语言定义信息

ext 必须以 . 作为开头 若不存在,则返回 nil

func Langs

func Langs() []*Language

Langs 返回所有支持的语言

Jump to

Keyboard shortcuts

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