입출력 형식
파스 트리
PEG.js가 만든 파서의 출력이다.
최상단
{
input: string,
root: {
type: 'root',
children: (element | verbatim | text)[],
location: location
}
}
input
: 입력된 yamd 코드.
element
{
type: 'element',
lbm: string,
name: string,
attributes: attribute[],
children: (element | verbatim | text)[],
rbm: string,
location: location
}
lbm
: 왼쪽 경계.name
: 태그 이름.rbm
: 오른쪽 경계.
attribute
다음의 둘 중 하나이다.
{ _type: 'attribute', attribute: [a, b, c, d, e] }
a
,b
,c
,d
,e
는foo="bar"
의 경우 다음과 같이 된다.foo
=
"
bar
"
a
b
c
d
e
foo=bar
의 경우 다음과 같이 된다.foo
=
bar
a
b
c
d
e
{ _type: 'whitespace', whitespace: string }
whitespace
: 공백 문자열.
verbatim
{
type: 'verbatim',
lvm: string,
separator: string,
child: text,
rvm: string,
location: location
}
`<.<script>>`
의 경우 lvm
, separator
, child
, rvm
이 다음과 같이 된다.
| | | |
| | | |
`asdf`
의 경우 다음과 같이 된다.
| | | |
| | | |
이때 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
파스 트리에서 verbatim
이 text
로 통합되고 몇 가지 토큰이 사라진다.
최상단
{
input: string,
root: {
type: 'root',
children: (element | text)[],
code: string
}
}
input
: 입력된 yamd 코드.code
: 전체 코드.input
과 같다.
element
{
type: 'element',
name: string,
attributes: Array<{
name: string,
value: string
}>,
code: string,
children: (element | text)[]
}
name
: 태그 이름.code
: 요소의 코드. 왼쪽 및 오른쪽 경계를 포함한다.
text
{
type: 'text',
text: string
}