Skip to content

Commit 5c6773e

Browse files
committed
Add regex doc
1 parent 2ca974a commit 5c6773e

File tree

12 files changed

+438
-3
lines changed

12 files changed

+438
-3
lines changed

GNUmakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pretty:
33
env DYLD_LIBRARY_PATH=${LD_LIBRARY_PATH} flx_pretty --outdir=web embedc.fdoc
44
env DYLD_LIBRARY_PATH=${LD_LIBRARY_PATH} flx_pretty --outdir=web corout.fdoc
55
env DYLD_LIBRARY_PATH=${LD_LIBRARY_PATH} flx_pretty --outdir=web views.fdoc
6+
env DYLD_LIBRARY_PATH=${LD_LIBRARY_PATH} flx_pretty --outdir=web regex.fdoc
67
env DYLD_LIBRARY_PATH=${LD_LIBRARY_PATH} flx_pretty --outdir=web ../felix/src/packages/lists.fdoc
78

89
tut:
@@ -24,6 +25,7 @@ extract:
2425
flx_iscr embedc.fdoc
2526
flx_iscr corout.fdoc
2627
flx_iscr openrecursion.fdoc
28+
flx_iscr regex.fdoc
2729

2830

2931
test:

examples/corout/ex1.flx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#line 18 "corout.fdoc"
2+
proc source (out: %>int) () {
3+
var i = 0;
4+
while true do
5+
write (out,i);
6+
++i;
7+
done
8+
}
9+
#line 30 "corout.fdoc"
10+
proc sink (inp: %<int) () {
11+
while true do
12+
var i = read inp;
13+
println$ i;
14+
done
15+
}
16+
#line 47 "corout.fdoc"
17+
proc squarer (inp: %<int, out: %>int) () {
18+
while true do
19+
var i = read inp;
20+
write (out, i * i);
21+
done
22+
}
23+
#line 59 "corout.fdoc"
24+
proc limiter (var limit: int) (inp: %<int, out: %>int) () {
25+
while limit > 0 do
26+
var i = read inp;
27+
write (out, i);
28+
--limit;
29+
done
30+
}
31+
#line 74 "corout.fdoc"
32+
proc run_pipeline() {
33+
// make channels
34+
var i1,o1 = mk_ioschannel_pair[int]();
35+
var i2,o2 = mk_ioschannel_pair[int]();
36+
var i3,o3 = mk_ioschannel_pair[int]();
37+
38+
// make coroutines by binding the channels
39+
var d1 = source(o1);
40+
var d2 = squarer(i1,o2);
41+
var d3 = limiter 8 (i2,o3);
42+
var d4 = sink (i3);
43+
44+
// spawn coroutines as fibres
45+
spawn_fthread d1;
46+
spawn_fthread d2;
47+
spawn_fthread d3;
48+
spawn_fthread d4;
49+
50+
// exit
51+
}
52+
run_pipeline();

examples/corout/ex2.flx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#line 108 "corout.fdoc"
2+
chip source
3+
connector io
4+
pin out: %>int
5+
{
6+
var i = 0;
7+
while true do
8+
write (io.out,i);
9+
++i;
10+
done
11+
}
12+
#line 126 "corout.fdoc"
13+
chip sink
14+
connector io
15+
pin inp: %<int
16+
{
17+
while true do
18+
var i = read io.inp;
19+
println$ i;
20+
done
21+
}
22+
#line 138 "corout.fdoc"
23+
chip squarer
24+
connector io
25+
pin inp: %<int
26+
pin out: %>int
27+
{
28+
while true do
29+
var i = read io.inp;
30+
write (io.out, i * i);
31+
done
32+
}
33+
chip limiter (var limit: int)
34+
connector io
35+
pin inp: %<int
36+
pin out: %>int
37+
{
38+
while limit > 0 do
39+
var i = read io.inp;
40+
write (io.out, i);
41+
--limit;
42+
done
43+
};
44+
#line 162 "corout.fdoc"
45+
proc run_pipeline1() {
46+
device limit8 = limiter 8;
47+
circuit
48+
connect source.out, squarer.inp
49+
connect squarer.out, limit8.inp
50+
connect limit8.out, sink.inp
51+
endcircuit
52+
}
53+
run_pipeline1();
54+
#line 183 "corout.fdoc"
55+
proc run_pipeline2() {
56+
(source |-> squarer |-> limiter 8 |-> sink)();
57+
}
58+
run_pipeline2();

examples/corout/ex3.flx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#line 231 "corout.fdoc"
2+
println$ "Begin Spawning";
3+
4+
spawn_fthread {
5+
println "Start1"; sleep (2.0); println$ "End1";
6+
};
7+
8+
spawn_fthread {
9+
println "Start2"; sleep (1.0); println$ "End2";
10+
};
11+
12+
sleep (0.25);
13+
println$ "Mainline terminates";

examples/corout/ex5.flx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#line 375 "corout.fdoc"
2+
chip D connector io pin inp: %<int pin out: %>int
3+
{
4+
while true do
5+
var x = read io.inp;
6+
write (io.out, x);
7+
done
8+
}
9+
device A = D;
10+
device B = D;
11+
circuit
12+
connect A.out, B.inp
13+
connect B.out, A.inp
14+
endcircuit
15+
println$ "Done";

examples/corout/ex6.flx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#line 403 "corout.fdoc"
2+
var inp,out = mk_ioschannel_pair[int]();
3+
spawn_fthread { write (out, 42); };

examples/embedc/ex1.flx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#line 14 "embedc.fdoc"
2+
type cplx = "::std::complex<double>"
3+
requires header '#include <complex>'
4+
;
5+
ctor cplx : double * double =
6+
"::std::complex<double>($1,$2)"
7+
;
8+
fun + : cplx * cplx -> cplx = "$1+$2";
9+
fun - : cplx * cplx -> cplx = "$1-$2";
10+
fun * : cplx * cplx -> cplx = "$1*$2";
11+
fun / : cplx * cplx -> cplx = "$1/$2";
12+
fun == : cplx * cplx -> bool = "$1==$2";
13+
fun real: cplx -> double = "$1.real()";
14+
fun imag: cplx -> double = "$1.imag()";
15+
fun abs: cplx -> double = "$1.abs()";
16+
fun arg: cplx -> double = "$1.arg()";
17+
fun norm: cplx -> double = "$1.norm()";
18+
fun conj: cplx -> double = "$1.conj()";
19+
20+
typedef polarbear = cplx;
21+
ctor polarbear: double * double = "::std::polar<double>($1,$2)";
22+
23+
fun str (x: cplx) => x.real.str + "+" + x.imag.str + "i";
24+
25+
// test
26+
var x = cplx (1.0,2.0);
27+
var y = polarbear (1.0,0.5);
28+
println$ (x+y).str;
29+
println$ (x == y).str;
30+
#line 46 "embedc.fdoc"
31+
println$ (x,y);
32+
#line 61 "embedc.fdoc"
33+
instance Str[cplx] {
34+
fun str (x: cplx) => x.real.str + "+" + x.imag.str + "i";
35+
}

examples/openrecursion/openrec.flx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,4 @@ var ydm = evald xm; // ORGINAL DATA
9393
println$ "yd="+ydd.str;
9494
println$ "ya="+yda.str;
9595
println$ "ys="+yds.str;
96-
println$ "yn="+ydm.str;
96+
println$ "ym="+ydm.str;

examples/regex/re1.flx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#line 11 "regex.fdoc"
2+
regdef digit = charset "01234356789";
3+
regdef lower = charset "abcdefghijklmnopqrstuvwxyz";
4+
regdef upper = charset "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
5+
regdef letter = lower | upper;
6+
regdef underscore = "-";
7+
8+
// C identifier
9+
regdef cidlead = underscore | letter;
10+
regdef cidtrail = underscore | letter | digit;
11+
regdef cid = cidlead cidtrail*;
12+
#line 37 "regex.fdoc"
13+
// C int
14+
regdef cint = digit+;
15+
16+
// C decimal fixed point float
17+
regdef ffixed = digit* "." digit+ | digit+ "." digit*;
18+
19+
// Scifloat
20+
regdef expon = ("E" | "e") ("+"|"-")? digit+;
21+
regdef sci = (cint | ffixed) expon;
22+
23+
regdef ffloat = ffixed | sci;
24+
#line 64 "regex.fdoc"
25+
var float_s : string = ffloat.Regdef::render; // convert regex to string
26+
var float_r : RE2 = float_s.RE2; // compile string to RE2 regex
27+
println$ "123.4e-7" in float_r; // if it is a float?
28+
println$ float_r;
29+
#line 94 "regex.fdoc"
30+
regdef assignment = " "* group(cid) " "* "=" " "* (group(cint) | group(ffloat)) " "* ";";
31+
var a_s = assignment.Regdef::render;
32+
var a_r = a_s.RE2;
33+
var result = Match (a_r, "x = 123.45;");
34+
match result with
35+
| None => println$ "No match";
36+
| Some v =>
37+
print$ "Variable is " + v.1; // group 1
38+
if v.2 == "" do // if group 2 didn't match
39+
println$ " Initialiser is float " + v.3; // group 3 matched
40+
else
41+
println$ " Initialiser is int " + v.2; // group 2 matched
42+
done
43+
endmatch;
44+
#line 128 "regex.fdoc"
45+
var anys = ".*";
46+
regdef anystring = perl(anys);
47+
#line 133 "regex.fdoc"
48+
var prefix_assignment = a_s + anys;

index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ <h2>The Standard Library</h2>
5555

5656
<h2>New Articles</h2>
5757
<ol>
58-
<li><a href=web/embedc.html>Embedding C/C++</a>
58+
<li><a href=web/regex.html>Regular Definitions</a>
59+
<li><a href=web/openrecursion.html>Open Recursion</a>
60+
<li><a href=web/views.html>Views</a>
5961
<li><a href=web/corout.html>Coroutine Magic</a>
6062
</ol>
6163
jklhgsdjkhgjsdf

0 commit comments

Comments
 (0)