-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgrammar.pegjs
65 lines (49 loc) · 1.09 KB
/
grammar.pegjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// v 0.0.2
start = Qurio
Qurio =
NL* q:Question+ {return {questions:q}}
Question =
type:QuestionType? t:QuestionTitle a:Answer+ NL* {
question = {title: t, answers: a}
if (type) {
question.type = type;
}
else {
question.type = 'multiplechoice';
}
return question
}
QuestionType 'question type' =
WS* '[' type:QUESTION_TYPES ']' WS* NL {return type;}
QUESTION_TYPES =
'multiplechoice'
/ 'checkbox'
QuestionTitle 'a question' =
WS* NL? title:$(!Bullet .)+ {return title.replace(/\n/g, '<br>');}
Answer 'an answer' = WS* Bullet l1:Line l2:IndentedBlock? o:Option? {
data = {
title: (l1 + l2).replace(/\n/g, '<br>')
}
if (o) {
data[o] = true;
}
return data
}
IndentedBlock =
lines:(!Bullet !Option NL+ Indent Line)* {
data = '';
for (i = 0; i < lines.length; i++) {
data += '\n' + lines[i][4];
}
return data;
}
Line =
l:$(!NL !Option .)+ {return l;}
Option =
WS* '[correct]' {return 'correct'}
Bullet = NL+ WS* '-' WS+
Indent = '\t' / WS WS+
WS = ' ' / '\t'
NL =
'\n'
/ '\r' '\n'?