Skip to content

Commit

Permalink
Why no colour?? [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
skaller committed Nov 1, 2017
1 parent 4adcf8e commit d11257b
Show file tree
Hide file tree
Showing 2 changed files with 211 additions and 53 deletions.
106 changes: 53 additions & 53 deletions doc/packages/rtl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,60 +9,60 @@ Bootstrap builder.
==================


.. code-block:: python
.. code-block:: python3
import fbuild
from fbuild.functools import call
from fbuild.path import Path
from fbuild.record import Record
from fbuild.builders.file import copy
import buildsystem
from buildsystem.config import config_call
# ------------------------------------------------------------------------------
def build_runtime(phase):
path = Path(phase.ctx.buildroot/'share'/'src', 'rtl')
print("[fbuild] [rtl] MAKING RTL ******* ")
srcs = [f for f in Path.glob(path / '*.cpp')]
includes = [
phase.ctx.buildroot / 'host/lib/rtl',
phase.ctx.buildroot / 'share/lib/rtl'
]
macros = ['BUILD_RTL']
libs = [
call('buildsystem.flx_strutil.build_runtime', phase),
call('buildsystem.flx_dynlink.build_runtime', phase),
call('buildsystem.flx_async.build_runtime', phase),
call('buildsystem.flx_exceptions.build_runtime', phase),
call('buildsystem.flx_gc.build_runtime', phase),
]
dlfcn_h = config_call('fbuild.config.c.posix.dlfcn_h',
phase.platform,
phase.cxx.static,
phase.cxx.shared)
if dlfcn_h.dlopen:
external_libs = dlfcn_h.external_libs
else:
external_libs = []
dst = 'host/lib/rtl/flx'
return Record(
static=buildsystem.build_cxx_static_lib(phase, dst, srcs,
includes=includes,
macros=macros,
libs=[lib.static for lib in libs],
external_libs=external_libs),
shared=buildsystem.build_cxx_shared_lib(phase, dst, srcs,
includes=includes,
macros=macros,
libs=[lib.shared for lib in libs],
external_libs=external_libs))
import fbuild
from fbuild.functools import call
from fbuild.path import Path
from fbuild.record import Record
from fbuild.builders.file import copy
import buildsystem
from buildsystem.config import config_call
# ------------------------------------------------------------------------------
def build_runtime(phase):
path = Path(phase.ctx.buildroot/'share'/'src', 'rtl')
print("[fbuild] [rtl] MAKING RTL ******* ")
srcs = [f for f in Path.glob(path / '*.cpp')]
includes = [
phase.ctx.buildroot / 'host/lib/rtl',
phase.ctx.buildroot / 'share/lib/rtl'
]
macros = ['BUILD_RTL']
libs = [
call('buildsystem.flx_strutil.build_runtime', phase),
call('buildsystem.flx_dynlink.build_runtime', phase),
call('buildsystem.flx_async.build_runtime', phase),
call('buildsystem.flx_exceptions.build_runtime', phase),
call('buildsystem.flx_gc.build_runtime', phase),
]
dlfcn_h = config_call('fbuild.config.c.posix.dlfcn_h',
phase.platform,
phase.cxx.static,
phase.cxx.shared)
if dlfcn_h.dlopen:
external_libs = dlfcn_h.external_libs
else:
external_libs = []
dst = 'host/lib/rtl/flx'
return Record(
static=buildsystem.build_cxx_static_lib(phase, dst, srcs,
includes=includes,
macros=macros,
libs=[lib.static for lib in libs],
external_libs=external_libs),
shared=buildsystem.build_cxx_shared_lib(phase, dst, srcs,
includes=includes,
macros=macros,
libs=[lib.shared for lib in libs],
external_libs=external_libs))
@
Expand Down
158 changes: 158 additions & 0 deletions src/packages/flx_doc.fdoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@tangler flx_libcontents.flx = $PWD/src/tools/flx_libcontents.flx
@tangler flx_libindex.flx = $PWD/src/tools/flx_libindex.flx
@tangler flx_mktutindex.flx = $PWD/src/tools/flx_mktutindex.flx
@tangler flx_fdoc2sphinx.flx = $PWD/src/tools/flx_fdoc2sphinx.flx

@h1 Documentation tools for Felix.
These tools are designed to extract and build
Expand Down Expand Up @@ -402,3 +403,160 @@ done
@


@tangle fdoc2sphinx.flx
open Regdef;

// command translation
regdef cmd_name_r = perl("[A-Za-z_][A-Za-z_0-9]*");
regdef spc_r = " " *;
regdef any_r = perl(".*");
regdef cmd_r = "@" group(cmd_name_r) spc_r group(any_r);
var cmd_s = render cmd_r;
var cmd_R = RE2 cmd_s;


typedef markup_t = (`Txt | `At | `Code);
fun code_markup (a:string): string =
{
var out = "";
var mode = (#`Txt) :>> markup_t;
for ch in a do
match mode with
| `Txt =>
if ch == char "@" do
mode = (#`At) :>> markup_t;
else
out += ch;
done

| `At =>
if ch == char "{" do
out += " :code:`";
mode = (#`Code) :>> markup_t;
else
out += "@"+ch;
done

| `Code =>
if ch == char "}" do
out += "`";
mode = (#`Txt) :>> markup_t;
else
out += ch;
done
endmatch;
done
return out;
}

fun lexer_from_filename (var s:string) : string =
{
s = strip s;
var lexer =
match s.Filename::get_extension with
| (".cpp" | ".cxx" | ".hpp") => "cpp"
| (".flx" | ".fdoc") => "felix"
| (".c" | ".h") => "c"
| (".py") => "python"
| _ => "text"
endmatch
;
return lexer;
}


typedef mode_t = (`Doc | `Code);

fun process_file (f: string): string =
{
var out = "";
proc println[T with Str[T]] (x:T) => out += x.str + "\n";
var mode : mode_t = (#`Doc) :>> mode_t;
for line in split (f, char "\n") do
var cmd = Match (cmd_R, line);
match cmd with
| Some grp =>
var c = grp.1;
var a = grp.2;
if c == "title" do
println$ "";
match mode with
| `Code () => mode = (#`Doc) :>> mode_t;
| _ => ;
endmatch;
a = code_markup a;
println$ "=" * a.len.int;
println$ a;
println$ "=" * a.len.int;
println$ "";

elif c == "h1" do
println$ "";
match mode with
| `Code () => mode = (#`Doc) :>> mode_t;
| _ => ;
endmatch;
a = code_markup a;
println$ a;
println$ "=" * a.len.int;
println$ "";

elif c == "h2" do
a = code_markup a;
println$ "";
match mode with
| `Code => mode = (#`Doc) :>> mode_t;
| _ => ;
endmatch;
println$ a;
println$ "-" * a.len.int;
println$ "";

elif c == "tangle" do
println$ "";
println$ ".. code-block:: "+lexer_from_filename a;
println$ "";
mode = (#`Code) :>> mode_t;
else
match mode with
| `Code =>
println$ "";
mode = (#`Doc) :>> mode_t;
| _ => ;
endmatch;
done


| None =>
match mode with
| `Doc =>
println$ code_markup line;
| `Code => println$ " " + line;
endmatch;
endmatch;
done
return out;
}


include "std/felix/flx_cp";

var dir = "src/packages";
var regex = "(.*).fdoc";
var target = "doc/packages/${1}.rst";
var live = true;
var verbose = true;

gen sandr (src: string, dst:string) =
{
var text = load src;
var result = process_file (text);
save (dst, result);
return true;
}

var filere = Re2::RE2 regex;
CopyFiles::processfiles sandr (dir, filere, target, live, verbose);
System::exit(0);
@

0 comments on commit d11257b

Please sign in to comment.