forked from pstodulka/swift-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mtGrammar.pegjs
32 lines (23 loc) · 1.03 KB
/
mtGrammar.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
start = eol fields:(complexField/simpleField)* {return fields}
simpleField = header:fieldHeader fieldText:content {
return {
type: header.type,
option: header.option,
fieldValue: fieldText,
content: header.text+fieldText
};
}
complexField = header:fieldHeader ":" qualifier:$(!"/" .)+ "//" fieldText:content {
var fieldValue = ":"+qualifier+"//"+fieldText;
return {
type: header.type,
option: header.option,
fieldValue: fieldValue,
content: header.text+fieldValue
};
}
fieldHeader = ":" type:$(digit digit) option:letter ":" {return {type: type, option: option, text: text()}}
content = text:$(!((eol ":")/(eol "-")) .)* ((eol &":")/(eol "-")) {return text}
eol = "\r\n"
digit = [0-9]
letter = [a-zA-Z]