hgl

package module
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2018 License: MIT Imports: 7 Imported by: 2

README

HGL

HGL은 Hangulize 2에서 언어 별 전사 규칙을 표현하기 위한 형식이다. 이름은 hangulize의 자음 H, G, L에서 따왔다. HGL 파일의 미디어타입은 text/vnd.hgl이다.

문법

HGL 문서는 여러 섹션으로 구성된다. 섹션엔 이름이 있다. 가령 이름이 hangulize일 경우 hangulize:으로 표시한다:

hangulize:
    ...

섹션은 둘 중 한 형식으로 구성된다. 하나는 사전형이다. 사전형 섹션은 key = value[, value2, ...] 형식으로 키와 값의 연관 관계를 표현한다. 사전형 속에서 한 키는 단 한 번만 나타나야 하고 여러번 나타날 수 없다. 여기서 키들 사이의 순서는 중요하지 않다. 키는 하나의 문자열이고 값은 여러개의 문자열이다:

jaeum:
    "ㄱ" = "기역"
    "ㄴ" = "니은"

tossi:
    "은(는)" = "은", "는"
    "이(가)" = "이", "가"

다른 하나는 목록형이다. 목록형 섹션 역시 키와 값들의 연관을 표현하지만 그 관계는 작성한 순서대로 나열된다. 목록에서의 위치에 따라 의미가 다를 수 있어서 키는 중복돼도 괜찮다. key -> value[, value2, ...] 형식으로 표현한다:

romanize:
    "한" -> "han"
    "글" -> "gul", "geul"

#부터는 주석이다. 해석되지 않는다:

test:
    # 가장 단순한 테스트케이스
    "gloria" -> "글로리아"

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

View Source
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
)
View Source
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 HGL

type HGL map[string]Section

HGL is a decoding result of an HGL code.

func Parse

func Parse(r io.Reader) (HGL, error)

Parse parses an HGL formatted text.

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

func (p Pair) Left() string

Left is a string. It is used for as keys in dict:

english = "Italian"
^^^^^^^

Or as left of pair:

aa -> "ㅏ", "ㅐ"
^^

func (Pair) Line

func (l Pair) Line() int

Line returns the line number where the node is defined.

func (Pair) Right

func (p Pair) Right() []string

Right is a string array. It is used for as values in dict:

 english = "Italian"
	          ^^^^^^^^^

Or as right of pair:

aa -> "ㅏ", "ㅐ"
      ^^^^^^^^^^

func (Pair) String

func (p Pair) String() string

type Section

type Section interface {
	Liner
	Pairs() []Pair
	// contains filtered or unexported methods
}

Section contains pairs.

Jump to

Keyboard shortcuts

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