From 87c34fdec120887345afd4659e018435f7792997 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Sun, 8 May 2016 23:07:15 +0200 Subject: [PATCH] metacrep attempt --- .../songs/chordpro/chordpro/content_meta | 1 + .../songs/chordpro/latex/content_meta | 1 + patacrep/data/templates/styles/patacrep.sty | 10 ++++++ patacrep/songs/chordpro/ast.py | 3 ++ test/test_book/syntax.tex.control | 31 +++++++++++++++++++ .../syntax_datadir/songs/metacrep.csg | 9 ++++++ test/test_song/metacrep.csg | 13 ++++++++ test/test_song/metacrep.csg.source | 9 ++++++ test/test_song/metacrep.tsg | 26 ++++++++++++++++ 9 files changed, 103 insertions(+) create mode 100644 patacrep/data/templates/songs/chordpro/chordpro/content_meta create mode 100644 patacrep/data/templates/songs/chordpro/latex/content_meta create mode 100644 test/test_book/syntax_datadir/songs/metacrep.csg create mode 100644 test/test_song/metacrep.csg create mode 100644 test/test_song/metacrep.csg.source create mode 100644 test/test_song/metacrep.tsg diff --git a/patacrep/data/templates/songs/chordpro/chordpro/content_meta b/patacrep/data/templates/songs/chordpro/chordpro/content_meta new file mode 100644 index 00000000..228cd8d5 --- /dev/null +++ b/patacrep/data/templates/songs/chordpro/chordpro/content_meta @@ -0,0 +1 @@ +{meta: (( content.argument[0] )):(( content.argument[1] ))} \ No newline at end of file diff --git a/patacrep/data/templates/songs/chordpro/latex/content_meta b/patacrep/data/templates/songs/chordpro/latex/content_meta new file mode 100644 index 00000000..b0d05b83 --- /dev/null +++ b/patacrep/data/templates/songs/chordpro/latex/content_meta @@ -0,0 +1 @@ +\metacrep{((- content.argument[0] -))}{((- content.argument[1] -))} \ No newline at end of file diff --git a/patacrep/data/templates/styles/patacrep.sty b/patacrep/data/templates/styles/patacrep.sty index 8b88af75..d4fb85f1 100644 --- a/patacrep/data/templates/styles/patacrep.sty +++ b/patacrep/data/templates/styles/patacrep.sty @@ -468,4 +468,14 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Handle metacrep key (skip if the \metacrep is not defined) +\newcommand{\metacrep}[2]{% + \ifcsname metacrep#1\endcsname% + \csname metacrep#1\endcsname{#2}% + \fi% +} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + \endinput diff --git a/patacrep/songs/chordpro/ast.py b/patacrep/songs/chordpro/ast.py index 37dbae28..04ac32b9 100644 --- a/patacrep/songs/chordpro/ast.py +++ b/patacrep/songs/chordpro/ast.py @@ -43,6 +43,7 @@ INLINE_DIRECTIVES = { "guitar_comment", "image", "newline", + "meta", } #: Some directive have alternative names. For instance `{title: Foo}` and `{t: @@ -355,6 +356,8 @@ class Directive(AST): def __init__(self, keyword, argument=None): super().__init__() self.keyword = directive_name(keyword.strip()) + if keyword == 'meta': + argument = argument.split(':') self.argument = argument @property diff --git a/test/test_book/syntax.tex.control b/test/test_book/syntax.tex.control index af7acb06..1b6604f6 100644 --- a/test/test_book/syntax.tex.control +++ b/test/test_book/syntax.tex.control @@ -34,6 +34,7 @@ guitar, \usepackage{lmodern} +\PassOptionsToPackage{german}{babel} \PassOptionsToPackage{english}{babel} \usepackage[english]{babel} \lang{english} @@ -91,6 +92,36 @@ guitar, \addcontentsline{toc}{section}{\songlistname} \begin{songs}{titleidx,authidx} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% songs/./metacrep.csg + +\selectlanguage{german} + +\beginsong{Der kleine Troll}[ + by={ + }, +] + + +\metacrep{liederbock}{ 292} + + + +\begin{verse} + Let's sing and test a +\end{verse} + + +\metacrep{undefined}{ whatever} + + + +\begin{verse} + directive between verses +\end{verse} + +\endsong + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% songs/./musicnote.csg diff --git a/test/test_book/syntax_datadir/songs/metacrep.csg b/test/test_book/syntax_datadir/songs/metacrep.csg new file mode 100644 index 00000000..0c0e78e9 --- /dev/null +++ b/test/test_book/syntax_datadir/songs/metacrep.csg @@ -0,0 +1,9 @@ +{lang: de} +{title: Der kleine Troll} +{meta: liederbock: 292} + +Let's sing and test a + +{meta: undefined: whatever} + +directive between verses diff --git a/test/test_song/metacrep.csg b/test/test_song/metacrep.csg new file mode 100644 index 00000000..5cbd9ba8 --- /dev/null +++ b/test/test_song/metacrep.csg @@ -0,0 +1,13 @@ +{lang: de} +{title: Der kleine Troll} + +{meta: liederbock: 292} + + +Let's sing and test a + + +{meta: undefined: whatever} + + +directive between verses diff --git a/test/test_song/metacrep.csg.source b/test/test_song/metacrep.csg.source new file mode 100644 index 00000000..0c0e78e9 --- /dev/null +++ b/test/test_song/metacrep.csg.source @@ -0,0 +1,9 @@ +{lang: de} +{title: Der kleine Troll} +{meta: liederbock: 292} + +Let's sing and test a + +{meta: undefined: whatever} + +directive between verses diff --git a/test/test_song/metacrep.tsg b/test/test_song/metacrep.tsg new file mode 100644 index 00000000..9ef5c542 --- /dev/null +++ b/test/test_song/metacrep.tsg @@ -0,0 +1,26 @@ +\selectlanguage{german} + +\beginsong{Der kleine Troll}[ + by={ + }, +] + + +\metacrep{liederbock}{ 292} + + + +\begin{verse} + Let's sing and test a +\end{verse} + + +\metacrep{undefined}{ whatever} + + + +\begin{verse} + directive between verses +\end{verse} + +\endsong