Skip to content

Commit

Permalink
mouais
Browse files Browse the repository at this point in the history
  • Loading branch information
athoune committed Sep 1, 2009
1 parent 1113a1d commit c02bf86
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Bib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
require 'rubygems'
require 'treetop'

Treetop.load "BibTex"
Treetop.load "BibTex.tt"

parser = BibTexParser.new


f = File.open('bibliographie.bib')
parser.parse(f.read).elements.each do |book|
puts book.label
bib = parser.parse(f.read)
puts bib
bib.elements.each do |element|
puts element
#.inspect
#.label
end
55 changes: 55 additions & 0 deletions BibTex.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
grammar BibTex

rule expression
(comment / book / white)*
end

rule comment
('%' / '@comment') (!'\n' . )* '\n' {
def label
return "comment"
end
}
end

rule book
title:bookTitle space '{' space key:Character+ space ',' (attribute space ',' white)* attribute '}' {
def label
return "book"
end
}
end

rule attribute
key space '=' space value
end

rule value
('"' content:(!'"' . )* '"') / ('{' content:(!'{' . )* '}') / key
end

rule bookTitle
'@' key {
def label
return "label"
end
}
end

rule key
[a-zA-Z] [-a-zA-Z0-9_]*
end

rule white
[ \n]+
end

rule space
' '* {
def label
return "white"
end
}
end

end

0 comments on commit c02bf86

Please sign in to comment.