From: Jakub H. <mal...@us...> - 2006-10-24 21:42:27
|
Update of /cvsroot/jedit/plugins/LaTeXTools/uk/co/antroy/latextools/parsers In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv31648/LaTeXTools/uk/co/antroy/latextools/parsers Modified Files: BibTeXParser.java Log Message: fix: allow also "" to mark values of bibtex entries (author="HGW" or author={HGW}). Index: BibTeXParser.java =================================================================== RCS file: /cvsroot/jedit/plugins/LaTeXTools/uk/co/antroy/latextools/parsers/BibTeXParser.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- BibTeXParser.java 22 Oct 2006 17:43:16 -0000 1.3 +++ BibTeXParser.java 24 Oct 2006 21:42:23 -0000 1.4 @@ -49,8 +49,8 @@ private Buffer buffer; private View view; private RE refRe; - private RE titleRe; - private RE authorRe; +// private RE titleRe; +// private RE authorRe; private RE contentsRe; //~ Constructors .......................................................... @@ -60,11 +60,16 @@ this.view = view; try { + // Matches the begining of a bibtex entry, such as '@article{Budk:87,' refRe = new RE("@\\w+?\\s*?\\{\\s*?(.+?),"); // WARN.: match includes trailing whitespace - titleRe = new RE("\\btitle\\s*=\\s*\\{(.+?)\\}"); - authorRe = new RE("\\bauthor\\s*=\\s*\\{(.*?)\\}\\s*(?:,|\\})"); - contentsRe = new RE("((?:\\bauthor)|(?:\\bjournal)|(?:\\btitle))\\s*=\\s*\\{(.*?)\\}\\s*(?:,|\\})", - RE.REG_MULTILINE | RE.REG_DOT_NEWLINE); +// titleRe = new RE("\\btitle\\s*=\\s*\\({|\")(.+?)\\(}|\")"); +// authorRe = new RE("\\bauthor\\s*=\\s*\\({|\")(.*?)\\}\\s*(?:,|\\(}|\"))"); + // Note: (?:expr) is the same as (expr) but doesn't save the content + // values may be enclosed in {..} or "..". Entries are separated by ','. + // Ex: author = "Jara Cimrmam" +// contentsRe = new RE("((?:\\bauthor)|(?:\\bjournal)|(?:\\btitle))\\s*=\\s*(?:\\{|\")(.*?)(?:\\}|\")\\s*(?:,|\\})", +// RE.REG_MULTILINE | RE.REG_DOT_NEWLINE); + contentsRe = new gnu.regexp.RE("((?:\\bauthor)|(?:\\bjournal)|(?:\\btitle))\\s*=\\s*(?:\\{|\")(.*?)(?:\\}|\")\\s*(?:,|\\})",gnu.regexp.RE.REG_MULTILINE | gnu.regexp.RE.REG_DOT_NEWLINE); } catch (REException e) { e.printStackTrace(); @@ -170,6 +175,13 @@ } } + /** + * Parse the content of a BibTex reference. + * Ex: '@article{Budk:87, key1 = "value1", key2 = {value2} ...' + * @param segment The text of the reference includng the beginning' @article{Budk:87,' + * @param ref The beginning (type and name) of the reference (e.g. '@article{Budk:87,'). + * @return BibEntry carrying info about the parsed bibtex entry + */ private BibEntry getEntryIn(String segment, String ref) { REMatch[] entries = contentsRe.getAllMatches(segment); @@ -177,8 +189,8 @@ for (int i = 0; i < entries.length; i++) { - String key = entries[i].toString(1); - String description = entries[i].toString(2); + String key = entries[i].toString(1); // references the 1st (group) + String description = entries[i].toString(2); // references the 2nd (group) if (key.equals("title")) { out.setTitle(description); @@ -234,11 +246,14 @@ Buffer buff = jEdit.openTemporary(view, bib.getParent(), bib.getName(), false); + // find all stuff like '@article{Budk:87,' REMatch[] references = refRe.getAllMatches(buff.getText(0, buff.getLength() - 1)); REMatch second = null; + // Parse each of the bibtex entries for 'key = value' pairs + // WARN: likely doesn't work if there are < 2 bibtex references for (int i = 0; i < references.length-1; i++) { REMatch first = references[i]; |