Skip to content

Commit 5617122

Browse files
committed
init
0 parents  commit 5617122

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

‎package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "coderoad-parser",
3+
"version": "0.1.0",
4+
"description": "",
5+
"keywords": [],
6+
"license": "ISC",
7+
"author": "Shawn McKay <shawn.j.mckay@gmail.com>",
8+
"main": "parser/index.pegjs",
9+
"scripts": {
10+
"test": "ava"
11+
},
12+
"dependencies": {
13+
"pegjs": "^0.9.0"
14+
},
15+
"devDependencies": {
16+
"ava": "^0.16.0"
17+
}
18+
}

‎parser/index.pegjs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
var output = {
3+
info: {
4+
5+
},
6+
pages: []
7+
}
8+
}
9+
10+
start
11+
= doc
12+
{ return output; }
13+
14+
doc
15+
= info
16+
17+
page
18+
= title: page_title
19+
description: description
20+
{
21+
// set page
22+
output.pages.push({
23+
title: title,
24+
description: description
25+
});
26+
}
27+
28+
page_title
29+
= '##'
30+
space
31+
title: content
32+
{ return title.join(''); }
33+
34+
info
35+
= title: info_title
36+
end
37+
description: description
38+
end
39+
{
40+
// set info
41+
output.info.title = title;
42+
output.info.description = description;
43+
}
44+
45+
info_title
46+
= '#'
47+
space
48+
title: content
49+
end
50+
{ return title.join(''); }
51+
52+
description
53+
= description: content
54+
{ return description.join(''); }
55+
56+
content = .+
57+
space = [ ]?
58+
end = [\n]
59+
60+
// @import
61+
62+
// page
63+
// page_title
64+
// page_description
65+
// page_test
66+
// page_action
67+
// page_hint
68+
// page_on_complete
69+
70+
// @action_insert
71+
// @action_set
72+
// @action_write
73+
// @action_write_from_file
74+
// @action_open
75+
// @action_cursor_position

‎test/titles.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import test from 'ava';
2+
import pegjs from 'pegjs';
3+
import { readFileSync } from 'fs';
4+
5+
const parser = readFileSync('../parser/index.pegjs', 'utf8');
6+
const parse = pegjs.buildParser(parser).parse;
7+
8+
test('parses a title', t => {
9+
const data = `# Title
10+
some description
11+
`;
12+
const expected = {
13+
info: {
14+
title: 'Title',
15+
description: 'some description'
16+
}
17+
};
18+
const result = parse(data);
19+
t.deepEqual(result.info, expected.info);
20+
});

0 commit comments

Comments
 (0)