Commit 2f0d1a86 authored by Vivien Kraus's avatar Vivien Kraus
Browse files

Cleaner org exporter for the manual

parent 45a26e14
......@@ -40,6 +40,7 @@ dist_tarotsysconf_DATA =
dist_pkgdata_DATA = COPYING
dist_html_DATA =
INDENTED =
TANGLED =
SUFFIXES =
dist_noinst_SCRIPTS = \
autogen.sh \
......@@ -94,6 +95,8 @@ include doc/Makefile.am
include src/Makefile.am
include games/Makefile.am
EXTRA_DIST += $(TANGLED)
TESTS += $(check_PROGRAMS)
indent_verbose = $(indent_verbose_@AM_V@)
indent_verbose_ = $(indent_verbose_@AM_DEFAULT_V@)
......
......@@ -33,24 +33,18 @@ dist_html_DATA += \
install-html-local: install-dist_htmlDATA
%reldir%/tarot-full.html %reldir%/tarot.texi \
src/scm/tarot/utf8-everywhere.scm $(SCM_TESTS) \
src/scm/tarot.scm \
src/tarot-learn \
src/tarot-self-train.in: \
%reldir%/tarot.org \
%reldir%/setup.el \
.version
TANGLED += %reldir%/generate-manual
$(TANGLED): %reldir%/tarot.org %reldir%/setup.el .version
$(MAKE) $(AM_MAKEFLAGS) src/libtarot.la src/features/tarot-header.arff
$(AM_V_GEN) (cd $(srcdir)/%reldir% \
&& LIBTAROT_VERSION="$(VERSION)" \
LD_LIBRARY_PATH="$(abs_top_builddir)/src/.libs:$LD_LIBRARY_PATH" \
$(EMACS) --batch \
-l setup.el \
--file tarot.org \
-f org-babel-tangle)
%reldir%/tarot-full.html %reldir%/tarot.texi: $(TANGLED)
$(MAKE) $(AM_MAKEFLAGS) src/libtarot.la src/features/tarot-header.arff
$(AM_V_GEN) (cd $(srcdir)/%reldir% && \
cp tarot.org tarot-full.org && \
LIBTAROT_VERSION="$(VERSION)" \
$(EMACS) --batch \
-l setup.el \
--file tarot-full.org \
-f org-babel-tangle \
-f org-babel-tangle \
-f org-texinfo-export-to-texinfo \
-f org-html-export-to-html && \
mv tarot-full.texi tarot.texi && \
rm tarot-full.org)
$(AM_V_GEN) $(srcdir)/%reldir%/generate-manual
......@@ -1011,10 +1011,7 @@ So let us check that this function works.
#+END_SRC
#+BEGIN_SRC shell :results output
guile \
-L ../src/scm \
-C ../src/scm \
../src/scm/tarot/check/example-generate-model-parser.scm || exit 1
guile ../src/scm/tarot/check/example-generate-model-parser.scm || exit 1
#+END_SRC
*** The model API
......@@ -1166,12 +1163,7 @@ Let us check that we can set the weights for the number of players
#+END_SRC
#+BEGIN_SRC shell :results output
export LD_LIBRARY_PATH="../src/.libs:$LD_LIBRARY_PATH"
../libtool --mode=execute guile \
-L ../src/scm \
-C ../src/scm \
../src/scm/tarot/check/example-generate-model-api.scm || exit 1
guile ../src/scm/tarot/check/example-generate-model-api.scm || exit 1
#+END_SRC
*** The generator API
......@@ -1476,12 +1468,7 @@ empty model.
#+END_SRC
#+BEGIN_SRC shell :results output
export LD_LIBRARY_PATH="../src/.libs:$LD_LIBRARY_PATH"
../libtool --mode=execute guile \
-L ../src/scm \
-C ../src/scm \
../src/scm/tarot/check/example-generate-generator-api.scm || exit 1
guile ../src/scm/tarot/check/example-generate-generator-api.scm || exit 1
#+END_SRC
*** Serialization API
......@@ -1934,12 +1921,7 @@ should stop early since everyone passes.
#+END_SRC
#+BEGIN_SRC shell :results output
export LD_LIBRARY_PATH="../src/.libs:$LD_LIBRARY_PATH"
../libtool --mode=execute guile \
-L ../src/scm \
-C ../src/scm \
../src/scm/tarot/check/example-generate-serialization-api.scm || exit 1
guile ../src/scm/tarot/check/example-generate-serialization-api.scm || exit 1
#+END_SRC
*** XML file format for tarot
......@@ -2026,15 +2008,8 @@ to the SXML syntax.
Here is what the previously generated game looks like.
#+BEGIN_SRC scheme :noweb no-export :tangle ../src/scm/tarot/check/example-generate-sxml-api.scm :mkdirp t :tangle-mode (identity #o755) :eval no
<<guile-prologue>>
(define-module (tarot check example-generate-sxml-api)
#:use-module (oop goops)
#:use-module (rnrs bytevectors)
#:use-module (system foreign)
#:use-module (ice-9 format)
#:use-module (ice-9 match)
#:use-module (tarot utf8-everywhere))
#+name: scm-code-for-example-generate-sxml-api
#+BEGIN_SRC scheme :noweb no-export :eval no
<<scm-define-tarot-model>>
<<scm-define-tarot-generator>>
<<scm-define-tarot-card>>
......@@ -2052,17 +2027,37 @@ Here is what the previously generated game looks like.
(define model (model-alloc))
(define generator (generator-alloc 5 #t model (u8e:lit "random seed")))
(define generated (generate generator))
(format #t "~y\n" (serialize-sxml generated))
(define serialization (serialize-sxml generated))
(format #t "~y\n" serialization)
#+END_SRC
#+BEGIN_SRC scheme :noweb no-export :tangle ../src/scm/tarot/check/example-generate-sxml-api.scm :mkdirp t :tangle-mode (identity #o755) :eval no
<<guile-prologue>>
(define-module (tarot check example-generate-sxml-api)
#:use-module (oop goops)
#:use-module (rnrs bytevectors)
#:use-module (system foreign)
#:use-module (ice-9 format)
#:use-module (ice-9 match)
#:use-module (tarot utf8-everywhere))
<<scm-code-for-example-generate-sxml-api>>
#+END_SRC
#+name: generate-sxml
#+BEGIN_SRC shell :results output
export LD_LIBRARY_PATH="../src/.libs:$LD_LIBRARY_PATH"
#+BEGIN_SRC sh :noweb yes :exports none :results output
guile -q <<"EOF" | tail -n +9 | head -n -3
(use-modules (oop goops)
(rnrs bytevectors)
(system foreign)
(ice-9 format)
(ice-9 match))
<<scm-utf8-everywhere>>
<<scm-code-for-example-generate-sxml-api>>
EOF
#+END_SRC
../libtool --mode=execute guile \
-L ../src/scm \
-C ../src/scm \
../src/scm/tarot/check/example-generate-sxml-api.scm || exit 1
#+BEGIN_SRC shell :results output
guile ../src/scm/tarot/check/example-generate-sxml-api.scm || exit 1
#+END_SRC
Now we can actually define what to do when we parse a
......@@ -2090,11 +2085,6 @@ game, serialize it to XML.
#+BEGIN_SRC shell :results output
echo "strategy_take = 1" > /tmp/empty
export LD_LIBRARY_PATH="../src/.libs:$LD_LIBRARY_PATH"
export GUILE_AUTO_COMPILE=1
export GUILE_LOAD_PATH="../src/scm:$GUILE_LOAD_PATH"
export GUILE_COMPILED_LOAD_PATH="../src/scm:$GUILE_COMPILED_LOAD_PATH"
../src/scm/tarot.scm \
generate \
-m /tmp/empty \
......@@ -2663,12 +2653,7 @@ a formal list, as you can see in table [[tbl-all-features]].
#+END_SRC
#+BEGIN_SRC shell :results output drawer
export LD_LIBRARY_PATH="../src/.libs:$LD_LIBRARY_PATH"
export GUILE_AUTO_COMPILE=1
export GUILE_LOAD_PATH="../src/scm:$GUILE_LOAD_PATH"
export GUILE_COMPILED_LOAD_PATH="../src/scm:$GUILE_COMPILED_LOAD_PATH"
../src/scm/tarot/check/example-features-list.scm || exit 1
guile ../src/scm/tarot/check/example-features-list.scm || exit 1
#+END_SRC
So we need to define the features array class, first.
......@@ -2958,12 +2943,8 @@ So this is about time to run the application.
When exporting the features of the previously generated game, we get:
#+BEGIN_SRC shell :results output
export LD_LIBRARY_PATH="../src/.libs:$LD_LIBRARY_PATH"
export GUILE_AUTO_COMPILE=1
export GUILE_LOAD_PATH="../src/scm:$GUILE_LOAD_PATH"
export GUILE_COMPILED_LOAD_PATH="../src/scm:$GUILE_COMPILED_LOAD_PATH"
export ARFF_HEADER="../src/features/tarot-header.arff"
export TAROT="../src/scm/tarot.scm"
export ARFF_HEADER="src/features/tarot-header.arff"
export TAROT="src/scm/tarot.scm"
export AI_MODEL="/tmp/empty.conf"
echo 'strategy_take = 1' > $AI_MODEL
......@@ -3616,7 +3597,7 @@ Finally, running the interactive application is trivial.
** UTF-8 everywhere
:PROPERTIES:
:header-args: :tangle ../src/scm/tarot/utf8-everywhere.scm :noweb no-export :eval no
:header-args: :noweb no-export :eval no
:END:
This is a collection of replacements of library functions in order to
support utf-8 in guile. We need them because Guile strings are
......@@ -3631,7 +3612,21 @@ function to convert a string literal.
So we define the =tarot utf8-everywhere= module:
#+name: scm-utf8-everywhere
#+BEGIN_SRC scheme
<<scm-u8e-lit>>
<<scm-u8e-open-input-string>>
<<scm-u8e-get-line>>
<<scm-u8e-string-length>>
<<scm-u8e-string-prefix>>
<<scm-u8e-locale-string-inexact>>
<<scm-u8e-string-contains>>
<<scm-u8e-substring>>
<<scm-u8e-string-join>>
<<scm-u8e-gettext>>
#+END_SRC
#+BEGIN_SRC scheme :tangle ../src/scm/tarot/utf8-everywhere.scm
<<guile-prologue>>
(define-module (tarot utf8-everywhere)
#:use-module (rnrs bytevectors)
......@@ -3646,22 +3641,26 @@ So we define the =tarot utf8-everywhere= module:
u8e:substring
u8e:string-join
u8e:gettext))
<<scm-utf8-everywhere>>
#+END_SRC
The =lit= function takes a string literal, and returns a byte vector.
#+name: scm-u8e-lit
#+BEGIN_SRC scheme
(define (u8e:lit str) (string->utf8 str))
#+END_SRC
The =string-length= function returns the size of the string.
#+name: scm-u8e-string-length
#+BEGIN_SRC scheme
(define (u8e:string-length str) (bytevector-length str))
#+END_SRC
This is the same for the =substring= function.
#+name: scm-u8e-substring
#+BEGIN_SRC scheme
(define (u8e:substring str start end)
(let* ((length (- end start))
......@@ -3674,6 +3673,7 @@ Sometimes we want to append two strings. This may be useful for
nul-terminating a string. However, here we give default arguments to
the delimiter (empty) and the grammar (infix).
#+name: scm-u8e-string-join
#+BEGIN_SRC scheme
(define (u8e:string-join ls)
(if (null? ls)
......@@ -3693,6 +3693,7 @@ In order to check whether =s1= is a prefix of =s2=, we override tge
=string-prefix?= function. For this, we need the =string-length=
function.
#+name: scm-u8e-string-prefix
#+BEGIN_SRC scheme
(define (u8e:string-prefix? s1 s2 start1 end1 start2 end2)
(cond ((eq? start1 end1)
......@@ -3707,6 +3708,7 @@ function.
We also need to find the first occurence of =s2= in =s1=. For this we
need the =string-prefix?= function.
#+name: scm-u8e-string-contains
#+BEGIN_SRC scheme
(define (u8e:string-contains s1 s2 start1 end1 start2 end2)
(let ((length1 (- end1 start1))
......@@ -3720,6 +3722,7 @@ The next function permits us to parse a string as a number. Since
this is quite complicated, we will rely on the unicode implementation.
We need the =string-length= function for this.
#+name: scm-u8e-locale-string-inexact
#+BEGIN_SRC scheme
(define (u8e:locale-string->inexact str locale)
(call-with-values (lambda ()
......@@ -3740,6 +3743,7 @@ binary interface.
This is how we open a port for reading:
#+name: scm-u8e-open-input-string
#+BEGIN_SRC scheme
(define (u8e:open-input-string str)
(open-bytevector-input-port str))
......@@ -3747,6 +3751,7 @@ This is how we open a port for reading:
And this will read a line from it.
#+name: scm-u8e-get-line
#+BEGIN_SRC scheme
(define (u8e:get-line input-port)
(define last-byte (array-ref (u8e:lit "\n") 0))
......@@ -3763,6 +3768,7 @@ And this will read a line from it.
Slightly more higher level, we may have to use gettext. We will
encode/decode for this one.
#+name: scm-u8e-gettext
#+BEGIN_SRC scheme
(define (u8e:gettext what)
(string->utf8 (gettext (utf8->string what))))
......@@ -3882,6 +3888,28 @@ section (C-c C-p), and put a table with the text and a link to that
section.
#+texinfo: @end ignore
* Build system extension :noexport:
In order to export the manual, we define a utility script:
#+BEGIN_SRC shell :eval no :tangle ./generate-manual :shebang "#!/bin/sh" :noweb yes
# This script is supposed to be run from the root of the build
# directory
export TOP_SRCDIR="$PWD/$(dirname $(dirname $0))"
export LIBTAROT_VERSION="<<el-package-version()>>"
export LD_LIBRARY_PATH="$PWD/src/.libs:$LD_LIBRARY_PATH"
export GUILE_LOAD_PATH="$TOP_SRCDIR/src/scm:$GUILE_LOAD_PATH"
cp doc/tarot.org doc/tarot-full.org || exit 1
emacs \
--batch \
-l doc/setup.el \
--file doc/tarot-full.org \
-f org-html-export-to-html \
-f org-texinfo-export-to-texinfo || exit 1
mv doc/tarot-full.texi doc/tarot.texi || exit 1
#+END_SRC
* File-local variables :noexport:
# Local Variables:
# mode: org
......
......@@ -20,6 +20,7 @@ dist_bin_SCRIPTS += %reldir%/tarot-learn
bin_SCRIPTS += %reldir%/tarot-self-train
lib_LTLIBRARIES += %reldir%/libtarot.la
EXTRA_DIST += %reldir%/tarot
TANGLED += %reldir%/tarot-learn %reldir%/tarot-self-train.in
LIBTAROT_VERSION_INFO=0:0:0
......
......@@ -19,7 +19,7 @@
moddir = $(datadir)/guile/site/$(GUILE_EFFECTIVE_VERSION)
godir = $(libdir)/guile/$(GUILE_EFFECTIVE_VERSION)/site-ccache
EXTRA_DIST += %reldir%/tarot.scm
TANGLED += %reldir%/tarot.scm
dist_mod_DATA = %reldir%/tarot.scm
go_DATA = %reldir%/tarot.go
......
......@@ -23,6 +23,8 @@ dist_tarotmod_DATA = \
%reldir%/utf8-everywhere.scm
tarotgo_DATA = \
%reldir%/utf8-everywhere.go
TANGLED += \
%reldir%/utf8-everywhere.scm
include %reldir%/check/Makefile.am
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment