yamd 설명서
  1. 시작하기
  2. API

입출력 형식

파스 트리

PEG.js가 만든 파서의 출력이다.

최상단

{
	input: string,
	root: {
		type: 'root',
		children: (element | verbatim | text)[],
		location: location
	}
}

element

{
	type: 'element',
	lbm: string,
	name: string,
	attributes: attribute[],
	children: (element | verbatim | text)[],
	rbm: string,
	location: location
}

attribute

다음의 둘 중 하나이다.

verbatim

{
	type: 'verbatim',
	lvm: string,
	separator: string,
	child: text,
	rvm: string,
	location: location
}

`<.<script>>`의 경우 lvm, separator, child, rvm이 다음과 같이 된다.

`<

.

<script>

>`

lvm

separator

child

rvm

`asdf`의 경우 다음과 같이 된다.

`

asdf

`

lvm

separator

child

rvm

이때 child는 문자열이 아니며 아래에 있는 text 객체이다.

text

{
	type: 'text',
	text: string,
	location: location
}

location

{
	start: { offset: start-offset, line: start-line, column: start-column },
	end: { offset: end-offset, line: end-line, column: end-column }
}

어떤 토큰의 시작 및 끝의 오프셋, 줄 번호, 열을 나타낸다. PEG.js의 location()을 호출한 것이다.

AST

파스 트리에서 verbatimtext로 통합되고 몇 가지 토큰이 사라진다.

최상단

{
	input: string,
	root: {
		type: 'root',
		children: (element | text)[],
		code: string
	}
}

element

{
	type: 'element',
	name: string,
	attributes: Array<{
		name: string,
		value: string
	}>,
	code: string,
	children: (element | text)[]
}

text

{
	type: 'text',
	text: string
}