buggyj / bibtex-js

Automatically exported from code.google.com/p/bibtex-js
0 stars 0 forks source link

comma between curly braces ends processing #1

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
First off... Awesome job!

Bibtex if this form does not work correctly because of the , between the curly 
braces.  Zotero exports in this format.

@article{thing,
   ...
},

@article{something,
   ...
},

@inproceedings{name,
    ...
}

This is the fix I came up with

  this.bibtex = function() {
    while(this.tryMatch("@")) {
      var d = this.directive().toUpperCase();
      this.match("{");
      if (d == "@STRING") {
        this.string();
      } else if (d == "@PREAMBLE") {
        this.preamble();
      } else if (d == "@COMMENT") {
        this.comment();
      } else {
        this.entry(); 
      }
      this.match("}");
      if (this.tryMatch(",")){
          this.match(",");
      }

    }
  }

I added this line to the grammar  
string_end -> ( '' | ',' )

// Grammar implemented here:
//  bibtex -> (string | preamble | comment | entry)*;
//  string -> '@STRING' '{' key_equals_value '}' string_end;
//  string_end -> ( '' | ',' )
//  preamble -> '@PREAMBLE' '{' value '}';
//  comment -> '@COMMENT' '{' value '}';
//  entry -> '@' key '{' key ',' key_value_list '}';
//  key_value_list -> key_equals_value (',' key_equals_value)*;
//  key_equals_value -> key '=' value;
//  value -> value_quotes | value_braces | key;
//  value_quotes -> '"' .*? '"'; // not quite
//  value_braces -> '{' .*? '"'; // not quite

Original issue reported on code.google.com by JCCC...@gmail.com on 2 Jul 2011 at 7:26