From 99dad489619ffb44301205975a8b2acac39939e9 Mon Sep 17 00:00:00 2001 From: "John J. Camilleri" Date: Sun, 4 Nov 2018 15:11:35 +0100 Subject: [PATCH] Use Pandoc instead of txt2tags binary, much more configurable --- .txt2tagsrc | 4 -- _post.html | 24 ------------ _pre.html | 16 -------- bin/_template.html | 90 ++++++++++++++++++++++++++++++++++++++++++++ bin/update_html | 45 +++++++++------------- doc/gf-reference.t2t | 81 ++++++++++++++++++++------------------- download/index.t2t | 1 + 7 files changed, 149 insertions(+), 112 deletions(-) delete mode 100644 .txt2tagsrc delete mode 100644 _post.html delete mode 100644 _pre.html create mode 100644 bin/_template.html diff --git a/.txt2tagsrc b/.txt2tagsrc deleted file mode 100644 index dd4b9503f..000000000 --- a/.txt2tagsrc +++ /dev/null @@ -1,4 +0,0 @@ -%!target: html -%!options: --no-headers -%!encoding: UTF-8 -%!postproc(html): '' '
' diff --git a/_post.html b/_post.html deleted file mode 100644 index 4973d2578..000000000 --- a/_post.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - diff --git a/_pre.html b/_pre.html deleted file mode 100644 index f9336e6f8..000000000 --- a/_pre.html +++ /dev/null @@ -1,16 +0,0 @@ - - - - - {{HEAD1}} - - - - -
-
- GF Logo -

{{HEAD1}}

-

{{HEAD2}}

-

{{HEAD3}}

-
diff --git a/bin/_template.html b/bin/_template.html new file mode 100644 index 000000000..fc100e1c4 --- /dev/null +++ b/bin/_template.html @@ -0,0 +1,90 @@ + + + + + + +$for(author-meta)$ + +$endfor$ +$if(date-meta)$ + +$endif$ +$if(keywords)$ + +$endif$ + $if(title-prefix)$$title-prefix$ – $endif$$pagetitle$ + +$if(highlighting-css)$ + +$endif$ +$for(css)$ + +$endfor$ +$if(math)$ + $math$ +$endif$ + +$for(header-includes)$ + $header-includes$ +$endfor$ + + +
+ +$if(title)$ +
+ GF Logo +

$title$

+$if(subtitle)$ +

$subtitle$

+$endif$ +$for(author)$ +

$author$

+$endfor$ +$if(date)$ +

$date$

+$endif$ +
+$endif$ +$if(toc)$ + +$endif$ +$body$ +
+ +
+
+
+
+ Home +
+
+
+
+ + + + + diff --git a/bin/update_html b/bin/update_html index 7777c7895..f7c0ad727 100755 --- a/bin/update_html +++ b/bin/update_html @@ -3,38 +3,29 @@ ### This script finds all .t2t (txt2tags) files and updates the corresponding ### .html file, if it is out-of-date. -config=".txt2tagsrc" -pre="_pre.html" -post="_post.html" -tmp="tmp.html" +# Path to this directory (not CWD) +# https://stackoverflow.com/a/246128/98600 +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" find . -name '*.t2t' | while read t2t ; do html="${t2t%.t2t}.html" if [ "$t2t" -nt "$html" ] ; then - txt2tags --config-file="$config" --target=html "$t2t" - cat $pre $html $post > $tmp - mv $tmp $html - head1=$(head -n 1 "$t2t") - head2=$(tail -n+2 "$t2t" | head -n 1) - head3=$(tail -n+3 "$t2t" | head -n 1) - - # Replace "headers" from t2t in final HTML - # Documentation here: https://txt2tags.org/userguide/headerarea - if [ -n "$head1" ] ; then - sed -i.bak "s/{{HEAD1}}/$head1/" "$html" && rm "$html.bak" + echo "$t2t" + relroot="$( dirname $t2t | sed -E 's/^.\///' | sed -E 's/[^/]+/../g' )" + pandoc \ + --from=t2t \ + --to=html5 \ + --standalone \ + --template="$DIR/_template.html" \ + --css="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" \ + --variable="rel-root:$relroot" \ + "$t2t" \ + --output="$html" + if [ -f "$html" ]; then + sed -i.bak "s/
/
/" "$html" && rm "$html.bak" + sed -i.bak -E "s/\`\`(.+)\`\`/\1<\/code>/g" "$html" && rm "$html.bak" else - sed -i.bak -E "s/<.+{{HEAD1}}.+>//" "$html" && rm "$html.bak" - continue # empty headers - fi - if [ -n "$head2" ] ; then - sed -i.bak "s/{{HEAD2}}/$head2/" "$html" && rm "$html.bak" - else - sed -i.bak -E "s/<.+{{HEAD2}}.+>//" "$html" && rm "$html.bak" - fi - if [ -n "$head3" ] ; then - sed -i.bak "s/{{HEAD3}}/$head3/" "$html" && rm "$html.bak" - else - sed -i.bak -E "s/<.+{{HEAD3}}.+>//" "$html" && rm "$html.bak" + echo "Error creating $html" fi fi done diff --git a/doc/gf-reference.t2t b/doc/gf-reference.t2t index aab828f0a..676a2088d 100644 --- a/doc/gf-reference.t2t +++ b/doc/gf-reference.t2t @@ -15,11 +15,11 @@ April 4, 2006 This is a quick reference on GF grammars. It aims to cover all forms of expression available when writing grammars. It assumes basic knowledge of GF, which -can be acquired from the +can be acquired from the [GF Tutorial http://www.grammaticalframework.org/doc/tutorial/gf-tutorial.html]. Help on GF commands is obtained on line by the -help command (``help``), and help on invoking -GF with (``gf -help``). +help command with ``help``, and help on invoking +GF with ``gf -help``. ===A complete example=== @@ -31,10 +31,10 @@ phrases //one pizza// and //two pizzas//. File ``Order.gf``: ``` abstract Order = { -cat - Order ; +cat + Order ; Item ; -fun +fun One, Two : Item -> Order ; Pizza : Item ; } @@ -42,13 +42,13 @@ fun File ``OrderEng.gf`` (the top file): ``` --# -path=.:prelude -concrete OrderEng of Order = +concrete OrderEng of Order = open Res, Prelude in { flags startcat=Order ; -lincat - Order = SS ; +lincat + Order = SS ; Item = {s : Num => Str} ; -lin +lin One it = ss ("one" ++ it.s ! Sg) ; Two it = ss ("two" ++ it.s ! Pl) ; Pizza = regNoun "pizza" ; @@ -84,10 +84,10 @@ File named ``Foo.gf`` contains module named Each module has the structure ``` -moduletypename = +moduletypename = Inherits ** -- optional open Opens in -- optional - { Judgements } + { Judgements } ``` Inherits are names of modules of the same type. Inheritance can be restricted: @@ -112,15 +112,15 @@ interface I -- like resource, but can have oper f : T without definition instance J of I -- like resource, defines opers that I leaves undefined -incomplete -- functor: concrete that opens +incomplete -- functor: concrete that opens concrete CI of A = one or more interfaces open I in ... concrete CJ of A = -- completion: concrete that CI with instantiates a functor by (I = J) instances of open interfaces -``` -The forms -``param``, ``oper`` +``` +The forms +``param``, ``oper`` may appear in ``concrete`` as well, but are then not inherited to extensions. @@ -134,11 +134,11 @@ Comments have the forms A ``concrete`` can be opened like a ``resource``. It is translated as follows: ``` -cat C ---> oper C : Type = +cat C ---> oper C : Type = lincat C = T T ** {lock_C : {}} -fun f : G -> C ---> oper f : A* -> C* = \g -> -lin f = t t g ** {lock_C = <>} +fun f : G -> C ---> oper f : A* -> C* = \g -> +lin f = t t g ** {lock_C = <>} ``` An ``abstract`` can be opened like an ``interface``. Any ``concrete`` of it then works as an ``instance``. @@ -155,7 +155,7 @@ fun f : T -- declare function f of type T def f = t -- define f as t def f p q = t -- define f by pattern matching data C = f | g -- set f,g as constructors of C -data f : A -> C -- same as +data f : A -> C -- same as fun f : A -> C; data C=f lincat C = T -- define lin.type of cat C @@ -166,7 +166,7 @@ printname fun f = s -- printname shown in menus printname cat C = s -- printname shown in menus printname f = s -- same as printname fun f = s -param P = C | D Q R -- define parameter type P +param P = C | D Q R -- define parameter type P with constructors C : P, D : Q -> R -> P oper h : T = t -- define oper h of type T @@ -207,14 +207,14 @@ P -- parameter type, if param P P => B -- table type, if P param. type {s : Str ; p : P}-- record type {s,t : Str} -- same as {s : Str ; t : Str} -{a : A} **{b : B}-- record type extension, same as +{a : A} **{b : B}-- record type extension, same as {a : A ; b : B} A * B * C -- tuple type, same as {p1 : A ; p2 : B ; p3 : C} Ints n -- type of n first integers ``` Resource (in ``oper``): all those of concrete, plus -``` +``` Tok -- tokens (subtype of Str) A -> B -- functions from A to B Int -- integers @@ -239,7 +239,7 @@ f a b -- : C if fun f : A -> B -> C ``` Higher-Order Abstract syntax (HOAS): functions as arguments: ``` -F a (\x -> c) -- : C if a : A, c : C (x : B), +F a (\x -> c) -- : C if a : A, c : C (x : B), fun F : A -> (B -> C) -> C ``` Tokens and token lists @@ -266,16 +266,16 @@ table { -- by pattern matching Pl => "mice" ; _ => "mouse" -- wildcard pattern } -table { - n => regn n "cat" -- variable pattern +table { + n => regn n "cat" -- variable pattern } table Num {...} -- table given with arg. type table ["ox"; "oxen"] -- table as course of values -\\_ => "fish" -- same as table {_ => "fish"} +\\_ => "fish" -- same as table {_ => "fish"} \\p,q => t -- same as \\p => \\q => t t ! p -- select p from table t -case e of {...} -- same as table {...} ! e +case e of {...} -- same as table {...} ! e ``` Records ``` @@ -296,7 +296,7 @@ Local definitions ``` let x : A = d in t -- let definition let x = d in t -- let defin, type inferred -let x=d ; y=e in t -- same as +let x=d ; y=e in t -- same as let x=d in let y=e in t let {...} in t -- same as let ... in t @@ -316,10 +316,10 @@ Typed expression ``` -- same as t, to help type inference ``` -Accessing bound variables in ``lin``: use fields ``$1, $2, $3,...``. +Accessing bound variables in ``lin``: use fields ``$1, $2, $3,...``. Example: ``` -fun F : (A : Set) -> (El A -> Prop) -> Prop ; +fun F : (A : Set) -> (El A -> Prop) -> Prop ; lin F A B = {s = ["for all"] ++ A.s ++ B.$1 ++ B.s} ``` @@ -367,7 +367,7 @@ oper cc2 : (_,_ : SS) -> SS -- concat SS's optStr : Str -> Str -- string or empty strOpt : Str -> Str -- empty or string - bothWays : Str -> Str -> Str -- X++Y or Y++X + bothWays : Str -> Str -> Str -- X++Y or Y++X init : Tok -> Tok -- all but last char last : Tok -> Tok -- last char prefixSS : Str -> SS -> SS @@ -388,7 +388,7 @@ Flags can appear, with growing priority, Some common flags used in grammars: ``` -startcat=cat use this category as default +startcat=cat use this category as default lexer=literals int and string literals recognized lexer=code like program code @@ -407,7 +407,7 @@ optimize=values good for lexicon concrete optimize=all usually good for resource optimize=noexpand for resource, if =all too big ``` -For the full set of values for ``FLAG``, +For the full set of values for ``FLAG``, use on-line ``h -FLAG``. @@ -415,7 +415,7 @@ use on-line ``h -FLAG``. ===File import search paths=== Colon-separated list of directories searched in the -given order: +given order: ``` --# -path=.:../abstract:../common:prelude ``` @@ -443,17 +443,17 @@ directories, colon-separated, in ``GF_LIB_PATH``. ===Alternative grammar formats=== -**Old GF** (before GF 2.0): +**Old GF** (before GF 2.0): all judgements in any kinds of modules, division into files uses ``include``s. A file ``Foo.gf`` is recognized as the old format -if it lacks a module header. +if it lacks a module header. **Context-free** (file ``foo.cf``). The form of rules is e.g. ``` Fun. S ::= NP "is" AP ; ``` -If ``Fun`` is omitted, it is generated automatically. +If ``Fun`` is omitted, it is generated automatically. Rules must be one per line. The RHS can be empty. **Extended BNF** (file ``foo.ebnf``). The form of rules is e.g. @@ -477,7 +477,7 @@ on command line. This file can be the grammar file itself. ``` in Cat "example string" ``` -are preprocessed by using a parser given by the flag +are preprocessed by using a parser given by the flag ``` --# -resource=File ``` @@ -489,5 +489,4 @@ and the result is written to ``foo.gf``. [GF Homepage http://www.grammaticalframework.org/] A. Ranta, Grammatical Framework: A Type-Theoretical Grammar Formalism. -//The Journal of Functional Programming//, vol. 14:2. 2004, pp. 145-189. - +//The Journal of Functional Programming//, vol. 14:2. 2004, pp. 145-189. diff --git a/download/index.t2t b/download/index.t2t index 1f89d9f78..da96f238c 100644 --- a/download/index.t2t +++ b/download/index.t2t @@ -16,6 +16,7 @@ What's new? See the [Release notes release-3.9.html]. | Ubuntu (32-bit) | [gf_3.9-1_i386.deb gf_3.9-1_i386.deb] | //GF+S+C+J+P// | ``sudo dpkg -i gf_3.9-1_i386.deb`` | Ubuntu (64-bit) | [gf_3.9-1_amd64.deb gf_3.9-1_amd64.deb] | //GF+S+C+J+P// | ``sudo dpkg -i gf_3.9-1_amd64.deb`` | Windows | [gf-3.9-bin-windows.zip gf-3.9-bin-windows.zip] | //GF+S// | ``unzip gf-3.9-bin-windows.zip`` + %| MINGW | [gf-3.9-bin-i686-MINGW32_NT-6.1.tar.gz gf-3.9-bin-i686-MINGW32_NT-6.1.tar.gz] | //GF+S+C// | ``tar -C / gf-3.9-bin-i686-MINGW32_NT-6.1.tar.gz`` %| ... | ... | ... | ...