Author: echatellier Date: 2011-03-08 14:40:19 +0100 (Tue, 08 Mar 2011) New Revision: 552 Url: http://nuiton.org/repositories/revision/jrst/552 Log: Fix options list parsing #644, #646 Added: trunk/jrst/src/test/resources/bugs/testOptionsList644.rst Modified: trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java trunk/jrst/src/test/java/org/nuiton/jrst/bugs/TextTest.java Modified: trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java 2011-03-07 16:42:19 UTC (rev 551) +++ trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java 2011-03-08 13:40:19 UTC (rev 552) @@ -638,17 +638,16 @@ Element result = null; String line = in.readLine(); if (line != null) { - if (line.matches("^(\\s*-{1,2}[^\\s-].+\\s+.*)+\\s+.+$")) { + if (line.matches("^(\\s*((--?)|(//?))\\w+([ =][<a-zA-Z][\\w-><]*)?)\\s*.*$")) { result = DocumentHelper.createElement(OPTION_LIST) .addAttribute("level", "" + level(line)); char delimiter; do { - Matcher matcher = Pattern.compile("-{1,2}.+").matcher(line); + Matcher matcher = Pattern.compile("[-/][-/]?.+").matcher(line); matcher.find(); Element option = result.addElement("option"); String option_stringTmp = matcher.group(); - matcher = Pattern.compile("^-{1,2}\\w+").matcher( - option_stringTmp); + matcher = Pattern.compile("^[-/][-/]?\\w+").matcher(option_stringTmp); matcher.find(); String option_string = matcher.group(); option.addAttribute("option_string", option_string); @@ -657,8 +656,8 @@ matcher.end(), option_stringTmp.length()); option.addAttribute("delimiterExiste", "false"); boolean done = false; - if (delimiter == ' ') { // S'il ya 2 espace a suivre, - // l'option est finit + if (delimiter == ' ') { // S'il y a 2 espaces a suivre, + // l'option est finie if (option_stringTmp.charAt(1) == ' ') { done = true; } @@ -666,16 +665,14 @@ if ((delimiter == '=' || delimiter == ' ') && !done) { option.addAttribute("delimiterExiste", "true"); option.addAttribute("delimiter", "" + delimiter); - matcher = Pattern.compile(delimiter + "\\w+").matcher( + matcher = Pattern.compile(delimiter + "[<a-zA-Z][\\w-><\\.\\|]+").matcher( option_stringTmp); String option_argument; if (matcher.find()) { option_argument = matcher.group().substring(1, matcher.group().length()); - option.addAttribute("option_argument", - option_argument); - if (option_stringTmp.charAt(option_argument - .length() + 1) == ',') { + option.addAttribute("option_argument", option_argument); + if (option_stringTmp.charAt(option_argument.length() + 1) == ',') { delimiter = ','; line = line.substring(option_string.length() + option_argument.length() + 3, line @@ -695,7 +692,8 @@ } } if (done) { - result.setText(option_stringTmp.substring(matcher.end(), option_stringTmp.length()).trim()); + result.setText(option_stringTmp.substring(matcher.end(), option_stringTmp.length()).trim() + + " " + joinBlock(readBlock(1))); } } while (delimiter == ','); } Modified: trunk/jrst/src/test/java/org/nuiton/jrst/bugs/TextTest.java =================================================================== --- trunk/jrst/src/test/java/org/nuiton/jrst/bugs/TextTest.java 2011-03-07 16:42:19 UTC (rev 551) +++ trunk/jrst/src/test/java/org/nuiton/jrst/bugs/TextTest.java 2011-03-08 13:40:19 UTC (rev 552) @@ -32,6 +32,7 @@ import junit.framework.Assert; import org.apache.commons.io.FileUtils; +import org.junit.Ignore; import org.junit.Test; import org.nuiton.jrst.JRST; @@ -101,4 +102,27 @@ Matcher matcher = pattern.matcher(content); Assert.assertTrue(matcher.find()); } + + /** + * Test que les synthaxe options sont bien parsées. + * + * @throws Exception + */ + @Test(timeout=10000) + @Ignore + public void testOptionLists() throws Exception { + File in = new File("src/test/resources/bugs/testOptionsList644.rst"); + File out = File.createTempFile("jrst-testOptionList644", ".html"); + out.deleteOnExit(); + JRST.generate(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME); + + String content = FileUtils.readFileToString(out); + System.out.println(content); + Assert.assertTrue(content.indexOf("<span class=\"option\">-a</span>") > 0); + Assert.assertTrue(content.indexOf("<p>options can have arguments and long descriptions</p>") > 0); + Assert.assertTrue(content.indexOf("<v3region.zip|v2region.xml|v2region.xml.gz>") > 0); + Assert.assertTrue(content.indexOf("<span class=\"option\">--importRegion") > 0); + Assert.assertTrue(content.indexOf("<span class=\"option\">/V</span>") > 0); + Assert.assertTrue(content.indexOf("<p>DOS/VMS-style options too</p>") > 0); + } } Added: trunk/jrst/src/test/resources/bugs/testOptionsList644.rst =================================================================== --- trunk/jrst/src/test/resources/bugs/testOptionsList644.rst (rev 0) +++ trunk/jrst/src/test/resources/bugs/testOptionsList644.rst 2011-03-08 13:40:19 UTC (rev 552) @@ -0,0 +1,47 @@ +Test option lists +================= + +Quick example : + +-a command-line option "a" +-b file options can have arguments + and long descriptions +--long options can be long also +--input=file long options can also have + arguments +/V DOS/VMS-style options too + + +Isis example : + +--listRegion Affiche la liste des régions disponibles +--importRegion <v3region.zip|v2region.xml|v2region.xml.gz> Importe une région dans la base locale. Il est possible d'importer des régions depuis ISIS-Fish version 2 ou 3. Suivant l'extension du fichier, ISIS-Fish fera la bonne opération + + +Docutils example : + +-a Output all. +-b Output both (this description is + quite long). +-c arg Output just arg. +--long Output all day long. + +-p This option has two paragraphs in the description. + This is the first. + + This is the second. Blank lines may be omitted between + options (as above) or left in (as here and below). + +--very-long-option A VMS-style option. Note the adjustment for + the required two spaces. + +--an-even-longer-option + The description can also start on the next line. + +-2, --two This option has two variants. + +-f FILE, --file=FILE These two options are synonyms; both have + arguments. + +/V A VMS/DOS-style option. +