Last active
August 29, 2015 14:06
-
-
Save r00k/c5a3ec1680768bff36ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2014-03-20 | |
Line 1 | |
Line 2 | |
2014-03-21 | |
Line 1 | |
Line 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# What I want: | |
[{:body=>"Line 1\n\nLine 2", :year=>"2014", :month=>"03", :day=>"20"}, | |
{:body=>"Line 1\n\nLine 2", :year=>"2014", :month=>"03", :day=>"21"}] | |
# What I'm getting | |
[{:year=>"2014"@0, | |
:month=>"03"@5, | |
:day=>"20"@8, | |
:body=>"Line 1\n\nLine 2\n\n2014-03-21\n\nLine 1\n\nLine 2"@12}] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Parser < Parslet::Parser | |
rule(:integer) { match('[0-9]').repeat(1) } | |
rule(:hyphen) { str('-') } | |
rule(:date) { integer.repeat(1,4).as(:year) >> | |
hyphen >> | |
integer.repeat(1,2).as(:month) >> | |
hyphen >> | |
integer.repeat(1,2).as(:day) >> | |
str("\n\n") } | |
rule(:body) { (any.repeat >> (date.present? | any.absent?)).as(:body) } | |
rule(:entry) { date >> body } | |
rule(:entries) { entry.repeat } | |
root(:entries) | |
end |
rule(:body) { (date.absent? >> any).repeat.as(:body) }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not familiar with this parser, but I think you want something besides
any
.