Skip to content

Commit 1d0446a

Browse files
committed
add tasks
1 parent 1ce5624 commit 1d0446a

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

‎parser/index.pegjs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// final parsed output for coderoad.json file
33
var position = {
44
page: -1,
5+
task: -1,
56
};
67
var output = {
78
info: {
@@ -23,21 +24,23 @@ start
2324
doc
2425
= info_title
2526
info_description*
26-
optionalBreak
27+
break?
2728
page*
2829

2930
page
3031
= page_title
3132
page_description*
33+
page_task*
3234

3335
page_title
3436
= '##'
35-
optionalSpace
37+
space?
3638
title: content
37-
EOL
39+
break
3840
{
3941
// increment page
4042
position.page += 1;
43+
position.task = -1;
4144
// add page outline
4245
output.pages.push({
4346
title: 'Page ' + position.page,
@@ -49,37 +52,48 @@ page_title
4952

5053
page_description
5154
= description: content
52-
EOL
55+
break
5356
{
5457
const d = output.pages[position.page].description;
5558
output.pages[position.page].description += d.length > 0 ? '\n' : '';
5659
output.pages[position.page].description += adjust(description);
5760
}
5861

62+
page_task
63+
= '+'
64+
space?
65+
description: content
66+
break
67+
{
68+
position.task += 1;
69+
if (!output.pages[position.page].tasks) {
70+
output.pages[position.page].tasks = [{
71+
description: adjust(description)
72+
}]
73+
}
74+
}
75+
5976
info_title
6077
= '#'
61-
optionalSpace
78+
space?
6279
title: content
6380
{ output.info.title = adjust(title); }
6481

6582
info_description
6683
= description: content
67-
EOL
84+
break
6885
{
6986
const d = output.info.description;
7087
output.info.description += d.length > 0 ? '\n' : '';
7188
output.info.description += adjust(description);
7289
}
7390

74-
content = [^#] [^\n^\r]+ [\n\r]
91+
content = [^#^@^+] [^\n^\r]+ [\n\r]
7592
space = [ \s]
76-
EOL = [\n\r]?
93+
break = [\n\r]?
7794
file_path = [a-z_\-\s0-9\.]+
7895
quote = [\"\'\`]
7996

80-
optionalBreak = EOL?
81-
optionalSpace = space?
82-
8397
{
8498
// notes
8599
// - break if line starts with #

0 commit comments

Comments
 (0)