eschulte pushed a commit to branch go in repository elpa. commit eb1d5264116d3e0fd7c0a169a18d6e26c4d25c74 Author: Eric Schulte <eric.schu...@gmx.com> Date: Tue May 22 11:38:05 2012 -0400
parsing weird comments --- sgf-tests.el | 19 +++++++++++++++++++ sgf2el.el | 6 +++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/sgf-tests.el b/sgf-tests.el index d1e3a8c..1fb34dd 100644 --- a/sgf-tests.el +++ b/sgf-tests.el @@ -57,6 +57,25 @@ (should (= 6 (length (car (first (second sgf)))))) (should (= 6 (length (car (second (second sgf)))))))) +(ert-deftest sgf-parse-tree-w-weird-comment () + (let* ((str "(;B[kd]N[(c)]LB[ke:a][pf:b] + C[Black 25 takes larger territory on top, and gives up + larger territory at the right, as compared to variation + (a) \\[3-1-2-1-1-1-2-2-3-2-2-1\\]. + + White continues with 'a'. White 'b' is an overplay + that sets up a ladder that ends the game, unless + White has a ladder break to the lower left.] + (;W[ke]N[(a)];B[ng];W[ne];B[mf];W[me];B[je];W[kf];B[jf];W[kg];B[jd];W[pf]) + + (;W[pf] + C[White 26 is a mistake unless White has a ladder break to the lower left.] + N[mistake (b)];B[pe];W[og];B[rg];W[qh];B[ng];W[ne];B[se];W[qg];B[mf]; + W[me];B[lf]) + )") + (sgf (sgf2el-str-to-el str))) + (should (= 3 (length sgf))))) + (ert-deftest sgf-parse-file-test () (let ((sgf (sgf2el-file-to-el "sgf-files/jp-ming-5.sgf"))) (should (= 247 (length sgf))))) diff --git a/sgf2el.el b/sgf2el.el index d1bb832..997b29d 100644 --- a/sgf2el.el +++ b/sgf2el.el @@ -29,10 +29,10 @@ (eval-when-compile (require 'cl)) (defvar prop-re - "\\([[:alpha:]]+\\)\\(\\([[:space:]]*\\[[^\000]*?[^\\]?\\]\\)+\\)") + "\\([[:alpha:]]+\\)\\(\\(\\[\\]\\|[[:space:]]*\\[[^\000]*?[^\\]\\]\\)+\\)") (defvar prop-val-re - "\\[\\([^\000]*?[^\\]?\\)\\]") + "\\(\\[\\]\\|\\[\\([^\000]*?[^\\]\\)\\]\\)") (defvar sgf2el-special-properties nil "A-list of properties and functions to specially convert their values.") @@ -81,7 +81,7 @@ (setq last-node t)) (let* ((key (sgf2el-convert-prop-key (match-string 2))) (val (sgf2el-convert-prop-vals key - (sgf2el-all-matches (match-string 3) prop-val-re 1))) + (sgf2el-all-matches (match-string 3) prop-val-re 2))) (rep (format "%S " (cons key (if (= 1 (length val)) (car val) val))))) (replace-match rep nil 'literal))))