Commit ff802bac authored by Vivien Kraus's avatar Vivien Kraus
Browse files

Add a Relax-NG schema for tarot

parent d2607ad8
......@@ -62,6 +62,7 @@
/doc/tarot-tune
/doc/tarot.info
/doc/tarot.man
/doc/tarot.rng
/doc/tarot.texi
/doc/tarot.xml
/doc/xml
......
......@@ -65,7 +65,13 @@ AS_IF([test "x$enable_valgrind" = "xyes"], [
])
AM_CONDITIONAL([HAVE_VALGRIND], [test "x$HAVE_VALGRIND" = "xyes"])
AM_MISSING_PROG([XSLTPROC], [xsltproc])
AM_MISSING_PROG([XMLLINT], [xmllint])
HAVE_XMLLINT=1
AC_PATH_PROG([XMLLINT], [xmllint], [no])
AS_IF([test "x$XMLLINT" = "xno"], [
HAVE_XMLLINT=0
AM_MISSING_PROG([XMLLINT], [xmllint])
])
AM_CONDITIONAL([HAVE_XMLLINT], [test "x$HAVE_XMLLINT" = "x1"])
AM_MISSING_PROG([CONVERT], [convert])
AM_PROG_VALAC
AC_ARG_VAR([VALAFLAGS], [Additional flags to pass to the vala compiler])
......
......@@ -70,7 +70,7 @@ case "$1" in
EXPECTED_FIRSTLINE="// $EXPECTED_FIRSTLINE"
EXPECTED_COPYRIGHT=$(echo "$EXPECTED_COPYRIGHT" | sed 's/^/\/\/ /g' | sed 's/^\/\/ $/\/\//g')
;;
*.svg | *.xsl | *.xml | *.tarot | *.ui | *.tarottest | *.xslt)
*.svg | *.xsl | *.xml | *.tarot | *.ui | *.tarottest | *.xslt |*.rng)
FIRSTLINE=$(head -n 2 "$1" | tail -n 1)
SECONDLINE=$(head -n 3 "$1" | tail -n 1)
REST=$(tail -n +5 "$1")
......
......@@ -20,7 +20,8 @@ TANGLED = \
$(srcdir)/%reldir%/petit-sec.c \
$(srcdir)/%reldir%/xml.c \
$(srcdir)/%reldir%/duplicate-a-posteriori.c \
$(srcdir)/%reldir%/dumb-ai.c
$(srcdir)/%reldir%/dumb-ai.c \
$(srcdir)/%reldir%/tarot.rng
EXTRA_DIST += \
$(srcdir)/%reldir%/tarot.texi \
......@@ -34,6 +35,8 @@ MAINTAINERCLEANFILES += \
$(TANGLED) \
$(srcdir)/%reldir%/org-stamp
dist_pkgdata_DATA += $(srcdir)/%reldir%/tarot.rng
.PHONY: tune
$(srcdir)/%reldir%/org-stamp: $(srcdir)/%reldir%/tarot.org $(srcdir)/%reldir%/setup.el
......
......@@ -1452,8 +1452,120 @@ should not worry, since the alignment is never stricter than the
maximum alignment of =max_align_t=.
#+end_deftypefun
** Loading and saving a game with XML
#+index: relax-ng
The XML representation of a game is simply the collection of events
that constitue it. For instance, the package comes with a sample
that constitue it. Here is the Relax-NG schema for the games:
#+BEGIN_SRC xml -i :eval no :tangle tarot.rng
<?xml version="1.0" encoding="utf-8"?>
<!-- tarot implements the rules of the tarot game
Copyright (C) 2019 Vivien Kraus
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
ns="http://planete-kraus.eu/tarot">
<start>
<element name="game">
<zeroOrMore>
<interleave>
<ref name="event" />
</interleave>
</zeroOrMore>
</element>
</start>
<define name="event">
<choice>
<!-- SETUP -->
<element name="setup">
<attribute name="n-players" />
<attribute name="with-call" />
</element>
<!-- DEAL or DEAL-ALL -->
<element name="deal">
<attribute name="to" />
<zeroOrMore>
<ref name="card" />
</zeroOrMore>
</element>
<element name="deal-all">
<zeroOrMore>
<ref name="player" />
</zeroOrMore>
</element>
<!-- BID -->
<element name="bid">
<attribute name="bid" />
</element>
<!-- DECL -->
<element name="decl">
<attribute name="slam" />
</element>
<!-- CALL -->
<element name="call">
<attribute name="card" />
</element>
<!-- DOG -->
<element name="dog">
<oneOrMore>
<ref name="card" />
</oneOrMore>
</element>
<!-- DISCARD -->
<element name="discard">
<zeroOrMore>
<ref name="card" />
</zeroOrMore>
</element>
<!-- HANDFUL -->
<element name="handful">
<zeroOrMore>
<ref name="card" />
</zeroOrMore>
</element>
<!-- CARD -->
<ref name="card" />
</choice>
</define>
<define name="card">
<element name="card">
<attribute name="card" />
</element>
</define>
<define name="player">
<element name="player">
<attribute name="player" />
</element>
</define>
</grammar>
#+END_SRC
The validation for game events is volutarily under-specified, because
it ultimately needs to understand the game rules.
For instance, the package comes with a sample
game:
#+include: ../games/example.xml src xml
......
......@@ -18,3 +18,16 @@ EXTRA_DIST += \
%reldir%/render_mcts_tree.xsl
MAINTAINERCLEANFILES +=
if HAVE_XMLLINT
.PHONY: check-rng
check-local: check-rng
rng_verbose = $(rng_verbose_@AM_V@)
rng_verbose_ = $(rng_verbose_@AM_DEFAULT_V@)
rng_verbose_0 = @echo " CHECK RNG $@";
check-rng: doc/tarot.rng %reldir%/example.xml
$(XMLLINT) --relaxng $(srcdir)/doc/tarot.rng $(srcdir)/%reldir%/example.xml
endif # HAVE_XMLLINT
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