Documentation
¶
Overview ¶
Package hgl implements a parser for the HGL format which is used for Hangulize.
The HGL format is a simple config language. A HGL config has sections. Each section contains string-strings pairs. A section can be one of a dictionary or a pair list:
# dictionary section
lang:
id = "ita"
code = "it", "ita", "ita"
english = "Italian"
korean = "이탈리아어"
script = "roman"
# pair list section
rewrite:
"^gli$" -> "li"
"^glia$" -> "g.lia"
"^glioma$" -> "g.lioma"
"^gli{@}" -> "li"
"{@}gli" -> "li"
Keys in a dictionary section must be unique, and the section won't keep their order. While a pair list section works in an inversed way. A pair list section just keeps described pairs in therir order.
The media type of HGL files: text/vnd.hgl
Index ¶
Constants ¶
const ( // Illegal represents any string not matched with legal tokens. Illegal token = iota // EOF represents the end-of-file. EOF // Space represents any of whitespace characters except "\n". Space // Comment represents a comment content excluding initial "#". Comment // Newline means only "\n". HGL is a line-sensitive format. Newline // String represents a text literal. String // Colon means only ":". Colon // Comma means only ",". Comma // Equal means only "=". Equal // Arrow means only "->". Arrow )
const Version = "2.0.0"
Version is the version number of HGL package. The version follows Semantic Versioning 2.0.0.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DictSection ¶
type DictSection struct {
// contains filtered or unexported fields
}
DictSection has an unordered list of pairs. Each left of underlying pairs is unique.
func (DictSection) All ¶
func (s DictSection) All(left string) []string
All returns the right values.
func (DictSection) Injective ¶
func (s DictSection) Injective() (map[string]string, error)
Injective returns the underying 1-to-1 map of a dict section. If some right (values) has multiple values, it returns an error.
func (DictSection) Line ¶
func (l DictSection) Line() int
Line returns the line number where the node is defined.
func (DictSection) Map ¶
func (s DictSection) Map() map[string][]string
Map returns the underying map of a dict section.
func (DictSection) One ¶
func (s DictSection) One(left string) string
One assumes the given left (key) has only one right (values). Then returns the only right value.
func (DictSection) Pairs ¶
func (s DictSection) Pairs() []Pair
Pairs returns dict key-values as an array of pairs.
type Liner ¶
type Liner interface {
Line() int
}
Liner holds the line number belonging to the node.
All HGL nodes should implement this interface.
type ListSection ¶
type ListSection struct {
// contains filtered or unexported fields
}
ListSection has an ordered list of pairs.
func (ListSection) Line ¶
func (l ListSection) Line() int
Line returns the line number where the node is defined.
func (ListSection) Pairs ¶
func (s ListSection) Pairs() []Pair
Pairs returns underlying pairs as an array.
type Pair ¶
type Pair struct {
// contains filtered or unexported fields
}
Pair is a left-right tuple:
aa -> "ㅏ", "ㅐ" ^^^^^^^^^^^^^^^^
func (Pair) Left ¶
Left is a string. It is used for as keys in dict:
english = "Italian" ^^^^^^^
Or as left of pair:
aa -> "ㅏ", "ㅐ" ^^