-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.peg
More file actions
31 lines (21 loc) · 1.01 KB
/
Copy pathparser.peg
File metadata and controls
31 lines (21 loc) · 1.01 KB
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 = (Comment / b:Block { return b; })*
Block = Comment / (__ doc:(Comment / Doc) __ route:(Comment / Route)) { return {doc: doc, route: route }}
Doc = begin:DocBlockBegin doc:(a:(!DocBlockEnd b:. { return b[0]; })* { return a.join(''); }) end:DocBlockEnd { return doc.trim() }
DocBlockBegin = '/**'
DocBlockEnd = '*/' __?
Route = !CommentDelimeter method:(Methods)? __ path:Path __ { return {method: method, path: path}; }
Methods = 'GET' / 'POST' / 'PUT' / 'DELETE' / 'OPTIONS' / 'HEAD'
Path = d:PathDelimeter p:([^\n]*) { return d + p.join(''); }
// alternate version to parse out path params
/*
Path = &PathDelimeter p:PathParts PathDelimeter? '\n' { return p; }
PathParts = part:(PathDelimeter p:(PathPart / Param) { return p; } )*
Char = [a-zA-Z]
PathPart = p:(Char+) { return {type: 'path', value: p.join('')}; }
Param = ':' p:(Char+) { return {type: 'param', value: p.join('')} ; }
*/
PathDelimeter = '/'
Comment = CommentDelimeter [^\n]* '\n' { return null; }
CommentDelimeter = '//'
// whitespace
__ = [ \t\n\r]*