diff --git a/CMakeLists.txt b/CMakeLists.txt index b66c654..008c457 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ SET (PROJECT_DESCRIPTION "LaTeX representation in the memory.") SET (MAJOR 0) SET (MINOR 1) -SET (PATCH 1) +SET (PATCH 2) LIST (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/backbone) diff --git a/cpack/CMakeLists.txt b/cpack/CMakeLists.txt index 3181975..506f3ba 100644 --- a/cpack/CMakeLists.txt +++ b/cpack/CMakeLists.txt @@ -1,6 +1,5 @@ SET (CONTACT "backbone@backbone.ws") -SET (DEBIAN_DEPENDENCIES "valac (>= 0.24), libglib2.0-bin (>= 2.33), libgee (>= -0.16)") +SET (DEBIAN_DEPENDENCIES "valac (>= 0.24), libglib2.0-bin (>= 2.33), libgee (>= 0.16)") SET (DEBIAN_SECTION "Libraries") SET (REDHAT_DEPENDENCIES "vala >= 0.24, glib >= 2.33, libgee >= 0.16") SET (REDHAT_SECTION "Applications/Text") diff --git a/src/latex-struct/AddSpace.vala b/src/latex-struct/AddSpace.vala index f06a258..7d8dce1 100644 --- a/src/latex-struct/AddSpace.vala +++ b/src/latex-struct/AddSpace.vala @@ -13,7 +13,7 @@ namespace LAview { * Possible values: [0-9]+{bp,cc,cm,dd,em,ex,in,mm,pc,pt,sp} <
> * or [0-9]+.[0-9][0-9]{\textwidth,columnwidth,paperwidth,linewidth,textheight,paperheight} */ - public string height = ""; + public string height { get; set; default = ""; } /** * Constructs a new ``AddSpace`` based on value. diff --git a/src/latex-struct/AddSpaces.vala b/src/latex-struct/AddSpaces.vala index 088f19b..4cce02e 100644 --- a/src/latex-struct/AddSpaces.vala +++ b/src/latex-struct/AddSpaces.vala @@ -26,7 +26,7 @@ namespace LAview { /** * Style of the {@link AddSpace}/{@link Subtable}. */ - public Style style = Style.DEFAULT; + public Style style { get; set; default = Style.DEFAULT; } /** * Constructs a new empty ``AddSpaces``. diff --git a/src/latex-struct/Cell.vala b/src/latex-struct/Cell.vala index 1b3ace7..f8e6a4e 100644 --- a/src/latex-struct/Cell.vala +++ b/src/latex-struct/Cell.vala @@ -10,49 +10,49 @@ namespace LAview { /** * Number of occupied cells. */ - public uint ncells = 1; + public uint ncells { get; set; default = 1; } /** * Cell's alignment. * * Possible values: "c", "r", "l", ">{\centering}p{0.07\paperwidth}", etc. */ - public string align = ""; + public string align { get; set; default = ""; } /** * Number of left lines. */ - public uint nllines; + public uint nllines { get; set; } /** * Number of right lines. */ - public uint nrlines; + public uint nrlines { get; set; } /** * Number of top lines. */ - public uint noverlines; + public uint noverlines { get; set; } /** * Number of bottom lines. */ - public uint nunderlines; + public uint nunderlines { get; set; } /** * Contents of the cell. */ - public Glob contents = new Glob (); + public Glob contents { get; set; default = new Glob (); } /** * Any text before the cell. */ - public string before = ""; + public string before { get; set; default = ""; } /** * Any text after the cell. */ - public string after = ""; + public string after { get; set; default = ""; } /** * Type of a cell indicates how much columns/rows does it occupy. diff --git a/src/latex-struct/ColParam.vala b/src/latex-struct/ColParam.vala index 687a176..28353d9 100644 --- a/src/latex-struct/ColParam.vala +++ b/src/latex-struct/ColParam.vala @@ -12,17 +12,17 @@ namespace LAview { * * Possible values: "c", "r", "l", ">{\centering}p{0.07\paperwidth}", etc. */ - public string align = "c"; + public string align { get; set; default = "c"; } /** * Number of left lines. */ - public uint nllines = 1; + public uint nllines { get; set; default = 1; } /** * Number of right lines. */ - public uint nrlines; + public uint nrlines { get; set; } /** * Constructs a new ``ColParam`` by it's properties. diff --git a/src/latex-struct/Graphics.vala b/src/latex-struct/Graphics.vala index 6487787..7b54328 100644 --- a/src/latex-struct/Graphics.vala +++ b/src/latex-struct/Graphics.vala @@ -10,19 +10,19 @@ namespace LAview { /** * All unknown parameters. */ - public string rest_params = ""; + public string rest_params { get; set; default = ""; } /** * Path to the image on the disk. */ - public string path = ""; + public string path { get; set; default = ""; } /** * Width of the image. * * For ex: 3.22, 128 */ - public double width; + public double width { get; set; } /** * Width units of the image. @@ -31,14 +31,14 @@ namespace LAview { * or \textwidth, \columnwidth, \pagewidth, * \linewidth, \textwidth, \paperwidth */ - public string width_unit = ""; + public string width_unit { get; set; default = ""; } /** * Height of the image. * * For ex: 3.22, 128 */ - public double height; + public double height { get; set; } /** * Height units of the image. @@ -47,7 +47,7 @@ namespace LAview { * or \textwidth, \columnwidth, \pagewidth, * \linewidth, \textwidth, \paperwidth */ - public string height_unit = ""; + public string height_unit { get; set; default = ""; } /** * Constructs a new ``Graphics`` by it's properties. diff --git a/src/latex-struct/LongtableParser.vala b/src/latex-struct/LongtableParser.vala index 63880ad..6a832a8 100644 --- a/src/latex-struct/LongtableParser.vala +++ b/src/latex-struct/LongtableParser.vala @@ -21,7 +21,10 @@ namespace LAview { this.position = position; /* get parameters string */ - var param_regex = "^(\\[(c|l|r)])?\\{[^{}]*([^{}]*\\{[^{}]*\\}[^{}]*)*\\}"; + var PAR_REG = "\\|*((>\\{[^{}*]+\\})?[^{}*]+\\{[^{}*]+\\}|[^{}*]+)\\|*"; + // Bug #94: Parse Multiple defined columns in the tabular/longtable. + var param_regex = "^(\\[(c|l|r)])?" + "\\{((\\*\\{[0-9]+\\}\\{" + + PAR_REG + "\\}|" + PAR_REG + "))*\\}"; string params = ""; @@ -59,16 +62,27 @@ namespace LAview { /* match reversed params so '|' will be snapped to the right column */ try { - var regex = new Regex ("(" - + "\\|*}[^{}]+{(p\\|*|m\\|*|b\\|*)(}[^{}]+{>(\\|+$|\\||)|\\|)?" - + "|" - + "\\|*(r|c|l)(}[^{}]+{@(p\\|*|m\\|*|b\\|*) (r|c|l))?(\\|+$|\\||)" - + ")"); + var col_reg1 = "\\|*}[^{}]+{(p\\|*|m\\|*|b\\|*)(}[^{}]+{>(\\|+$|\\||)|\\|)?"; + var col_reg2 = "\\|*(r|c|l)(}[^{}]+{@(p\\|*|m\\|*|b\\|*) (r|c|l))?(\\|+$|\\||)"; + var regex = new Regex ("(" + col_reg1 + "|" + col_reg2 + // Bug #94: Parse Multiple defined columns... + + "|\\}" + col_reg1 + "\\{\\}[0-9]+\\{\\*" + + "|\\}" + col_reg2 + "\\{\\}[0-9]+\\{\\*)"); MatchInfo match_info; regex.match_full (params, -1, 0, 0, out match_info); while (match_info.matches ()) { var col_param = new ColParam.with_params (0, "", 0); var word = match_info.fetch (0).reverse ().compress (); + + // Bug #94: Parse Multiple defined columns in the tabular/longtable. + int count = 1; + if (word[0] == '*') { + count = int.parse (word.offset(2)); + int start; + for (start = 2; word[start] != '{'; ++start); + word = word[start + 1:word.length - 1]; + } + int nllines, nrlines; for (nllines = 0; '|' == word[nllines]; ++nllines); for (nrlines = word.length - 1; nrlines != 0 && '|' == word[nrlines]; --nrlines); @@ -77,7 +91,10 @@ namespace LAview { col_param.align = word.offset (nllines); col_param.nllines = nllines; col_param.nrlines = wlen - 1 - nrlines; - col_params.insert (0, col_param); + + // Bug #94: Parse Multiple defined columns in the tabular/longtable. + while (count-- > 0) col_params.insert (0, col_param); + match_info.next (); } } catch (RegexError e) {} diff --git a/src/latex-struct/ParserFactory.vala b/src/latex-struct/ParserFactory.vala index 5e1d333..bb05af3 100644 --- a/src/latex-struct/ParserFactory.vala +++ b/src/latex-struct/ParserFactory.vala @@ -6,9 +6,9 @@ namespace LAview { class Link { - public string[] begin; - public string[] end; - public unowned ParserDelegate create; + public string[] begin { get; set; } + public string[] end { get; set; } + public unowned ParserDelegate create { get; set; } public Link (string[] begin, string[] end, ParserDelegate? create = null) { this.begin = begin; this.end = end; this.create = create; @@ -17,7 +17,7 @@ namespace LAview { class ParserFactory { - public Array group = new Array (); + public Array group { get; set; default = new Array (); } public virtual TextParser make_text_parser (Array links) { return new TextParser (links); diff --git a/src/latex-struct/Row.vala b/src/latex-struct/Row.vala index b9bc0d9..1d615fc 100644 --- a/src/latex-struct/Row.vala +++ b/src/latex-struct/Row.vala @@ -88,28 +88,28 @@ namespace LAview { /** * Any text before the ``Row``. */ - public string before = ""; + public string before { get; set; default = ""; } /** * Style of any operation on {@link ATable}/{@link Subtable} or ``Row`` * for lines preserving/creation. */ - public Style style; + public Style style { get; set; } /** * Top vertical spaces. */ - public AddSpaces top = new AddSpaces (); + public AddSpaces top { get; set; default = new AddSpaces (); } /** * Bottom vertical spaces. */ - public AddSpace bottom = new AddSpace.with_params (""); + public AddSpace bottom { get; set; default = new AddSpace.with_params (""); } /** * Vertical spaces inside the {@link Subtable} */ - public AddSpaces between = new AddSpaces (); + public AddSpaces between { get; set; default = new AddSpaces (); } /** * Type of horizontal lines for the ``Row``. diff --git a/src/latex-struct/Subtable.vala b/src/latex-struct/Subtable.vala index 66de581..532b476 100644 --- a/src/latex-struct/Subtable.vala +++ b/src/latex-struct/Subtable.vala @@ -10,22 +10,22 @@ namespace LAview { /** * Caption of the table. */ - public string caption = ""; + public string caption { get; set; default = ""; } /** * Any text before the ``Subtable``. */ - public string before = ""; + public string before { get; set; default = ""; } /** * Any text after the ``Subtable``. */ - public string after = ""; + public string after { get; set; default = ""; } /** * Style of the table (Default/Formal). */ - public AddSpaces.Style style; + public AddSpaces.Style style { get; set; } protected override ADocList create_default_instance () { return new Subtable (); } diff --git a/src/latex-struct/Table.vala b/src/latex-struct/Table.vala index 366a6cd..e690400 100644 --- a/src/latex-struct/Table.vala +++ b/src/latex-struct/Table.vala @@ -36,42 +36,42 @@ namespace LAview { * * Possible values: 't', 'b'. */ - public char align; + public char align { get; set; } /** * Style of the {@link AddSpace}/{@link Subtable}. */ - public AddSpaces.Style style; + public AddSpaces.Style style { get; set; } /** * Parameters of columns. */ - public ColParams params = new ColParams (); + public ColParams params { get; set; default = new ColParams (); } /** * Main sutable. */ - public Subtable table = new Subtable (); + public Subtable table { get; set; default = new Subtable (); } /** * First Header. */ - public Subtable first_header = new Subtable (); + public Subtable first_header { get; set; default = new Subtable (); } /** * Header. */ - public Subtable header = new Subtable (); + public Subtable header { get; set; default = new Subtable (); } /** * Footer. */ - public Subtable footer = new Subtable (); + public Subtable footer { get; set; default = new Subtable (); } /** * Last Footer. */ - public Subtable last_footer = new Subtable (); + public Subtable last_footer { get; set; default = new Subtable (); } protected ATable () {} diff --git a/src/latex-struct/Tabular.vala b/src/latex-struct/Tabular.vala index 84c290b..ed39f7d 100644 --- a/src/latex-struct/Tabular.vala +++ b/src/latex-struct/Tabular.vala @@ -21,7 +21,7 @@ namespace LAview { * \textwidth,\columnwidth,\pagewidth,\linewidth, * \textheight,\columnheight,\pageheight,\lineheight}. */ - public string width = ""; + public string width { get; set; default = ""; } /** * Gets a copy of the ``Tabular``. diff --git a/src/latex-struct/TabularParser.vala b/src/latex-struct/TabularParser.vala index d11061e..9863df0 100644 --- a/src/latex-struct/TabularParser.vala +++ b/src/latex-struct/TabularParser.vala @@ -21,9 +21,10 @@ namespace LAview { this.position = position; /* get parameters string */ - var PARAM_REGEX_FIGBRANCHES = "\\{[^{}]*([^{}]*\\{[^{}]*\\}[^{}]*)*\\}"; - var param_regex = "^(\\[(t|b)])?" + PARAM_REGEX_FIGBRANCHES + "(" - + PARAM_REGEX_FIGBRANCHES + ")?"; + var PAR_REG = "\\|*((>\\{[^{}*]+\\})?[^{}*]+\\{[^{}*]+\\}|[^{}*]+)\\|*"; + // Bug #94: Parse Multiple defined columns in the tabular/longtable. + PAR_REG = "\\{((\\*\\{[0-9]+\\}\\{" + PAR_REG + "\\}|" + PAR_REG + "))*\\}"; + var param_regex = "^(\\[(t|b)])?" + PAR_REG + "(" + PAR_REG + ")?"; string params = ""; uint start_pos = 0, stop_pos = 0; @@ -55,8 +56,8 @@ namespace LAview { /* width */ try { - if (Regex.match_simple (PARAM_REGEX_FIGBRANCHES + PARAM_REGEX_FIGBRANCHES, params)) { - var regex = new Regex (PARAM_REGEX_FIGBRANCHES); + if (Regex.match_simple ("^" + PAR_REG + PAR_REG + "$", params)) { + var regex = new Regex (PAR_REG); MatchInfo match_info; regex.match (params, 0, out match_info); match_info.fetch_pos (0, out start_pos, out stop_pos); @@ -74,17 +75,28 @@ namespace LAview { /* match reversed params so '|' will be snapped to the right column */ try { - var regex = new Regex ("(" - + "\\|*}[^{}]+{(p\\|*|m\\|*|b\\|*)(}[^{}]+{>(\\|+$|\\||)|\\|)?" - + "|" - + "\\|*(r|c|l)(}[^{}]+{@(p\\|*|m\\|*|b\\|*) (r|c|l))?(\\|+$|\\||)" - + ")"); + var col_reg1 = "\\|*}[^{}]+{(p\\|*|m\\|*|b\\|*)(}[^{}]+{>(\\|+$|\\||)|\\|)?"; + var col_reg2 = "\\|*(r|c|l)(}[^{}]+{@(p\\|*|m\\|*|b\\|*) (r|c|l))?(\\|+$|\\||)"; + var regex = new Regex ("(" + col_reg1 + "|" + col_reg2 + // Bug #94: Parse Multiple defined columns... + + "|\\}" + col_reg1 + "\\{\\}[0-9]+\\{\\*" + + "|\\}" + col_reg2 + "\\{\\}[0-9]+\\{\\*)"); params = params.reverse (); MatchInfo match_info; regex.match_full (params, -1, 0, 0, out match_info); while (match_info.matches ()) { var col_param = new ColParam.with_params (0, "", 0); var word = match_info.fetch (0).reverse ().compress (); + + // Bug #94: Parse Multiple defined columns in the tabular/longtable. + int count = 1; + if (word[0] == '*') { + count = int.parse (word.offset(2)); + int start; + for (start = 2; word[start] != '{'; ++start); + word = word[start + 1:word.length - 1]; + } + int nllines, nrlines; for (nllines = 0; '|' == word[nllines]; ++nllines); for (nrlines = word.length - 1; nrlines != 0 && '|' == word[nrlines]; --nrlines); @@ -93,7 +105,10 @@ namespace LAview { col_param.align = word.offset (nllines); col_param.nllines = nllines; col_param.nrlines = wlen - 1 - nrlines; - col_params.insert (0, col_param); + + // Bug #94: Parse Multiple defined columns in the tabular/longtable. + while (count-- > 0) col_params.insert (0, col_param); + match_info.next (); } } catch (RegexError e) {} diff --git a/src/latex-struct/Text.vala b/src/latex-struct/Text.vala index e39f5fd..c8b9db8 100644 --- a/src/latex-struct/Text.vala +++ b/src/latex-struct/Text.vala @@ -8,7 +8,7 @@ namespace LAview { /** * Plain text in UTF-8 string. */ - public string text = ""; + public string text { get; set; default = ""; } /** * Constructs a new ``Text``. diff --git a/test/parse-test/CMakeLists.txt b/test/parse-test/CMakeLists.txt index e6002a3..5b01dfd 100644 --- a/test/parse-test/CMakeLists.txt +++ b/test/parse-test/CMakeLists.txt @@ -322,5 +322,12 @@ do_parse_test (back_slashes_in_a_table ${PROJECT_SOURCE_DIR}/test/tex/back_slash "Original and generated text are EQUAL .-.") SET_TESTS_PROPERTIES(ParseTest-back_slashes_in_a_table PROPERTIES ENVIRONMENT "LANG=en") +# test multiply_defined_columns.tex +do_parse_test (multiply_defined_columns + ${PROJECT_SOURCE_DIR}/test/tex/multiply_defined_columns.tex + ${PROJECT_SOURCE_DIR}/test/tex/multiply_defined_columns.etalon.tex +"Original and generated text are EQUAL .-.") +SET_TESTS_PROPERTIES(ParseTest-multiply_defined_columns PROPERTIES ENVIRONMENT "LANG=en") + # enable testing ENABLE_TESTING () diff --git a/test/tex/multiply_defined_columns.etalon.tex b/test/tex/multiply_defined_columns.etalon.tex new file mode 100644 index 0000000..03bd3bd --- /dev/null +++ b/test/tex/multiply_defined_columns.etalon.tex @@ -0,0 +1,10 @@ +\begin{tabular}{l|>{\centering}p{0.11\linewidth}||>{\centering}p{0.11\linewidth}||>{\centering}p{0.11\linewidth}|c} +a & b & c \tabularnewline +\hline +a & b & c & d & e & f & g \tabularnewline +\end{tabular} +\begin{longtable}{l|>{\centering}p{0.11\linewidth}||>{\centering}p{0.11\linewidth}||>{\centering}p{0.11\linewidth}|c} +a & b & c \tabularnewline +\hline +a & b & c & d & e & f & g \tabularnewline +\end{longtable} diff --git a/test/tex/multiply_defined_columns.tex b/test/tex/multiply_defined_columns.tex new file mode 100644 index 0000000..cb288b6 --- /dev/null +++ b/test/tex/multiply_defined_columns.tex @@ -0,0 +1,10 @@ +\begin{tabular}{l*{3}{|>{\centering}p{0.11\linewidth}|}c} +a & b & c \tabularnewline +\hline +a & b & c & d & e & f & g \tabularnewline +\end{tabular} +\begin{longtable}{l*{3}{|>{\centering}p{0.11\linewidth}|}c} +a & b & c \tabularnewline +\hline +a & b & c & d & e & f & g \tabularnewline +\end{longtable}