[bug 6458]: need some help for a parsing problem in 'misc/translator/TTParser.pm'
Hi, I have problem with bug 6458 (http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=6458). I will resume the problem (as the bug report is "historical commented" and the problem not clearly pointed at the beginning): Currently, the translation parser (use to apply po files) don't support template directive *in* tag. For example: <tagname attr1="value1" templateText attr2="value2" ...> is interpreted like: <tagname attr1="value1" templateText="templateText" attr2="value2" ...> This occurs rarely in templates, and generate a problem *only* when translation replacement occurs *also* in this tag. Here a case not generating problem (in 'opac-user.tt'): <tr[% IF ( overdue ) %] class="overdue"[% END %]> No problem, because a bad-parsed hash is not used, as the element contains no translated string, so the tag isn't rewrited [see 'tmpl_process3.pl': function 'text_replace_tag', rewrite occurs only if $translated_p]). Here a case with problem (in 'sco/sco-main.tt'): <input type="button" value="Renew Item" [% UNLESS ( renew ) %] name="confirm"[% END %] class="renew" onclick="this.form.confirmed.value='1';this.form.submit();" /> TTParser read as: tagname=input attributes = { type = "button", value = "Renew Item", [% = "[%", unless = "UNLESS", %] = "%]", ... } And as the value attribute is a translated string, this bad-parsed hash is used to rewrite the tag, resulting: <input value="Renouveler document" name="confirm" unless="UNLESS" %]="%]" renew="renew" end="END" )=")" type="button" onclick="this.form.confirmed.value='1';this.form.submit();" class="renew" (="(" [%="[%" /> which is not a valid template... and TT produce a blocking error. So what to do ? 1. works on TTParser.pm, in order to include case for DIRECTIVE in tag element ? (lot of work for rare occurences) 2. works 'tmpl_process3.pl' for change the rewriting style of element (not using the parsed hash, using regexp for example) ? (not a strong method, and need some works too) 3. discard the use of Template DIRECTIVE in tag element ? (adding a test case for report incorrect use of template *in* tag element, or a check in TTParser reporting "unallowed template form") 4. discard the use of Template DIRECTIVE in tag element which contains translated string ? (same before, but more complex to implement) Personnally, I prefer the 3 (or 4) choice... but what is your opinion about this ? Thanks. -- Frère Sébastien Marie Abbaye Notre Dame de La Trappe 61380 Soligny-la-Trappe Tél: 02.33.84.17.00 Fax: 02.33.34.98.57 Web: http://www.latrappe.fr/
Le 19/07/2011 11:10, Frère Sébastien Marie a écrit :
So what to do ? 1. works on TTParser.pm, in order to include case for DIRECTIVE in tag element ? (lot of work for rare occurences) 2. works 'tmpl_process3.pl' for change the rewriting style of element (not using the parsed hash, using regexp for example) ? (not a strong method, and need some works too) 3. discard the use of Template DIRECTIVE in tag element ? (adding a test case for report incorrect use of template *in* tag element, or a check in TTParser reporting "unallowed template form") 4. discard the use of Template DIRECTIVE in tag element which contains translated string ? (same before, but more complex to implement)
Personnally, I prefer the 3 (or 4) choice... but what is your opinion about this ? Not a direct answer to your question, but we agreed, a long time ago, not to have template loops/if inside a html tag. So, the template should not be
<tr[% IF ( overdue ) %] class="overdue"[% END %]> but [% IF ( overdue ) %] <tr class="overdue" > [% ELSE %] <tr> [% END %] that does not break the translator and is *much* easy to read. ah, and I just fixed http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=6412 that is exactly related to this problem ;-) (and not specific to translator) -- Paul POULAIN http://www.biblibre.com Expert en Logiciels Libres pour l'info-doc Tel : (33) 4 91 81 35 08
On Tue, Jul 19, 2011 at 11:38:28AM +0200, Paul Poulain wrote:
Not a direct answer to your question, but we agreed, a long time ago, not to have template loops/if inside a html tag. So, the template should not be
<tr[% IF ( overdue ) %] class="overdue"[% END %]> but [% IF ( overdue ) %] <tr class="overdue" > [% ELSE %] <tr> [% END %]
that does not break the translator and is *much* easy to read.
ah, and I just fixed http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=6412 that is exactly related to this problem ;-)
but should we open bug report for each "miss-used" templates ? (warning, simple grep report 56 occurences) and not all generate a problem (in my case, only when contains also a translated string: an invalid template is produced) -- Frère Sébastien Marie Abbaye Notre Dame de La Trappe 61380 Soligny-la-Trappe Tél: 02.33.84.17.00 Fax: 02.33.34.98.57 Web: http://www.latrappe.fr/
Le 19/07/2011 12:02, Frère Sébastien Marie a écrit :
but should we open bug report for each "miss-used" templates ? (warning, simple grep report 56 occurences) and not all generate a problem (in my case, only when contains also a translated string: an invalid template is produced) don't hesistate to do so ! (opening a bugreport) and if you fix some of those bugs, pls do a patch for each template (or logical group of templates, like "circulation", "members" ...) That would be easier to have small patches (less rebase conflicts if it takes time to have them merged onto master)
-- Paul POULAIN http://www.biblibre.com Expert en Logiciels Libres pour l'info-doc Tel : (33) 4 91 81 35 08
On Tue, Jul 19, 2011 at 12:14:53PM +0200, Paul Poulain wrote:
Le 19/07/2011 12:02, Frère Sébastien Marie a écrit :
but should we open bug report for each "miss-used" templates ? (warning, simple grep report 56 occurences) and not all generate a problem (in my case, only when contains also a translated string: an invalid template is produced) don't hesistate to do so ! (opening a bugreport)
I wrote a simple parser in order to found easily these issues. Resulting: - 6 files unable to parse: CDATA are open but not closed - 1 file unable to parse: an attribute is opened but not closed (exactly, closed and not opened) - 253 occurrences found, in 38 files Does exist any batch processing for opening bug report ? or could I open only one bug report, and populate with multiples patchs ? I attach my log file (report of errors found). The format is: filename: xxx yyy zzz where 'xxx', 'yyy', 'zzz' are line number, where a directive (search for "[%") is found in a tag (something between '<' and '>') and not in an attribute value (something between '"' and '"'). error of parsing are: '(EOF in ...)' For example: ./koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt: 318 318 346 346 362 362 ./koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt: 106 (EOF in Attribute Value) First, in './koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt', two times on each lines: 318, 346 and 362. Second, in './koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt', line 106 and the parse could be terminated because of EOF occurs in a attribute. Here, beware: the parser is too simple to report correctly the error: it only note that an attribute has a bad pair of '"'. And as he continue parsing, the reported error are bad. (here the error is line 97: <option value=ISO_8859-1">, and after correction not problem with DIRECTIVE in TAG). If need, I could also share the parser, but is written in haskell...
and if you fix some of those bugs, pls do a patch for each template (or logical group of templates, like "circulation", "members" ...) That would be easier to have small patches (less rebase conflicts if it takes time to have them merged onto master)
there are generally simple issues, but there are numberous... -- Frère Sébastien Marie Abbaye Notre Dame de La Trappe 61380 Soligny-la-Trappe Tél: 02.33.84.17.00 Fax: 02.33.34.98.57 Web: http://www.latrappe.fr/
On Tue, Jul 19, 2011 at 12:14:53PM +0200, Paul Poulain wrote:
Le 19/07/2011 12:02, Frère Sébastien Marie a écrit :
but should we open bug report for each "miss-used" templates ? (warning, simple grep report 56 occurences) and not all generate a problem (in my case, only when contains also a
don't hesistate to do so ! (opening a bugreport)
I wrote a simple parser in order to found easily these issues.
Resulting: - 6 files unable to parse: CDATA are open but not closed - 1 file unable to parse: an attribute is opened but not closed (exactly, closed and not opened) - 253 occurrences found, in 38 files
Does exist any batch processing for opening bug report ?
or could I open only one bug report, and populate with multiples patchs ?
I attach my log file (report of errors found). The format is: filename: xxx yyy zzz
where 'xxx', 'yyy', 'zzz' are line number, where a directive (search for "[%") is found in a tag (something between '<' and '>') and not in an attribute value (something between '"' and '"').
error of parsing are: '(EOF in ...)'
For example: ./koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt: 318 318 346 346 362 362 ./koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt: 106 (EOF in Attribute Value)
First, in './koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt', two times on each lines: 318, 346 and 362.
Second, in './koha-tmpl/intranet-tmpl/prog/en/modules/tools/ stage-marc-import.tt', line 106 and the parse could be terminated because of EOF occurs in a attribute. Here, beware: the parser is too simple to report correctly the error: it only note that an attribute has a bad pair of '"'. And as he continue parsing, the reported error are bad. (here the error is
Hi One bug with many patches is fine, see 2505 as an example Adding tests to xt/ to catch these would be awesome too, then it would stop more creeping in. I could add it as a step for jenkins, so if you wanted to share the parser that would be excellent, I have a koha-qa git repo we could add it to. Chris On 20 Jul 2011 03:11, "Frère Sébastien" <semarie-koha@latrappe.fr> wrote: translated string: an invalid template is produced) line 97: <option value=ISO_8859-1">, and after correction not problem with DIRECTIVE in TAG).
If need, I could also share the parser, but is written in haskell...
and if you fix some of those bugs, pls do a patch for each template (or logical group of templates, like "circulation", "members" ...) That would be easier to have small patches (less rebase conflicts if it takes time to have them merged onto master)
there are generally simple issues, but there are numberous...
-- Frère Sébastien Marie Abbaye Notre Dame de La Trappe 61380 Soligny-la-Trappe Tél: 02.33.84.17.00 Fax: 02.33.34.98.57 Web: http://www.latrappe.fr/
On Wed, Jul 20, 2011 at 06:42:24AM +1200, Chris Cormack wrote:
Hi
Adding tests to xt/ to catch these would be awesome too, then it would stop more creeping in.
I could add it as a step for jenkins, so if you wanted to share the parser that would be excellent, I have a koha-qa git repo we could add it to.
As said, the parser is in haskell language (exactly, ni literate haskell). So before including in t/ , it should be refactoring (I have tried, but my knowledge in perl is too bad, even for creating a simple stream parser). The haskell parser is just a program which take on STDIN a file content, and output: - nothing : no problem found - numbers separated by space : lines number where DIRECTIVE are found in TAG - an error message in parentheses For generate the log file, a used a couple of shell script (a wrapper around 'find', and a wrapper around the parser). -- Frère Sébastien Marie Abbaye Notre Dame de La Trappe 61380 Soligny-la-Trappe Tél: 02.33.84.17.00 Fax: 02.33.34.98.57 Web: http://www.latrappe.fr/
* Frère Sébastien Marie (semarie-koha@latrappe.fr) wrote:
On Wed, Jul 20, 2011 at 06:42:24AM +1200, Chris Cormack wrote:
Hi
Adding tests to xt/ to catch these would be awesome too, then it would stop more creeping in.
I could add it as a step for jenkins, so if you wanted to share the parser that would be excellent, I have a koha-qa git repo we could add it to.
As said, the parser is in haskell language (exactly, ni literate haskell).
So before including in t/ , it should be refactoring (I have tried, but my knowledge in perl is too bad, even for creating a simple stream parser).
It would go in xt/ if it was to become part of the main repo, but I was proposing putting it in the koha-qa repo, so it can go in there in Haskell just fine. Someone can refactor it into perl at their leisure, but that doesnt stop us setting up jenkins to run it as part of it's tests in the mean time
The haskell parser is just a program which take on STDIN a file content, and output: - nothing : no problem found - numbers separated by space : lines number where DIRECTIVE are found in TAG - an error message in parentheses
For generate the log file, a used a couple of shell script (a wrapper around 'find', and a wrapper around the parser).
Thanks for attaching it, with your permission I'll add it to http://gitorious.org/koha-qa-tools for now Chris
-- Frère Sébastien Marie Abbaye Notre Dame de La Trappe 61380 Soligny-la-Trappe Tél: 02.33.84.17.00 Fax: 02.33.34.98.57 Web: http://www.latrappe.fr/
This program is written in Literate Haskell. All lines starting with '> ' are Haskell, others are comments.
Haskell is a lazy functional and pure language.
This program is not very optimized... it just work.
This program should be used as pipe: - STDIN: template to check - STDOUT: - nothing: no problem found - numbers separated by space : lines number where DIRECTIVE are found in TAG - an error message in parentheses (generally when EOF in found inner not toplevel context)
First, the haskell module definition (mandatory).
module Main where
Next, we create the entrypoint of the program: the 'main' funtion.
The function use 'interact' for interfacing with STDIN/STDOUT. The argument of 'interact' is a function which take a list of Char (type String) and return a list of Char.
We start in the INITIAL context, with line number set to 1
main :: IO () main = interact $ inINITIALContext 1
All the context have the form: an Integer argument : the line number position a list of Char (the String) : the current position of STDIN
and return a list of Char (type String) : STDOUT output
Functions are composed of: - function signature (not mandatory [else infered], but good practice) - the body, using Pattern Matching
In the INITIAL context: - increment 'line' on newline - if start with '<!--', go in COMMENT context - if start with '<![CDATA[', go in CDATA context - if start with '<', go in TAG context - else, discard char - EOF in INITIAL: so end
inINITIALContext :: Integer -> String -> String
inINITIALContext line ('\n':xs) = inINITIALContext (line+1) xs inINITIALContext line ('<':'!':'-':'-':xs) = inCOMMENTContext line xs inINITIALContext line ('<':'!':'[':'C':'D':'A':'T':'A':'[':xs) = inCDATAContext line xs inINITIALContext line ('<':xs) = inTAGContext line xs inINITIALContext line (_x:xs) = inINITIALContext line xs inINITIALContext _line [] = ""
In the COMMENT context: - increment 'line' on newline - go in INITIAL at end of comment '-->' - discard char else - EOF in COMMENT
inCOMMENTContext :: Integer -> String -> String
inCOMMENTContext line ('\n':xs) = inCOMMENTContext (line+1) xs inCOMMENTContext line ('-':'-':'>':xs) = inINITIALContext line xs inCOMMENTContext line (_x:xs) = inCOMMENTContext line xs inCOMMENTContext _line [] = "(EOF in COMMENT)"
In the CDATA context: - increment 'line' on newline - go in INITIAL at end of cdata ']]>' - discard char else - EOF in CDATA
inCDATAContext :: Integer -> String -> String
inCDATAContext line ('\n':xs) = inCDATAContext (line+1) xs inCDATAContext line (']':']':'>':xs) = inINITIALContext line xs inCDATAContext line (_xs:xs) = inCDATAContext line xs inCDATAContext _line [] = "(EOF in CDATA)"
In the TAG context: - increment 'line' on newline - go in STRING if '"' found - go back in INITIAL if '>' - found a DIRECTIVE TEMPLATE in TAG if '[%': output the line (with conversion Integer -> String using 'show'), append space, append the rest (keep in TAG context, continue parsing) - EOF in TAG
inTAGContext :: Integer -> String -> String
inTAGContext line ('\n':xs) = inTAGContext (line+1) xs inTAGContext line ('"':xs) = inSTRINGContext line xs inTAGContext line ('>':xs) = inINITIALContext line xs inTAGContext line ('[':'%':xs) = show line ++ " " ++ inTAGContext line xs inTAGContext line (_x:xs) = inTAGContext line xs inTAGContext _line [] = "(EOF in TAG)"
In the STRING context: - increment 'line' on newline - skip \" (keep STRING context) - go in TAG context at end of string - discard else - EOF in STRING context
inSTRINGContext :: Integer -> String -> String
inSTRINGContext line ('\n':xs) = inSTRINGContext (line+1) xs inSTRINGContext line ('\\':'"':xs) = inSTRINGContext line xs inSTRINGContext line ('"':xs) = inTAGContext line xs inSTRINGContext line (_x:xs) = inSTRINGContext line xs inSTRINGContext _line [] = "(EOF in STRING)"
_______________________________________________ Koha-devel mailing list Koha-devel@lists.koha-community.org http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel website : http://www.koha-community.org/ git : http://git.koha-community.org/ bugs : http://bugs.koha-community.org/
-- Chris Cormack Catalyst IT Ltd. +64 4 803 2238 PO Box 11-053, Manners St, Wellington 6142, New Zealand
On Wed, Jul 20, 2011 at 10:02:56PM +1200, Chris Cormack wrote:
It would go in xt/ if it was to become part of the main repo, but I was proposing putting it in the koha-qa repo, so it can go in there in Haskell just fine.
sorry, I miss the 'x' (and I discover this directory !). There is no problem for including it in main repo or in koha-qa. I attach the shell script (refactoring of the two wrapper in only one) for using the parser more easily.
Someone can refactor it into perl at their leisure, but that doesnt stop us setting up jenkins to run it as part of it's tests in the mean time
It would be possible with a haskell-compiler (but should be compile only once).
The haskell parser is just a program which take on STDIN a file content, and output: - nothing : no problem found - numbers separated by space : lines number where DIRECTIVE are found in TAG - an error message in parentheses
For generate the log file, a used a couple of shell script (a wrapper around 'find', and a wrapper around the parser).
Thanks for attaching it, with your permission I'll add it to http://gitorious.org/koha-qa-tools for now
No problem, and same for the shell script if you want too. -- Frère Sébastien Marie Abbaye Notre Dame de La Trappe 61380 Soligny-la-Trappe Tél: 02.33.84.17.00 Fax: 02.33.34.98.57 Web: http://www.latrappe.fr/
participants (5)
-
Chris Cormack -
Chris Cormack -
Frère Sébastien Marie -
Frère Sébastien Marie -
Paul Poulain