-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtutorial.js
50 lines (45 loc) · 1.46 KB
/
tutorial.js
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
$(document).ready(function() {
// HACK: add global definitions used in some examples
globalThis.cat1=NP(D("the"),N("cat"));
globalThis.mouse1=NP(D("a"),A("grey"),N("mouse"));
globalThis.cat2=NP(D("the"),N("cat"));
globalThis.mouse2=NP(D("a"),A("grey"),N("mouse"));
globalThis.mouse3 = ()=> NP(D("a"),A("grey"),N("mouse"));
function np(){
return NP(D("a"),a(),N(oneOf("cat","mouse","dog","rabbit")).n(oneOf("s","p")));
}
function a(){
return oneOf(
()=>A(oneOf("hungry","grey","nervous")),
()=>Q("")
);
}
function vp (){
return oneOf(
()=>VP(V(oneOf("sit","run","laugh")).t(oneOf("p","ps","f"))), // intransitive verb
()=>VP(V(oneOf("eat","love")).t(oneOf("p","ps","f")), // transitive verb
np())
);
}
$(".js").each(function(){
var codeId=$(this).attr("code-id")
if (codeId !==undefined){
$(this).text(eval($(codeId).text()));
return
}
// only evaluate code
eval($(this).text());
});
$(".jsh").each(function(){
var codeId=$(this).attr("code-id")
if (codeId !==undefined){
$(this).html(eval($(codeId).text()).toString());
return
}
// only evaluate code
eval($(this).text());
});
$("#newSent").click(function(){
$("#genSent").html(""+S(np(),vp()));
});
});