-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathpeg.js
More file actions
47 lines (37 loc) · 1.36 KB
/
peg.js
File metadata and controls
47 lines (37 loc) · 1.36 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Start
= _ q: Query _ {
var re = new RegExp(q, "g");
//var input = processingSanad.toString();
var input = [1, 5917, 2].toString(); return "{" + re + "}.'" + input + "' => " + re.test(input);
return re.test(input);
}
Query
= _ head: Expression _ tail: (TailQuery) * _{ return "(?=.*" + head + ")" + tail; }
// NOT "!(" neg:Query ")"{ return "("+neg+")";}
TailQuery
= _ op: ("|") _ tail: Expression _ { return "|" + tail; }
/ _ op:("&") _ tail: Expression _ {return "(?=.*"+tail+")";}
// XOR
Expression
= _ ex: (Isnad / Factor) _ { return ex; }
Factor
= _ "(" _ q: Query _ ")" _ { return "(" + q + ")"; }
Isnad
= _ "$" _ list: Rawi + _ "$" _ { return "(^)" + list.join() + "($)"; }
/ _ "$" _ list:Rawi+ _ {return "(^)"+list.join()+"(,|$)";}
/ _ list: (Rawi +) _ "$" _ { return "(^|,)" + list.join() + "($)"; }
/ _ list:Rawi+ _{return "(^|,)"+list.join()+"(,|$)"}
Rawi
= _ head: "@" id: Integer _ tail: (ORRawi) * _ { return id + tail; }
/ _ "(" _ r:Rawi+ _ ")" _ tail:(ORRawi)* _ { return "("+r.join()+")" + tail; }
/ _ "*" _ tail: (ORRawi) * _ { return "[0-9]+" + tail; }
// Quantifier
Quantifier
= "<" n: Integer ">" r: Isnad { return "(" + r + "){" + n + "}"; }
ORRawi
= _ op: "|" _ tail: Rawi _{ return "|" + tail; }
Integer "integer"
= _[0 - 9] +
{ return text(); }
_ "whitespace"
= [\t\n\r] *